diff options
author | martinw | 2000-06-06 10:17:57 +0000 |
---|---|---|
committer | martinw | 2000-06-06 10:17:57 +0000 |
commit | 0c2fc8bee853030a29494fbb1781f287421c0870 (patch) | |
tree | f92453d8dc6d150eafd6a89681c6071aaafda986 /frontend/scanner.icl | |
parent | enabled higher order function elimination also for functions (producers) (diff) |
added simple hacky preprocessor facility. The following source
module t
/*2.0
from m import :: T(C1)
0.2*/
//1.3
from m import T, C1
//3.1
will be transformed into
module t
/***/
from m import :: T(C1)
/***/
/*1.3
from m import T, C1
3.1*/
before scanning. In this way we achieve that the upper source can be
compiled with the 2.0 compiler as well as with the 1.3 compiler
The comments _must_ begin the line (no leading whitespaces are allowed).
git-svn-id: https://svn.cs.ru.nl/repos/clean-compiler/trunk@150 1f8540f1-abd5-4d5b-9d24-4c5ce8603e2d
Diffstat (limited to 'frontend/scanner.icl')
-rw-r--r-- | frontend/scanner.icl | 59 |
1 files changed, 48 insertions, 11 deletions
diff --git a/frontend/scanner.icl b/frontend/scanner.icl index 160a23b..8e17d42 100644 --- a/frontend/scanner.icl +++ b/frontend/scanner.icl @@ -434,7 +434,6 @@ skip_whites_in_line i fp_col fp_line line tabsize stream inp_filename TryScanComment :: !Char !Input -> (!Optional String, !Char, !Input) TryScanComment c1=:'/' input -// #! pos = input.inp_pos // MW++ # (eof,c2, input) = ReadNormalChar input | eof = (No, c1, input) = case c2 of @@ -442,13 +441,6 @@ TryScanComment c1=:'/' input '*' -> case ScanComment input of (No,input) -> SkipWhites input (er,input) -> (er, c1, input) -/* -// MW.. - NewLineChar - # input = charBack input - -> (No, c1, { input & inp_pos = pos }) -// ..MW -*/ _ -> (No, c1, charBack input) TryScanComment c input @@ -1150,7 +1142,8 @@ ReadNormalChar {inp_stream = OldLine i line stream,inp_pos,inp_tabsize,inp_filen ) = ReadNormalChar {inp_filename=inp_filename,inp_tabsize=inp_tabsize,inp_pos=inp_pos,inp_stream = stream} ReadNormalChar {inp_stream = InFile file, inp_pos, inp_tabsize, inp_filename} - #! (s, file) = freadline file +// MW8 was: #! (s, file) = freadline file + #! (s, file) = (SwitchPreprocessor freadPreprocessedLine freadline) file | size s==0 # c = NewLineChar // pos = NextPos c inp_pos inp_tabsize @@ -1194,7 +1187,8 @@ ReadChar {inp_stream = OldLine i line stream,inp_pos,inp_tabsize,inp_filename} inp_stream = stream} //ReadChar input=:{inp_stream = InFile file, inp_pos, inp_tabsize} ReadChar {inp_stream = InFile file, inp_pos, inp_tabsize, inp_filename} - #! (s, file) = freadline file +// MW8 was: #! (s, file) = freadline file + #! (s, file) = (SwitchPreprocessor freadPreprocessedLine freadline) file | size s==0 # c = NewLineChar pos = NextPos c inp_pos inp_tabsize @@ -1360,7 +1354,8 @@ ReadLine input=:{inp_stream = OldLine i line oldfile, inp_pos} ReadLine input=:{inp_stream = InFile infile,inp_pos} # (eof, file) = fend infile | eof = ("", {input & inp_stream = InFile file}) - # (l, file ) = freadline file +//MW8 was # (l, file ) = freadline file + # (l, file ) = (SwitchPreprocessor freadPreprocessedLine freadline) file = (l, {input & inp_stream = InFile file, inp_pos = NextPos CRChar inp_pos 0}) /* ReadLine input=:{inp_stream = OldChar c p oldfile} @@ -1885,3 +1880,45 @@ where (-->>) val _ :== val //(-->>) val message :== val ---> ("Scanner",message) + + +// MW8.. + //--------------------// + //--- Preprocessor ---// +//--------------------// + + +SwitchPreprocessor preprocessor no_preprocessor :== preprocessor + +freadPreprocessedLine :: !*File -> (!.{#Char},!*File) +freadPreprocessedLine file + #! (line, file) = freadline file + | begins_with "/*2.0" line + = (replace_beginning_with "/***/" line, file) + | begins_with "0.2*/" line + = (replace_beginning_with "/***/" line, file) + | begins_with "//1.3" line + = (replace_beginning_with "/*1.3" line, file) + | begins_with "//3.1" line + = (replace_beginning_with "3.1*/" line, file) + = (line, file) + where + begins_with :: !String !String -> Bool + begins_with pattern line + # size_pattern = size pattern + | size line<size_pattern + = False + = loop pattern line (size_pattern-1) + loop :: !String !String !Int -> Bool + loop pattern line i + | i<0 + = True + | line.[i]<>pattern.[i] + = False + = loop pattern line (i-1) + replace_beginning_with :: !String !*String -> .String + replace_beginning_with replacement string + # result = { string & [i] = replacement.[i] \\ i<-[0..size replacement-1] } + | True--->("replaced", result) + = result +// ..MW8 |