Commit 0dff923b authored by John van Groningen's avatar John van Groningen

remove unused code, add some function type signatures

parent 798891d9
......@@ -5,17 +5,6 @@ definition module PmParse
import StdString, StdFile
from UtilStrictLists import :: List
FindImportsInFile ::
!.String // pathname
!*Files
-> *((Bool,List String),*Files);
Tokenize ::
!String
!*Files
-> ([String],*Files)
:: SearchKind
= Definition
| Implementation
......@@ -27,7 +16,6 @@ Tokenize ::
| Cls !Int !Int IdentifierPositionList
| Ins !Int !Int IdentifierPositionList
FindIdentifiersInFile ::
!Bool
!(List String) // list of imported modules
......
......@@ -75,7 +75,7 @@ FromSym :== {repr = FromSymID, string = ""};
ImportSym :== {repr = ImportSymID, string = ""};
InstanceSym :== {repr = InstanceSymID, string = ""};
ClassSym :== {repr = ClassSymID, string = ""};
InfixSym :== {repr = InfixSymID, string = ""}; // DvA
InfixSym :== {repr = InfixSymID, string = ""};
DigitSym :== {repr = DigitSymID, string = ""}
WhereSym :== {repr = WhereSymID, string = ""}
HashSym :== {repr = HashSymID, string = ""}
......@@ -85,56 +85,6 @@ IsTypeSymId id :== id == IdentUpperSymID || id == IdentFunnySymID;
ConstrSymId id :== id == IdentUpperSymID || id == IdentFunnySymID;
CommaSymId id :== id == CommaSymID
//-- DvA: poging tot xref anal
FindImportsInFile :: !.String !*Files -> *((Bool,List String),*Files);
FindImportsInFile path files
# (files,ok,file) = OpenTextFile path files
| not ok
= ((False,Nil), files)
# (input,sym,_,_) = ScanInput (StartInput file)
# is_system = sym.repr == IdentLowerSymID && sym.string == "system"
# (input,imports) = FindXrefsInInput Nil sym input
# input = EndInput input
# files = CloseTextFile input files
= ((is_system,imports), files)
FindXrefsInInput imports sym=:{repr} input
| repr==FromSymID
# (inputa,syma,importsa) = ScanFrom imports input;
= FindXrefsInInput importsa syma inputa;
| repr==ImportSymID
# (inputb,symb,importsb) = ScanImport imports input;
= FindXrefsInInput importsb symb inputb;
| repr==EofSymID
= (input,imports);
# (input2,next_symbol,_,_) = ScanInput input;
= FindXrefsInInput imports next_symbol input2;
//<< DvA: end poging
//++ Tokenizer
Tokenize :: !String !*Files -> ([String],*Files)
Tokenize path files
# (files,ok,file) = OpenTextFile path files
| not ok
= ([], files)
# input = StartInput file
# (syms,input) = TT input
# input = EndInput input
# files = CloseTextFile input files
# tokens = map (\s->"R: "+++toString s.repr+++"\t"+++s.string) syms
= (tokens, files)
where
TT input
# (input,sym,_,_) = ScanInput input
| sym.repr == EofSymID
= ([],input)
# (rest,input) = TT input
= ([sym:rest],input)
:: DefinesState =
{ syms :: ![Def]
}
......@@ -144,25 +94,13 @@ where
| DefClass String Int
| DefInst String String Int
FindDefinesInFile :: !String !Files -> (![Def],!Files)
FindDefinesInFile path files
# (files,ok,file) = OpenTextFile path files
| not ok
= ([], files)
# input = StartInput file
# state = {syms = []}
# (state,input) = FindDefsInInput state input
# input = EndInput input
# files = CloseTextFile input files
= (state.syms, files)
FindDefinesInText :: !*{String} !Files -> (![Def],!Files)
FindDefinesInText text files
# input = StartInput` text
# state = {syms = []}
# (state,input) = FindDefsInInput state input
= (state.syms, files)
FindDefsInInput :: !DefinesState !(Input a) -> (!DefinesState,!(Input a)) | ScanInput a
FindDefsInInput state input
# (input,sym,line,_) = ScanGlobal input
......@@ -226,6 +164,7 @@ FindDefsInInput state input
= FindDefsInInput state input
= FindDefsInInput state input
ScanMatch :: {#Char} Int Int ({#Char},{#Char}) Int *(Input a) -> *(!*(Input a),!{#Char}) | ScanInput a;
ScanMatch str open close (oString,cString) depth input
# (input,sym,line,char) = ScanInput input
| sym.repr == EofSymID
......@@ -273,7 +212,7 @@ FindIdentifiersInFile :: !Bool !(List String) !String !String !Files
FindIdentifiersInFile imp imports cleanid path files
# (files,ok,file) = OpenTextFile path files
| not ok
= trace_n ("failed to open",path) ((imports,PosNil), files)
= ((imports,PosNil), files)
# (input,sym,_,_) = ScanInput (StartInput file)
# (input,imports,identifier_position_list) = FindIdentifiersInInput imp cleanid imports sym input PosNil
= ((imports,identifier_position_list), CloseTextFile (EndInput input) files)
......@@ -302,7 +241,7 @@ FindDefinitionInText imp imports cleanid text files
# (input,imports,positions) = FindDefinitionInInput imp cleanid imports (StartInput` text)
= ((imports,positions), files)
//FindIdentifiersInInput :: !Bool !String !(List String) !Symbol !Input -> (!Input, !List String, !IdentifierPositionList);
FindIdentifiersInInput :: !Bool !String !(List String) !Symbol !(Input a) IdentifierPositionList -> (!Input a, !List String, !IdentifierPositionList) | ScanInput a;
FindIdentifiersInInput imp cleanid imports sym=:{repr} input positions
| repr==FromSymID && imp
# (input,sym,imports,positions) = FindFrom imports input positions
......@@ -318,7 +257,7 @@ FindIdentifiersInInput imp cleanid imports sym=:{repr} input positions
= (input,imports,Pos linenr charnr positions);
= FindIdentifiersInInput imp cleanid imports sym input positions
where
//FindFrom :: !(List String) !Input -> (!Input, !Symbol, !List String, !IdentifierPositionList);
FindFrom :: !(List String) !(Input a) IdentifierPositionList -> (!Input a, !Symbol, !List String, !IdentifierPositionList) | ScanInput a;
FindFrom imports input positions
# (input,sym,linenr,charnr) = ScanInput input;
| IdentSymId sym.repr
......@@ -327,14 +266,16 @@ where
= (input,sym,imports,Pos linenr charnr positions)
= FindFromIdent (sym.string :! imports) input positions
= (input,sym, imports,positions);
//FindFromIdent :: !(List String) !Input -> (!Input, !Symbol, !List String);
FindFromIdent :: !(List String) !(Input a) IdentifierPositionList -> (!Input a, !Symbol, !List String, IdentifierPositionList) | ScanInput a;
FindFromIdent imports input positions
# (input,sym,_,_) = ScanInput input;
| sym.repr == ImportSymID
# (input,sym,_,positions) = FindImport Nil input positions
= (input,sym,imports,positions)
= (input, sym, imports,positions);
//FindImport :: !(List String) !Input -> (!Input, !Symbol, !List String, !IdentifierPositionList);
FindImport :: !(List String) !(Input a) IdentifierPositionList -> (!Input a, !Symbol, !List String, !IdentifierPositionList) | ScanInput a;
FindImport imports input positions
# (input,sym,linenr,charnr) = ScanInput input
| IdentSymId sym.repr
......@@ -343,13 +284,15 @@ where
= (input,sym,imports,Pos linenr charnr positions)
= FindImportIdent (sym.string :! imports) input positions
= (input,sym,imports,positions);
//FindImportIdent :: !(List String) !Input -> (!Input, !Symbol, !List String);
FindImportIdent :: !(List String) !(Input a) IdentifierPositionList -> (!Input a, !Symbol, !List String,IdentifierPositionList) | ScanInput a;
FindImportIdent imports input positions
# (input,sym,_,_) = ScanInput input
| sym.repr == CommaSymID
= FindImportIdentComma imports input positions
= (input,sym, imports,positions);
//FindImportIdentComma :: !(List String) !Input -> (!Input, !Symbol, !List String);
FindImportIdentComma :: !(List String) !(Input a) IdentifierPositionList -> (!Input a, !Symbol, !List String,IdentifierPositionList) | ScanInput a;
FindImportIdentComma imports input positions
# (input,sym,linenr,charnr) = ScanInput input
| IdentSymId sym.repr
......@@ -373,7 +316,8 @@ Definition1 maybe_sym imp cleanid imports input
| match_import
# (inputb,symb,importsb) = ScanImport imports input`;
= SkipToDefinition imp cleanid importsb symb inputb;
| match_typespec = TypeDef imp cleanid imports input`;
| sym.repr == TypeSpecSymID
= TypeDef imp cleanid imports input`;
| match_instance = InstanceDef imp cleanid imports input`;
| match_class = trace_n ("Definition1: match_class",lnr) ClassDef imp cleanid imports input`;
| match_ident = RuleOrMacroDef lnr cnr imp False cleanid imports input`;
......@@ -384,7 +328,6 @@ where
(input`,sym,lnr,cnr) = case maybe_sym of
Just (sym,lnr,cnr) -> (input,sym,lnr,cnr)
_ -> ScanInput input;
match_typespec = sym.repr == TypeSpecSymID;
match_from = sym.repr == FromSymID && imp;
match_import = sym.repr == ImportSymID && imp;
match_instance = sym.repr == InstanceSymID;
......@@ -536,7 +479,8 @@ where
RuleOrMacroDef :: !Int !Int !Bool !Bool !String !(List String) !(Input a) -> (!Input a, !List String,!IdentifierPositionList) | ScanInput a;
RuleOrMacroDef linenr charnr imp in_class cleanid imports input
| match_typespec = FoundDefinition cleanid sym linenr charnr imp imports input`;
| sym.repr == TypeSpecSymID
= FoundDefinition cleanid sym linenr charnr imp imports input`;
| match_synonym = FoundDefinition cleanid sym linenr charnr imp imports input`;
| match_variable = RuleOrMacroDef linenr charnr imp in_class cleanid imports input`
| match_is = FoundDefinition cleanid sym linenr charnr imp imports input`
......@@ -544,11 +488,9 @@ RuleOrMacroDef linenr charnr imp in_class cleanid imports input
= SkipToDefinition imp cleanid imports sym input`;
where
(input`,sym,_,_) = ScanInput input;
match_typespec = sym.repr == TypeSpecSymID;
match_synonym = sym.repr == SynonymSymID;
match_variable = sym.repr == IdentLowerSymID;
match_is = imp && (sym.repr == IsSymID || sym.repr == HashSymID || sym.repr == BarSymID); // only find rules without types in .icl XXX
InfixRuleDef :: !Bool !String !(List String) !(Input a) -> (!Input a, !List String,!IdentifierPositionList) | ScanInput a;
InfixRuleDef imp cleanid imports input
......@@ -568,33 +510,33 @@ where
InfixRuleDef1 :: !Int !Int !Bool !String !(List String) !(Input a) -> (!Input a, !List String,!IdentifierPositionList) | ScanInput a;
InfixRuleDef1 linenr charnr imp cleanid imports input
| match_typespec = trace_n ("InfixRuleDef1: match_typespec") FoundDefinition cleanid sym linenr charnr imp imports input`;
| sym.repr == TypeSpecSymID
= FoundDefinition cleanid sym linenr charnr imp imports input`;
| match_synonym = trace_n ("InfixRuleDef1: match_synonym") FoundDefinition cleanid sym linenr charnr imp imports input`;
| match_infix = trace_n ("InfixRuleDef1: match_infix") IRD linenr charnr imp cleanid imports input`
| match_variable = trace_n ("InfixRuleDef1: match_variable") InfixRuleDef1 linenr charnr imp cleanid imports input`;
= trace_n ("InfixRuleDef1: no_match") SkipToDefinition imp cleanid imports sym input`;
where
(input`,sym,_,_) = ScanInput input;
match_typespec = sym.repr == TypeSpecSymID;
match_synonym = sym.repr == SynonymSymID;
match_variable = sym.repr == IdentLowerSymID;
match_infix = sym.repr == InfixSymID;
IRD l c imp cleanid imports input
| match_typespec = trace_n ("IRD: match_typespec") FoundDefinition cleanid sym l c imp imports input`
| sym.repr == TypeSpecSymID
= FoundDefinition cleanid sym l c imp imports input`
| match_synonym = trace_n ("IRD: match_synonym") FoundDefinition cleanid sym l c imp imports input`
| match_digit
| match_typespec` = trace_n ("IRD: match_digit && match_typespec`") FoundDefinition cleanid sym l c imp imports input``
| sym`.repr == TypeSpecSymID
= FoundDefinition cleanid sym l c imp imports input``
| match_synonym` = trace_n ("IRD: match_digit && match_synonym`") FoundDefinition cleanid sym l c imp imports input``
= trace_n ("IRD: match_digit, no_match`") SkipToDefinition imp cleanid imports sym` input``
= trace_n ("IRD: no_match") SkipToDefinition imp cleanid imports sym input`
where
(input`,sym,_,_) = ScanInput input;
match_typespec = sym.repr == TypeSpecSymID;
match_synonym = sym.repr == SynonymSymID;
match_digit = sym.repr == DigitSymID;
(input``,sym`,_,_) = ScanInput input`;
match_typespec` = sym`.repr == TypeSpecSymID;
match_synonym` = sym`.repr == SynonymSymID;
TypeDef :: !Bool !String !(List String) !(Input a) -> (!Input a, !List String,!IdentifierPositionList) | ScanInput a;
......@@ -612,18 +554,18 @@ TypeDef imp cleanid imports input
(input`,sym,lnr,cnr) = ScanInput input;
match_typevar2 = IsTypeSymId sym.repr;
match_typevar1 = match_typevar2 && sym.string == cleanid;
Algebraic :: !Bool !String !(List String) !(Input a) -> (!Input a, !List String,!IdentifierPositionList) | ScanInput a;
Algebraic imp cleanid imports input
| sym.repr==IsSymID
= Constructors imp cleanid imports input`;
| sym.repr==SemiColonSymID || sym.repr==OpenBraceSymID
= SkipToDefinition imp cleanid imports sym input`;
| sym.repr<>EofSymID
= Algebraic imp cleanid imports input`;
= (input`,imports,PosNil);
where
(input`,sym,_,_) = ScanInput input;
Algebraic :: !Bool !String !(List String) !(Input a) -> (!Input a, !List String,!IdentifierPositionList) | ScanInput a;
Algebraic imp cleanid imports input
| sym.repr==IsSymID
= Constructors imp cleanid imports input`;
| sym.repr==SemiColonSymID || sym.repr==OpenBraceSymID
= SkipToDefinition imp cleanid imports sym input`;
| sym.repr<>EofSymID
= Algebraic imp cleanid imports input`;
= (input`,imports,PosNil);
where
(input`,sym,_,_) = ScanInput input;
Constructors :: !Bool !String !(List String) !(Input a) -> (!Input a, !List String,!IdentifierPositionList) | ScanInput a;
Constructors imp cleanid imports input
......@@ -669,7 +611,7 @@ NextFields imp cleanid imports input
= SkipToDefinition imp cleanid imports sym input1;
where
(input1,sym,_,_) = ScanInput input;
InfixConstructors :: !Bool !String !(List String) !(Input a) -> (!Input a, !List String,!IdentifierPositionList) | ScanInput a;
InfixConstructors imp cleanid imports input
| match_ident1 = FoundDefinition cleanid sym lnr cnr imp imports input`;
......@@ -679,7 +621,6 @@ InfixConstructors imp cleanid imports input
(input`,sym,lnr,cnr) = ScanInput input;
match_ident1 = match_ident2 && sym.string == cleanid;
match_ident2 = ConstrSymId sym.repr;
Braces :: !Int !Bool !String !(List String) !(Input a) -> (!Input a, !List String,!IdentifierPositionList) | ScanInput a;
Braces nesting imp cleanid imports input
......@@ -695,20 +636,6 @@ Braces nesting imp cleanid imports input
match_closebrace2 = sym.repr == CloseBraceSymID;
match_eof = sym.repr == EofSymID;
/*
ScanImports :: !(List String) !Input -> (!Input, !List String);
ScanImports imports input
| match_from = SkipToScanImports importsa syma inputa;
| match_import = SkipToScanImports importsb symb inputb;
= SkipToScanImports imports sym input`;
where
(input`,sym,_,_) = ScanInput input;
(inputa,syma,importsa) = ScanFrom imports input`;
(inputb,symb,importsb) = ScanImport imports input`;
match_from = sym.repr == FromSymID;
match_import = sym.repr == ImportSymID;
*/
ScanFrom :: !(List String) !(Input a) -> (!Input a, !Symbol, !List String) | ScanInput a;
ScanFrom imports input
# (input`,sym,_,_) = ScanInput input;
......@@ -727,7 +654,6 @@ where
ScanFromIdentImport imports input
# (input`,sym,_,_) = ScanInput input;
= (input`, sym, imports);
ScanImport :: !(List String) !(Input a) -> (!Input a, !Symbol, !List String) | ScanInput a;
ScanImport imports input
......@@ -741,27 +667,12 @@ where
| CommaSymId sym.repr = trace_n ("C0",sym) ScanImport imports input`;
= trace_n ("C1",sym) (input`,sym, imports);
/*
SkipToScanImports :: !(List String) !Symbol !Input -> (!Input, !List String);
SkipToScanImports imports sym input
| sym.repr==EofSymID
= (input, imports);
= ScanImports imports input;
*/
FoundDefinition :: !String !Symbol !Int Int !Bool !(List String) !(Input a) -> (!Input a, !List String,!IdentifierPositionList) | ScanInput a;
FoundDefinition cleanid sym linenr charnr imp imports input
# (input`,imports`,posl) = SkipToDefinition imp cleanid imports sym input
# posl` = Pos linenr charnr posl
= (input`, imports`, posl`);
/*
| imp
# (input,imports) = ScanImports imports input
= (input, imports, Pos linenr charnr PosNil)
= (input, imports, Pos linenr charnr PosNil)
*/
FoundInstance :: !String !Symbol !Int Int !Bool !(List String) !(Input a) -> (!Input a, !List String,!IdentifierPositionList) | ScanInput a;
FoundInstance cleanid sym linenr charnr imp imports input
# (input`,imports`,posl) = SkipToDefinition imp cleanid imports sym input
......@@ -789,6 +700,8 @@ SkipToDefinition imp cleanid imports sym=:{repr} input
FindSym :: !Int !Int !String -> (!Bool,!Int,!Symbol);
FindSym curpos curlen line
| curpos >= curlen = (False, curpos, ErrorSym);
# curchar = line.[curpos];
curpos` = inc curpos;
| curchar == ':' = FindColon1 curpos` curlen line;
| curchar == '=' = FindIs1 curpos` curlen line;
| curchar == '*' = FindStar1 curpos` curlen line;
......@@ -806,31 +719,25 @@ FindSym curpos curlen line
| UpperCase curchar = FindId1 IdentUpperSymID curpos curpos` curlen line;
| SpecialChar curchar = FindId2 IdentFunnySymID curpos curpos` curlen line;
| Digit curchar = (True,curpos`,DigitSym);
= (False, curpos`, ErrorSym);
where
curpos` = inc curpos;
curchar = line.[curpos];
= (False, curpos`, ErrorSym);
FindColon1 :: !Int !Int !String -> (!Bool, !Int, !Symbol);
FindColon1 curpos curlen line
| curpos >= curlen = FindId2 IdentFunnySymID (dec curpos) curpos curlen line;
# curchar = line.[curpos];
curpos` = inc curpos;
| curchar == '=' = FindColon2 curpos` curlen line;
| curchar == ':' = (True, curpos`, TypeSpecSym);
= FindId2 IdentFunnySymID (dec curpos) curpos curlen line;
where
curpos` = inc curpos;
curchar = line.[curpos];
where
FindColon2 :: !Int !Int !String -> (!Bool, !Int, !Symbol);
FindColon2 curpos curlen line
| curpos >= curlen = FindId2 IdentFunnySymID (dec curpos) curpos curlen line;
# curchar = line.[curpos];
curpos` = inc curpos;
| curchar == '=' = (True, curpos`, SynonymSym);
= FindId2 IdentFunnySymID (curpos-2) curpos curlen line;
FindColon2 :: !Int !Int !String -> (!Bool, !Int, !Symbol);
FindColon2 curpos curlen line
| curpos >= curlen = FindId2 IdentFunnySymID (dec curpos) curpos curlen line;
| curchar == '=' = (True, curpos`, SynonymSym);
= FindId2 IdentFunnySymID (curpos-2) curpos curlen line;
where
curpos` = inc curpos;
curchar = line.[curpos];
FindIs1 :: !Int !Int !String -> (!Bool, !Int, !Symbol);
FindIs1 curpos curlen line
| curpos >= curlen = (True, curpos, IsSym);
......@@ -879,6 +786,7 @@ FindReserved :: !SymbolId !Int !Int !Int !String -> (!Bool, !Int, !Symbol);
FindReserved symid start curpos curlen str
| start>=curpos
= (True,curpos,{repr=symid, string=str % (start,dec curpos)});
# first_char = str.[start];
| first_char=='f' && start+4==curpos && str.[start+1]=='r' && str.[start+2]=='o' && str.[start+3]=='m'
= (True,curpos,FromSym);
| first_char=='i' && start+6==curpos && str.[start+1]=='m' && str.[start+2]=='p' && str.[start+3]=='o'
......@@ -900,8 +808,6 @@ FindReserved symid start curpos curlen str
&& str.[start+4]=='e'
= (True,curpos,WhereSym);
= (True,curpos,{repr=symid, string=str % (start,dec curpos)});
where
first_char = str.[start];
FindId2 :: !SymbolId !Int !Int !Int !String -> (!Bool, !Int, !Symbol);
FindId2 symid start curpos curlen str
......@@ -939,7 +845,7 @@ StartInput file
where
(_,curpos,curlen,line,file`,linenr,charnr) = SkipLayOut1 False 0 0 0 "" file (-1) (-1);
offside = ApplyLayOutRule curpos curlen line;
StartInput` :: !*{String} -> Input *{String}
StartInput` file
= { offside = offside,
......@@ -971,7 +877,7 @@ EndInput {Input | file} = file
class ScanInput a
where
ScanInput :: !(Input *a) -> (!Input *a, !Symbol, !Int, !Int)
instance ScanInput File
where
// ScanInput :: !(Input *File) -> (!Input *File, !Symbol, !Int, !Int);
......@@ -1016,127 +922,100 @@ where
SkipLayOut1 :: !Bool !Int !Int !Int !String !*File !Int !Int
-> (!Bool, !Int, !Int, !String, !*File, !Int, !Int);
SkipLayOut1 offside nesting curpos curlen str text linenr charnr
| curpos >= curlen
| curpos >= curlen
= SkipToNewLine offside nesting text linenr charnr;
# curchar = str.[curpos];
| WhiteSpace curchar
= SkipLayOut1 offside nesting (inc curpos) curlen str text linenr (inc charnr);
| curchar == '\"'
= trace_n ('"',linenr,charnr,charnrq) SkipLayOut1 offside nesting curposq curlenq str text linenr charnrq;
# (curposq,curlenq,charnrq) = SkipQuote (inc curpos) curlen str (inc charnr);
= SkipLayOut1 offside nesting curposq curlenq str text linenr charnrq;
# more2 = inc curpos < curlen;
nextchar = str.[inc curpos];
| curchar=='/' && more2 && nextchar=='*'
= trace_n ("/*",linenr,charnr) SkipLayOut1 offside (inc nesting) (curpos+2) curlen str text linenr (charnr+2);
= SkipLayOut1 offside (inc nesting) (curpos+2) curlen str text linenr (charnr+2);
| curchar=='*' && more2 && nextchar=='/'
= trace_n ("*/",linenr,charnr) SkipLayOut1 offside nesting` (curpos+2) curlen str text linenr (charnr+2);
# nesting` = if (nesting==0) nesting (dec nesting);
= SkipLayOut1 offside nesting` (curpos+2) curlen str text linenr (charnr+2);
| curchar=='/' && more2 && nextchar=='/'
= trace_n ("//",linenr,charnr) SkipToNewLine offside nesting text linenr 0;
= SkipToNewLine offside nesting text linenr 0;
| nesting > 0
= SkipLayOut1 offside nesting (inc curpos) curlen str text linenr (inc charnr);
= (False, curpos, curlen, str, text, linenr, charnr);
where
curchar = str.[curpos];
nextchar = str.[inc curpos];
more2 = inc curpos < curlen;
nesting` | nesting==0 = nesting;
= dec nesting;
(curposq,curlenq,charnrq) = SkipQuote (inc curpos) curlen str (inc charnr);
where
SkipToNewLine :: !Bool !Int !*File !Int !Int
-> (!Bool, !Int, !Int, !String, !*File, !Int, !Int);
SkipToNewLine offside nesting text linenr charnr
# (str,text) = readLine text
# curlen = size str
| curlen==0
= (True, 0, 0, "", text, linenr, charnr)
# linenr = inc linenr
# newline = str.[0]== '\n'
| newline
= SkipToNewLine offside nesting text linenr 0
# semicolon = nesting == 0 && offside && curlen > 0 && NoLayOut (str.[0]) && NoComment str
| semicolon
= (False, 0, inc curlen, ";"+++str, text, linenr, -1)
= SkipLayOut1 offside nesting 0 curlen str text linenr 0
SkipLayOut1` :: !Bool !Int !Int !Int !String !*{String} !Int !Int
-> (!Bool, !Int, !Int, !String, !*{String}, !Int, !Int);
SkipLayOut1` offside nesting curpos curlen str text linenr charnr
| curpos >= curlen
| curpos >= curlen
= SkipToNewLine` offside nesting text linenr charnr;
# curchar = str.[curpos];
| WhiteSpace curchar
= SkipLayOut1` offside nesting (inc curpos) curlen str text linenr (inc charnr);
| curchar == '\"'
# (curposq,curlenq,charnrq) = SkipQuote (inc curpos) curlen str (inc charnr);
= SkipLayOut1` offside nesting curposq curlenq str text linenr charnrq;
# more2 = inc curpos < curlen;
nextchar = str.[inc curpos];
| curchar=='/' && more2 && nextchar=='*'
= SkipLayOut1` offside (inc nesting) (curpos+2) curlen str text linenr (charnr+2);
| curchar=='*' && more2 && nextchar=='/'
# nesting` = if (nesting==0) nesting (dec nesting);
= SkipLayOut1` offside nesting` (curpos+2) curlen str text linenr (charnr+2);
| curchar=='/' && more2 && nextchar=='/'
= SkipToNewLine` offside nesting text linenr 0;
| nesting > 0
= SkipLayOut1` offside nesting (inc curpos) curlen str text linenr (inc charnr);
= (False, curpos, curlen, str, text, linenr, charnr);
where
curchar = str.[curpos];
nextchar = str.[inc curpos];
more2 = inc curpos < curlen;
nesting` | nesting==0 = nesting;
= dec nesting;
(curposq,curlenq,charnrq) = SkipQuote (inc curpos) curlen str (inc charnr);
SkipToNewLine :: !Bool !Int !*File !Int !Int
-> (!Bool, !Int, !Int, !String, !*File, !Int, !Int);
SkipToNewLine offside nesting text linenr charnr
# (eof,text) = fend text
| eof
= (True, 0, 0, "", text, linenr, charnr)
# (str,text) = readLine text
# linenr = inc linenr
# curlen = size str
# newline = curlen > 0 && str.[0]== '\n'
| newline
= SkipToNewLine offside nesting text linenr 0
# semicolon = nesting == 0 && offside && curlen > 0 && NoLayOut (str.[0]) && NoComment str
| semicolon
= (False, 0, inc curlen, ";"+++str, text, linenr, -1)
= SkipLayOut1 offside nesting 0 curlen str text linenr 0
where
NoLayOut :: !Char -> Bool
NoLayOut c = c <> ' ' && c <> '\t'
NoComment :: !String -> Bool
NoComment s
| size s <= 1
= True
| curchar=='/' && nextchar=='*'
= False
| curchar=='*' && nextchar=='/'
= False
| curchar=='/' && nextchar=='/'
= False
= True
where
curchar = s.[0]
nextchar = s.[1]
SkipToNewLine` :: !Bool !Int !*{String} !Int !Int
-> (!Bool, !Int, !Int, !String, !*{String}, !Int, !Int);
SkipToNewLine` offside nesting text linenr charnr
# (siz,text) = usize text
# eof = dec siz == linenr
| eof
= (True, 0, 0, "", text, linenr, charnr)