diff --git a/Ide/IDE.icl b/Ide/IDE.icl index 8cbd174dd913886f4a2fbd1813b351e66eb69141..9de7c000974baaa0c0149ddc33b50e5495d42bcb 100644 --- a/Ide/IDE.icl +++ b/Ide/IDE.icl @@ -1059,6 +1059,13 @@ where = cl1 < cl2 sort (DefInst _ _ _) _ = True sort _ (DefInst _ _ _) = False + sort (DefGeneric id1 _) (DefGeneric id2 _) = id1 < id2 + sort (DefGeneric _ _) _ = True + sort _ (DefGeneric _ _) = False + sort (DefDerive cl1 id1 _)(DefDerive cl2 id2 _) | cl1 == cl2 = id1 < id2 + = cl1 < cl2 + sort (DefDerive _ _ _) _ = True + sort _ (DefDerive _ _ _) = False sort (DefFun id1 _) (DefFun id2 _) = id1 < id2 sort (DefFun _ _) _ = True sort _ (DefFun _ _) = False @@ -1068,6 +1075,8 @@ toMenuItem (DefFun id ln) = MenuItem (id) [MenuFunction (menfun ln)] toMenuItem (DefType id ln) = MenuItem (":: "+++.id) [MenuFunction (menfun ln)] toMenuItem (DefClass id ln) = MenuItem ("class "+++.id) [MenuFunction (menfun ln)] toMenuItem (DefInst cl id ln) = MenuItem ("instance "+++.cl+++." "+++.id) [MenuFunction (menfun ln)] +toMenuItem (DefGeneric id ln) = MenuItem ("generic "+++.id) [MenuFunction (menfun ln)] +toMenuItem (DefDerive cl id ln) = MenuItem ("derive "+++.cl+++." "+++.id) [MenuFunction (menfun ln)] menfun ln (ls,ps) # (_,ps) = sendToActiveWindow (msgScrollToLine ln) ps @@ -1082,16 +1091,14 @@ purge_and_reverse acc [] = acc purge_and_reverse [] [h:t] = purge_and_reverse [h] t -purge_and_reverse [a:as] [d:ds] - | same a d - = purge_and_reverse [d:as] ds +purge_and_reverse [a=:(DefFun an al):as] [d=:(DefFun dn dl):ds] + | an==dn + | al
Bool; IsImportError13 :: !String -> (!Bool,!String); IsImportError20 :: !String -> (!Bool,!String); -// x-perimental... :: Def - = DefFun String Int - | DefType String Int - | DefClass String Int - | DefInst String String Int + = DefFun !String !Int + | DefType !String !Int + | DefClass !String !Int + | DefInst !String !String !Int + | DefGeneric !String !Int + | DefDerive !String !String !Int + FindDefinesInText :: !*{String} !Files -> (![Def],!Files) diff --git a/Pm/PmParse.icl b/Pm/PmParse.icl index f1dbb121dba3a18a83b844d909916149f73e45f6..009f71bb6a8904ea38c26b4e6b147016ca6f65b4 100644 --- a/Pm/PmParse.icl +++ b/Pm/PmParse.icl @@ -50,12 +50,14 @@ IdentUpperSymID :== 14; IdentFunnySymID :== 15; FromSymID :== 16; ImportSymID :== 17; -InstanceSymID :== 19; -ClassSymID :== 20; -InfixSymID :== 21; -DigitSymID :== 22; -WhereSymID :== 23; -HashSymID :== 24; +InstanceSymID :== 18; +ClassSymID :== 19; +InfixSymID :== 20; +DigitSymID :== 21; +WhereSymID :== 22; +HashSymID :== 23; +GenericSymID :== 24; +DeriveSymID :== 25; EofSym :== {repr = EofSymID ,string = ""}; ErrorSym :== {repr = ErrorSymID ,string = ""}; @@ -86,13 +88,15 @@ ConstrSymId id :== id == IdentUpperSymID || id == IdentFunnySymID; CommaSymId id :== id == CommaSymID :: DefinesState = - { syms :: ![Def] - } + { syms :: ![Def] } + :: Def - = DefFun String Int - | DefType String Int - | DefClass String Int - | DefInst String String Int + = DefFun !String !Int + | DefType !String !Int + | DefClass !String !Int + | DefInst !String !String !Int + | DefGeneric !String !Int + | DefDerive !String !String !Int FindDefinesInText :: !*{String} !Files -> (![Def],!Files) FindDefinesInText text files @@ -103,107 +107,161 @@ FindDefinesInText text files FindDefsInInput :: !DefinesState !(Input a) -> (!DefinesState,!(Input a)) | ScanInput a FindDefsInInput state input - # (input,sym,line,_) = ScanGlobal input - | sym.repr == EofSymID - = (state,input) - | sym.repr == ClassSymID //=> class def - # (input,sym,line,_) = ScanInput input - | sym.repr == IdentLowerSymID || sym.repr == IdentUpperSymID || sym.repr == IdentFunnySymID - # state = {state & syms = [DefClass sym.string line:state.syms]} - = FindDefsInInput state input - | sym.repr == OpenSymID //=> infix class def + # (input,sym,line,_) = ScanGlobal input + = find_definitions input sym line state +where + ScanGlobal input + # (input,sym,line,char) = ScanInput input + | sym.repr == EofSymID + = (input,sym,line,char) + | char == 0 + = (input,sym,line,char) + = ScanGlobal input + + find_definitions :: !(Input a) !Symbol !Int !DefinesState -> (!DefinesState,!(Input a)) | ScanInput a + find_definitions input sym=:{repr} line state + | sym.repr == EofSymID + = (state,input) + | sym.repr == ClassSymID //=> class def # (input,sym,line,_) = ScanInput input | sym.repr == IdentLowerSymID || sym.repr == IdentUpperSymID || sym.repr == IdentFunnySymID # state = {state & syms = [DefClass sym.string line:state.syms]} = FindDefsInInput state input + | sym.repr == OpenSymID //=> infix class def + # (input,sym,line,_) = ScanInput input + | sym.repr == IdentLowerSymID || sym.repr == IdentUpperSymID || sym.repr == IdentFunnySymID + # state = {state & syms = [DefClass sym.string line:state.syms]} + = FindDefsInInput state input + = FindDefsInInput state input = FindDefsInInput state input - = FindDefsInInput state input - | sym.repr == IdentLowerSymID || sym.repr == IdentUpperSymID || sym.repr == IdentFunnySymID //=> fun or macro def - # state = {state & syms = [DefFun sym.string line:state.syms]} - = FindDefsInInput state input - | sym.repr == TypeSpecSymID //=> type def - # (input,sym,line,_) = ScanInput input - | sym.repr == IdentLowerSymID || sym.repr == IdentUpperSymID || sym.repr == IdentFunnySymID - # state = {state & syms = [DefType sym.string line:state.syms]} + | sym.repr == IdentLowerSymID || sym.repr == IdentUpperSymID || sym.repr == IdentFunnySymID //=> fun or macro def + #! function_name = sym.string + # (input,sym,line,char) = ScanInput input + // generic function ? + | sym.repr==OpenBraceSymID && char<>0 + # (input,sym,line,char) = ScanInput input + | sym.repr==BarSymID && char<>0 + # (input,sym,line,char) = ScanInput input + #! type_name = sym.string + | (sym.repr == IdentLowerSymID || sym.repr == IdentUpperSymID || sym.repr == IdentFunnySymID) && char<>0 + # (input,sym,line,char) = ScanInput input + | sym.repr==BarSymID && char<>0 + # (input,sym,line,char) = ScanInput input + | sym.repr==CloseBraceSymID && char<>0 + #! name = function_name+++"{|"+++type_name+++"|}" + # state = {state & syms = [DefFun name line:state.syms]} + = FindDefsInInput state input + # state = {state & syms = [DefFun function_name line:state.syms]} + = FindDefsInInput state input + # state = {state & syms = [DefFun function_name line:state.syms]} + = FindDefsInInput state input + # state = {state & syms = [DefFun function_name line:state.syms]} + = FindDefsInInput state input + # state = {state & syms = [DefFun function_name line:state.syms]} + = FindDefsInInput state input + # state = {state & syms = [DefFun function_name line:state.syms]} = FindDefsInInput state input - | sym.repr == UniqueAttrSymID //=> unique type def + | sym.repr == TypeSpecSymID //=> type def # (input,sym,line,_) = ScanInput input | sym.repr == IdentLowerSymID || sym.repr == IdentUpperSymID || sym.repr == IdentFunnySymID - # state = {state & syms = [DefType ("*"+++. sym.string) line:state.syms]} + # state = {state & syms = [DefType sym.string line:state.syms]} + = FindDefsInInput state input + | sym.repr == UniqueAttrSymID //=> unique type def + # (input,sym,line,_) = ScanInput input + | sym.repr == IdentLowerSymID || sym.repr == IdentUpperSymID || sym.repr == IdentFunnySymID + # state = {state & syms = [DefType ("*"+++. sym.string) line:state.syms]} + = FindDefsInInput state input = FindDefsInInput state input = FindDefsInInput state input - = FindDefsInInput state input - | sym.repr == OpenSymID //=> infix operator def - # (input,sym,line,_) = ScanInput input - | sym.repr == IdentLowerSymID || sym.repr == IdentUpperSymID || sym.repr == IdentFunnySymID - # state = {state & syms = [DefFun sym.string line:state.syms]} + | sym.repr == OpenSymID //=> infix operator def + # (input,sym,line,_) = ScanInput input + | sym.repr == IdentLowerSymID || sym.repr == IdentUpperSymID || sym.repr == IdentFunnySymID + # state = {state & syms = [DefFun sym.string line:state.syms]} + = FindDefsInInput state input = FindDefsInInput state input - = FindDefsInInput state input - | sym.repr == InstanceSymID //=> instance def - # (input,sym,line,_) = ScanInput input - | sym.repr == IdentLowerSymID || sym.repr == IdentUpperSymID || sym.repr == IdentFunnySymID - # (input,sym`,line,_) = ScanInput input - | sym`.repr == IdentLowerSymID || sym`.repr == IdentUpperSymID || sym`.repr == IdentFunnySymID - # state = {state & syms = [DefInst sym.string sym`.string line:state.syms]} - // can be a list in .dcl so need to read on for CommaSymId... + | sym.repr == InstanceSymID //=> instance def + # (input,sym,line,_) = ScanInput input + | sym.repr == IdentLowerSymID || sym.repr == IdentUpperSymID || sym.repr == IdentFunnySymID + = instance_or_derive_definition sym.string DefInst state input + = FindDefsInInput state input + | repr==GenericSymID + # (input,sym,line,_) = ScanInput input + | sym.repr == IdentLowerSymID || sym.repr == IdentUpperSymID || sym.repr == IdentFunnySymID + # state = {state & syms = [DefGeneric sym.string line:state.syms]} = FindDefsInInput state input - | sym`.repr == OpenSymID || sym`.repr == OpenBraceSymID - // save contents upto matching close sym... - # closeSym = case sym`.repr of - OpenSymID -> CloseSymID - OpenBraceSymID -> CloseBraceSymID - # (oString,cString) = case sym`.repr of - OpenSymID -> ("(",")") - OpenBraceSymID -> ("{","}") - # (input,str) = ScanMatch oString sym`.repr closeSym (oString,cString) 0 input - # state = {state & syms = [DefInst sym.string str line:state.syms]} = FindDefsInInput state input - // or uniqueness & strictness attributes... - //... + | repr==DeriveSymID + # (input,sym,line,_) = ScanInput input + | sym.repr == IdentLowerSymID || sym.repr == IdentUpperSymID || sym.repr == IdentFunnySymID + = instance_or_derive_definition sym.string DefDerive 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 + = (input,"") + | sym.repr == open + = ScanMatch (str +++. oString) open close (oString,cString) (inc depth) input + | sym.repr == close + | depth == 0 + = (input, str +++. cString) + = ScanMatch (str +++. cString) open close (oString,cString) (dec depth) input + = case sym.repr of + BarSymID -> ScanMatch (str +++. "|") open close (oString,cString) depth input + CloseSymID -> ScanMatch (str +++. ")") open close (oString,cString) depth input + CloseBraceSymID -> ScanMatch (str +++. "}") open close (oString,cString) depth input + CommaSymID -> ScanMatch (str +++. ",") open close (oString,cString) depth input + IsSymID -> ScanMatch (str +++. "=") open close (oString,cString) depth input + OpenBraceSymID -> ScanMatch (str +++. "{") open close (oString,cString) depth input + OpenSymID -> ScanMatch (str +++. "(") open close (oString,cString) depth input + SynonymSymID -> ScanMatch (str +++. ":==") open close (oString,cString) depth input + SemiColonSymID -> ScanMatch (str +++. ";") open close (oString,cString) depth input + TypeSpecSymID -> ScanMatch (str +++. "::") open close (oString,cString) depth input + FromSymID -> ScanMatch (str +++. "from") open close (oString,cString) depth input + ImportSymID -> ScanMatch (str +++. "import") open close (oString,cString) depth input + InstanceSymID -> ScanMatch (str +++. "instance") open close (oString,cString) depth input + ClassSymID -> ScanMatch (str +++. "class") open close (oString,cString) depth input + InfixSymID -> ScanMatch (str +++. "infix") open close (oString,cString) depth input + DigitSymID # (char,input) = input!line.[char] + -> ScanMatch (str +++. {char}) open close (oString,cString) depth input + WhereSymID -> ScanMatch (str +++. "where") open close (oString,cString) depth input + HashSymID -> ScanMatch (str +++. "#") open close (oString,cString) depth input + GenericSymID -> ScanMatch (str +++. "generic") open close (oString,cString) depth input + DeriveSymID -> ScanMatch (str +++. "derive") open close (oString,cString) depth input + _ -> ScanMatch (str +++. sym.string) open close (oString,cString) depth input + + instance_or_derive_definition name make_def state input + # (input,sym`,line,_) = ScanInput input + | sym`.repr == IdentLowerSymID || sym`.repr == IdentUpperSymID || sym`.repr == IdentFunnySymID + # state = {state & syms = [make_def name sym`.string line:state.syms]} + // can be a list in .dcl so need to read on for CommaSymId... + = more_instance_or_derive_types name make_def state input + | sym`.repr == OpenSymID || sym`.repr == OpenBraceSymID + // save contents upto matching close sym... + # closeSym = case sym`.repr of + OpenSymID -> CloseSymID + OpenBraceSymID -> CloseBraceSymID + # (oString,cString) = case sym`.repr of + OpenSymID -> ("(",")") + OpenBraceSymID -> ("{","}") + # (input,str) = ScanMatch oString sym`.repr closeSym (oString,cString) 0 input + # state = {state & syms = [make_def name str line:state.syms]} + = more_instance_or_derive_types name make_def state input + // or uniqueness & strictness attributes... + //... = 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 - = (input,"") - | sym.repr == open - = ScanMatch (str +++. oString) open close (oString,cString) (inc depth) input - | sym.repr == close - | depth == 0 - = (input, str +++. cString) - = ScanMatch (str +++. cString) open close (oString,cString) (dec depth) input - = case sym.repr of - BarSymID -> ScanMatch (str +++. "|") open close (oString,cString) depth input - CloseSymID -> ScanMatch (str +++. ")") open close (oString,cString) depth input - CloseBraceSymID -> ScanMatch (str +++. "}") open close (oString,cString) depth input - CommaSymID -> ScanMatch (str +++. ",") open close (oString,cString) depth input - IsSymID -> ScanMatch (str +++. "=") open close (oString,cString) depth input - OpenBraceSymID -> ScanMatch (str +++. "{") open close (oString,cString) depth input - OpenSymID -> ScanMatch (str +++. "(") open close (oString,cString) depth input - SynonymSymID -> ScanMatch (str +++. ":==") open close (oString,cString) depth input - SemiColonSymID -> ScanMatch (str +++. ";") open close (oString,cString) depth input - TypeSpecSymID -> ScanMatch (str +++. "::") open close (oString,cString) depth input - FromSymID -> ScanMatch (str +++. "from") open close (oString,cString) depth input - ImportSymID -> ScanMatch (str +++. "import") open close (oString,cString) depth input - InstanceSymID -> ScanMatch (str +++. "instance") open close (oString,cString) depth input - ClassSymID -> ScanMatch (str +++. "class") open close (oString,cString) depth input - InfixSymID -> ScanMatch (str +++. "infix") open close (oString,cString) depth input - DigitSymID # (char,input) = input!line.[char] - -> ScanMatch (str +++. {char}) open close (oString,cString) depth input - WhereSymID -> ScanMatch (str +++. "where") open close (oString,cString) depth input - HashSymID -> ScanMatch (str +++. "#") open close (oString,cString) depth input - _ -> ScanMatch (str +++. sym.string) open close (oString,cString) depth input - -ScanGlobal input - # (input,sym,line,char) = ScanInput input - | sym.repr == EofSymID - = (input,sym,line,char) - | char == 0 - = (input,sym,line,char) - = ScanGlobal input + + more_instance_or_derive_types name make_def state input + # (input,sym,line,char) = ScanInput input + | sym.repr == CommaSymID + = instance_or_derive_definition name make_def state input + | sym.repr == EofSymID + = (state,input) + | char==0 + = find_definitions input sym line state + = FindDefsInInput state input // Find the identifiers in the .dcl and the .icl files; @@ -323,7 +381,9 @@ Definition1 maybe_sym imp cleanid imports input | match_ident = RuleOrMacroDef lnr cnr imp False cleanid imports input`; | match_open = trace_n ("Definition1: match_open: "+++toString lnr) InfixRuleDef imp cleanid imports input`; | match_where = RuleOrInfixRuleDef imp cleanid imports input`; - = SkipToDefinition imp cleanid imports sym input`; + | sym.repr == GenericSymID || sym.repr == DeriveSymID + = generic_or_derive_definition imp cleanid imports input`; + = SkipToDefinition imp cleanid imports sym input`; where (input`,sym,lnr,cnr) = case maybe_sym of Just (sym,lnr,cnr) -> (input,sym,lnr,cnr) @@ -410,21 +470,16 @@ where | sym.repr == IdentFunnySymID && sym.string == "&" = ClassContext imp cleanid imports sym input | sym.repr == SemiColonSymID -// = Definition1 Nothing imp cleanid imports input -//* # (input,sym,lnr,cnr) = ScanInput input | sym.repr == WhereSymID = trace_n ("lookforclassvar","ClassMemberDef") ClassMemberDef imp cleanid imports input = trace_n ("lookforclassvar","Definition1",sym) Definition1 (Just (sym,lnr,cnr)) imp cleanid imports input -//*/ | sym.repr == WhereSymID = ClassMemberDef imp cleanid imports input = SkipToDefinition imp cleanid imports sym input = SkipToDefinition imp cleanid imports sym input ClassMemberDef imp cleanid imports input // =:{} need to track indent level here... -// = RuleOrInfixRuleDef imp cleanid imports input -///* # (input,sym,lnr,cnr) = ScanInput input # match_semicolon = trace_n ("ClassMemberDef",lnr,sym) sym.repr == SemiColonSymID | match_semicolon = trace_n (lnr ," semicolon") Definition1 Nothing imp cleanid imports input @@ -485,7 +540,12 @@ RuleOrMacroDef linenr charnr imp in_class cleanid imports input | match_variable = RuleOrMacroDef linenr charnr imp in_class cleanid imports input` | match_is = FoundDefinition cleanid sym linenr charnr imp imports input` | in_class = ClassMemberDef imp cleanid imports input` - = SkipToDefinition imp cleanid imports sym input`; + | sym.repr == OpenBraceSymID + # (input``,sym,_,_) = ScanInput input` + | sym.repr==BarSymID + = FoundDefinition cleanid sym linenr charnr imp imports input`` + = braces_sym sym 1 imp cleanid imports input`` + = SkipToDefinition imp cleanid imports sym input`; where (input`,sym,_,_) = ScanInput input; match_synonym = sym.repr == SynonymSymID; @@ -624,18 +684,22 @@ InfixConstructors imp cleanid imports input Braces :: !Int !Bool !String !(List String) !(Input a) -> (!Input a, !List String,!IdentifierPositionList) | ScanInput a; Braces nesting imp cleanid imports input - | match_openbrace = Braces (inc nesting) imp cleanid imports input`; - | match_closebrace1 = Definition1 Nothing imp cleanid imports input`; - | match_closebrace2 = Braces (dec nesting) imp cleanid imports input`; - | match_eof = (input`,imports,PosNil); - = Braces nesting imp cleanid imports input`; + # (input`,sym,_,_) = ScanInput input; + = braces_sym sym nesting imp cleanid imports input`; + +braces_sym :: !Symbol !Int !Bool !String !(List String) !(Input a) -> (!Input a, !List String,!IdentifierPositionList) | ScanInput a; +braces_sym sym nesting imp cleanid imports input + | match_openbrace = Braces (inc nesting) imp cleanid imports input; + | match_closebrace1 = Definition1 Nothing imp cleanid imports input; + | match_closebrace2 = Braces (dec nesting) imp cleanid imports input; + | match_eof = (input,imports,PosNil); + = Braces nesting imp cleanid imports input; where - (input`,sym,_,_) = ScanInput input; match_openbrace = sym.repr == OpenBraceSymID; match_closebrace1 = match_closebrace2 && nesting == 1; match_closebrace2 = sym.repr == CloseBraceSymID; match_eof = sym.repr == EofSymID; - + ScanFrom :: !(List String) !(Input a) -> (!Input a, !Symbol, !List String) | ScanInput a; ScanFrom imports input # (input`,sym,_,_) = ScanInput input; @@ -667,6 +731,13 @@ where | CommaSymId sym.repr = trace_n ("C0",sym) ScanImport imports input`; = trace_n ("C1",sym) (input`,sym, imports); +generic_or_derive_definition :: !Bool !String !(List String) !(Input a) -> (!Input a, !List String,!IdentifierPositionList) | ScanInput a; +generic_or_derive_definition imp cleanid imports input + # (input`,sym,lnr,cnr) = ScanInput input; + | IdentSymId sym.repr && sym.string == cleanid + = FoundDefinition cleanid sym lnr cnr imp imports input`; + = SkipToDefinition imp cleanid imports sym 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 @@ -745,7 +816,7 @@ FindIs1 curpos curlen line = (True, curpos, IsSym); where curchar = line.[curpos]; - + FindHash1 :: !Int !Int !String -> (!Bool, !Int, !Symbol); FindHash1 curpos curlen line | curpos >= curlen = (True, curpos, HashSym); @@ -753,7 +824,7 @@ FindHash1 curpos curlen line = (True, curpos, HashSym); where curchar = line.[curpos]; - + FindBar1 :: !Int !Int !String -> (!Bool, !Int, !Symbol); FindBar1 curpos curlen line | curpos >= curlen = (True, curpos, BarSym); @@ -782,33 +853,42 @@ FindId1 symid start curpos curlen str curchar = str.[curpos]; curpos` = inc curpos; +eq3chars1 s i c1 c2 c3 + :== s.[i+1]==c1 && s.[i+2]==c2 && s.[i+3]==c3 +eq4chars1 s i c1 c2 c3 c4 + :== s.[i+1]==c1 && s.[i+2]==c2 && s.[i+3]==c3 && s.[i+4]==c4 +eq5chars1 s i c1 c2 c3 c4 c5 + :== s.[i+1]==c1 && s.[i+2]==c2 && s.[i+3]==c3 && s.[i+4]==c4 && s.[i+5]==c5 +eq6chars1 s i c1 c2 c3 c4 c5 c6 + :== s.[i+1]==c1 && s.[i+2]==c2 && s.[i+3]==c3 && s.[i+4]==c4 && s.[i+5]==c5 && s.[i+6]==c6 +eq7chars1 s i c1 c2 c3 c4 c5 c6 c7 + :== s.[i+1]==c1 && s.[i+2]==c2 && s.[i+3]==c3 && s.[i+4]==c4 && s.[i+5]==c5 && s.[i+6]==c6 && s.[i+7]==c7 + 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' + | first_char=='f' && start+4==curpos && eq3chars1 str start 'r' 'o' 'm' = (True,curpos,FromSym); - | first_char=='i' && start+6==curpos && str.[start+1]=='m' && str.[start+2]=='p' && str.[start+3]=='o' - && str.[start+4]=='r' && str.[start+5]=='t' + | first_char=='i' && start+6==curpos && eq5chars1 str start 'm' 'p' 'o' 'r' 't' = (True,curpos,ImportSym); - | first_char=='i' && start+8==curpos && str.[start+1]=='n' && str.[start+2]=='s' && str.[start+3]=='t' - && str.[start+4]=='a' && str.[start+5]=='n' && str.[start+6]=='c' && str.[start+7]=='e' + | first_char=='i' && start+8==curpos && eq7chars1 str start 'n' 's' 't' 'a' 'n' 'c' 'e' = (True,curpos,InstanceSym); - | first_char=='c' && start+5==curpos && str.[start+1]=='l' && str.[start+2]=='a' && str.[start+3]=='s' - && str.[start+4]=='s' + | first_char=='c' && start+5==curpos && eq4chars1 str start 'l' 'a' 's' 's' = (True,curpos,ClassSym); - | first_char=='i' && start+5==curpos && str.[start+1]=='n' && str.[start+2]=='f' && str.[start+3]=='i' - && str.[start+4]=='x' + | first_char=='i' && start+5==curpos && eq4chars1 str start 'n' 'f' 'i' 'x' = (True,curpos,InfixSym); - | first_char=='i' && start+6==curpos && str.[start+1]=='n' && str.[start+2]=='f' && str.[start+3]=='i' - && str.[start+4]=='x' && (str.[start+5]=='l' || str.[start+5]=='r') + | first_char=='i' && start+6==curpos && eq4chars1 str start 'n' 'f' 'i' 'x' && (str.[start+5]=='l' || str.[start+5]=='r') = (True,curpos,InfixSym); - | first_char=='w' && start+5==curpos && str.[start+1]=='h' && str.[start+2]=='e' && str.[start+3]=='r' - && str.[start+4]=='e' + | first_char=='w' && start+5==curpos && eq4chars1 str start 'h' 'e' 'r' 'e' = (True,curpos,WhereSym); + | first_char=='g' && start+7==curpos && eq6chars1 str start 'e' 'n' 'e' 'r' 'i' 'c' + = (True,curpos,{repr=GenericSymID,string=""}); + | first_char=='d' && start+6==curpos && eq5chars1 str start 'e' 'r' 'i' 'v' 'e' + = (True,curpos,{repr=DeriveSymID,string=""}); = (True,curpos,{repr=symid, string=str % (start,dec curpos)}); - + FindId2 :: !SymbolId !Int !Int !Int !String -> (!Bool, !Int, !Symbol); FindId2 symid start curpos curlen str | curpos >= curlen = (True, curpos, {repr=symid, string=str % (start,dec curpos)}); @@ -817,7 +897,6 @@ FindId2 symid start curpos curlen str where curchar = str.[curpos]; curpos` = inc curpos; - /* Aux. functions for parsing text in a file */ @@ -927,9 +1006,6 @@ SkipLayOut1 offside nesting curpos curlen str 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=='*' @@ -937,10 +1013,13 @@ SkipLayOut1 offside nesting curpos curlen str text linenr charnr | 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); + | curchar == '\"' + # (curposq,curlenq,charnrq) = SkipQuote (inc curpos) curlen str (inc charnr); + = SkipLayOut1 offside nesting curposq curlenq str text linenr charnrq; + | curchar=='/' && more2 && nextchar=='/' + = SkipToNewLine offside nesting text linenr 0; = (False, curpos, curlen, str, text, linenr, charnr); where SkipToNewLine :: !Bool !Int !*File !Int !Int @@ -967,9 +1046,6 @@ SkipLayOut1` offside nesting curpos curlen str 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=='*' @@ -977,10 +1053,13 @@ SkipLayOut1` offside nesting curpos curlen str text linenr charnr | curchar=='*' && more2 && nextchar=='/' # nesting` = if (nesting==0) nesting (dec nesting); = SkipLayOut1` offside nesting` (curpos+2) curlen str text linenr (charnr+2); + | nesting > 0 + = 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; | 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 SkipToNewLine` :: !Bool !Int !*{String} !Int !Int @@ -1048,7 +1127,7 @@ IsSubStr subpos substop substr pos stop str SpecialChar :: !Char -> Bool; SpecialChar c = pos < speciallen; - where + where pos = FindChar c special speciallen 0; special = "~@#$%^?!+-*<>\\/|&=:."; speciallen = size special;