Commit 13efbf36 authored by John van Groningen's avatar John van Groningen

add searching of generic definitions,

fix line comments and strings inside nested comments
parent 3f65e074
......@@ -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 [a=:(DefFun an al):as] [d=:(DefFun dn dl):ds]
| an==dn
| al<dl
= purge_and_reverse [a:as] ds
= purge_and_reverse [d:as] ds
= purge_and_reverse [d,a:as] ds
same (DefFun l _) (DefFun l` _) = l == l`
//same (DefType l _) (DefType l` _) = l == l`
//same (DefClass l _) (DefClass l` _) = l == l`
//same (DefInst l m _) (DefInst l` m` _) = l == l` && m == m`
same _ _ = False
purge_and_reverse [a:as] [d:ds]
= purge_and_reverse [d,a:as] ds
//==== 13/20 transition hack...
// Wrap...
......
......@@ -62,10 +62,12 @@ IsTypeSpec :: !String -> 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)
......@@ -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
......@@ -104,6 +108,18 @@ FindDefinesInText text files
FindDefsInInput :: !DefinesState !(Input a) -> (!DefinesState,!(Input a)) | ScanInput a
FindDefsInInput state input
# (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
......@@ -119,7 +135,31 @@ 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]}
#! 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 == TypeSpecSymID //=> type def
# (input,sym,line,_) = ScanInput input
......@@ -142,30 +182,23 @@ 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...
= instance_or_derive_definition sym.string DefInst state input
= 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]}
| 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
// or uniqueness & strictness attributes...
//...
= FindDefsInInput state input
| 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
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,"")
......@@ -195,15 +228,40 @@ ScanMatch str open close (oString,cString) depth input
-> 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
ScanGlobal 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
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
= (input,sym,line,char)
| char == 0
= (input,sym,line,char)
= ScanGlobal input
= (state,input)
| char==0
= find_definitions input sym line state
= FindDefsInInput state input
// Find the identifiers in the .dcl and the .icl files;
......@@ -323,6 +381,8 @@ 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`;
| 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
......@@ -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,6 +540,11 @@ 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`
| 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;
......@@ -624,13 +684,17 @@ 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;
......@@ -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
......@@ -782,31 +853,40 @@ 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);
......@@ -818,7 +898,6 @@ FindId2 symid start curpos curlen str
curchar = str.[curpos];
curpos` = inc curpos;
/* Aux. functions for parsing text in a file */
OpenTextFile :: !String !Files -> (!Files, !Bool, !*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);
| 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 !*{String} !Int !Int
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment