Commit 4a8b2555 authored by Pieter Koopman's avatar Pieter Koopman
Browse files

Context -> ScanContext

various small things like operators of the form ::>
parent 35ab261c
...@@ -113,7 +113,7 @@ instance <<< FilePosition ...@@ -113,7 +113,7 @@ instance <<< FilePosition
| ExistsToken // E. | ExistsToken // E.
| ForAllToken // A. | ForAllToken // A.
:: Context :: ScanContext
= GeneralContext = GeneralContext
| TypeContext | TypeContext
| FunctionContext | FunctionContext
...@@ -129,13 +129,13 @@ instance getFilename ScanState ...@@ -129,13 +129,13 @@ instance getFilename ScanState
class tokenBack state :: !*state -> !*state class tokenBack state :: !*state -> !*state
instance tokenBack ScanState instance tokenBack ScanState
class nextToken state :: !Context !*state -> (!Token, !*state) class nextToken state :: !ScanContext !*state -> (!Token, !*state)
instance nextToken ScanState instance nextToken ScanState
class currentToken state :: !*state -> (!Token, !*state) class currentToken state :: !*state -> (!Token, !*state)
instance currentToken ScanState instance currentToken ScanState
class insertToken state :: !Token !Context !*state -> *state class insertToken state :: !Token !ScanContext !*state -> *state
instance insertToken ScanState instance insertToken ScanState
class replaceToken state :: !Token !*state -> *state class replaceToken state :: !Token !*state -> *state
......
...@@ -97,7 +97,7 @@ ScanOptionNoNewOffsideForSeqLetBit:==4; ...@@ -97,7 +97,7 @@ ScanOptionNoNewOffsideForSeqLetBit:==4;
{ lt_position :: ! FilePosition // Start position of this token { lt_position :: ! FilePosition // Start position of this token
, lt_index :: ! Int // The index in the current line , lt_index :: ! Int // The index in the current line
, lt_token :: ! Token // The token itself , lt_token :: ! Token // The token itself
, lt_context :: ! Context // The context of the token , lt_context :: ! ScanContext // The context of the token
} }
:: Buffer x :: Buffer x
...@@ -200,13 +200,13 @@ ScanOptionNoNewOffsideForSeqLetBit:==4; ...@@ -200,13 +200,13 @@ ScanOptionNoNewOffsideForSeqLetBit:==4;
| ForAllToken // A. | ForAllToken // A.
:: Context :: ScanContext
= GeneralContext = GeneralContext
| TypeContext | TypeContext
| FunctionContext | FunctionContext
| CodeContext | CodeContext
instance == Context instance == ScanContext
where where
(==) co1 co2 = equal_constructor co1 co2 (==) co1 co2 = equal_constructor co1 co2
...@@ -283,7 +283,7 @@ where ...@@ -283,7 +283,7 @@ where
# (index,stream) = getIndex stream # (index,stream) = getIndex stream
= (index,{input & inp_stream=stream}) = (index,{input & inp_stream=stream})
class nextToken state :: !Context !*state -> (!Token, !*state) class nextToken state :: !ScanContext !*state -> (!Token, !*state)
instance nextToken RScanState instance nextToken RScanState
where where
...@@ -397,7 +397,7 @@ where currentToken scanState=:{ss_tokenBuffer} ...@@ -397,7 +397,7 @@ where currentToken scanState=:{ss_tokenBuffer}
= (ErrorToken "dummy", scanState) = (ErrorToken "dummy", scanState)
= ((head ss_tokenBuffer).lt_token, scanState) = ((head ss_tokenBuffer).lt_token, scanState)
class insertToken state :: !Token !Context !*state -> *state class insertToken state :: !Token !ScanContext !*state -> *state
instance insertToken RScanState instance insertToken RScanState
where where
...@@ -572,7 +572,7 @@ SkipToEndOfLine input ...@@ -572,7 +572,7 @@ SkipToEndOfLine input
| c==NewLineChar = input | c==NewLineChar = input
= SkipToEndOfLine input = SkipToEndOfLine input
Scan :: !Char !Input !Context -> (!Token, !Input) Scan :: !Char !Input !ScanContext -> (!Token, !Input)
Scan '(' input co = (OpenToken, input) Scan '(' input co = (OpenToken, input)
Scan ')' input co = (CloseToken, input) Scan ')' input co = (CloseToken, input)
Scan '{' input CodeContext = ScanCodeBlock input Scan '{' input CodeContext = ScanCodeBlock input
...@@ -720,14 +720,20 @@ Scan c0=:'=' input co ...@@ -720,14 +720,20 @@ Scan c0=:'=' input co
Scan c0=:':' input co Scan c0=:':' input co
# (eof,c1, input) = ReadNormalChar input # (eof,c1, input) = ReadNormalChar input
| eof = (ColonToken, input) | eof = (ColonToken, input)
| c1 == ':' = (DoubleColonToken, input) | c1 == ':'
| c1 <> '=' # (eof, c2, input) = ReadNormalChar input
| isSpecialChar c1 = ScanOperator 1 input [c1, c0] co | eof = (DoubleColonToken, input)
= (ColonToken, charBack input) | isSpecialChar c2 && ~(c2=='!' || c2=='*') // for type rules and the like
# (eof, c2, input) = ReadNormalChar input = ScanOperator 2 input [c2, c1, c0] co
| eof = ScanOperator 1 input [c1, c0] co = (DoubleColonToken, charBack input)
| c2 == '=' = (ColonDefinesToken, input) | c1 == '='
# (eof, c2, input) = ReadNormalChar input
| eof = ScanOperator 1 input [c1, c0] co
| c2 == '=' = (ColonDefinesToken, input)
= ScanOperator 1 (charBack input) [c1, c0] co = ScanOperator 1 (charBack input) [c1, c0] co
// c1 <> '='
| isSpecialChar c1 = ScanOperator 1 input [c1, c0] co
= (ColonToken, charBack input)
Scan c0=:'\'' input co = ScanChar input [c0] Scan c0=:'\'' input co = ScanChar input [c0]
Scan c0=:'\"' input co = ScanString 0 [c0] input Scan c0=:'\"' input co = ScanString 0 [c0] input
...@@ -748,7 +754,7 @@ Scan c input co ...@@ -748,7 +754,7 @@ Scan c input co
| isSpecialChar c = ScanOperator 0 input [c] co | isSpecialChar c = ScanOperator 0 input [c] co
= (ErrorToken ScanErrIllegal, input) = (ErrorToken ScanErrIllegal, input)
possibleKeyToken :: !Token ![Char] !Context !Input -> (!Token, !Input) possibleKeyToken :: !Token ![Char] !ScanContext !Input -> (!Token, !Input)
possibleKeyToken token reversedPrefix context input possibleKeyToken token reversedPrefix context input
# (eof, c, input) = ReadNormalChar input # (eof, c, input) = ReadNormalChar input
| eof = (token, input) | eof = (token, input)
...@@ -762,11 +768,11 @@ new_exp_char '{' = True ...@@ -762,11 +768,11 @@ new_exp_char '{' = True
new_exp_char '/' = True // to handle end of comment symbol: */ new_exp_char '/' = True // to handle end of comment symbol: */
new_exp_char c = isSpace c new_exp_char c = isSpace c
ScanIdentFast :: !Int !Input !Context -> (!Token, !Input) ScanIdentFast :: !Int !Input !ScanContext -> (!Token, !Input)
ScanIdentFast n input=:{inp_stream=OldLine i line stream,inp_pos} co ScanIdentFast n input=:{inp_stream=OldLine i line stream,inp_pos} co
# end_i = ScanIdentCharsInString i line co # end_i = ScanIdentCharsInString i line co
with with
ScanIdentCharsInString :: !Int !{#Char} !Context -> Int ScanIdentCharsInString :: !Int !{#Char} !ScanContext -> Int
ScanIdentCharsInString i line co ScanIdentCharsInString i line co
| i<size line && IsIdentChar line.[i] co | i<size line && IsIdentChar line.[i] co
= ScanIdentCharsInString (i+1) line co = ScanIdentCharsInString (i+1) line co
...@@ -775,14 +781,14 @@ ScanIdentFast n input=:{inp_stream=OldLine i line stream,inp_pos} co ...@@ -775,14 +781,14 @@ ScanIdentFast n input=:{inp_stream=OldLine i line stream,inp_pos} co
# input = {input & inp_stream=OldLine end_i line stream,inp_pos=pos} # input = {input & inp_stream=OldLine end_i line stream,inp_pos=pos}
= CheckReserved co (line % (i-n,end_i-1)) input = CheckReserved co (line % (i-n,end_i-1)) input
ScanOperator :: !Int !Input ![Char] !Context -> (!Token, !Input) ScanOperator :: !Int !Input ![Char] !ScanContext -> (!Token, !Input)
ScanOperator n input token co ScanOperator n input token co
# (eof, c, input) = ReadNormalChar input # (eof, c, input) = ReadNormalChar input
| eof = CheckReserved co (revCharListToString n token) input | eof = CheckReserved co (revCharListToString n token) input
| isSpecialChar c = ScanOperator (n + 1) input [c:token] co | isSpecialChar c = ScanOperator (n + 1) input [c:token] co
= CheckReserved co (revCharListToString n token) (charBack input) = CheckReserved co (revCharListToString n token) (charBack input)
CheckReserved :: !Context !String !Input -> (!Token, !Input) CheckReserved :: !ScanContext !String !Input -> (!Token, !Input)
CheckReserved GeneralContext s i = CheckGeneralContext s i CheckReserved GeneralContext s i = CheckGeneralContext s i
CheckReserved TypeContext s i = CheckTypeContext s i CheckReserved TypeContext s i = CheckTypeContext s i
CheckReserved FunctionContext s i = CheckFunctContext s i CheckReserved FunctionContext s i = CheckFunctContext s i
...@@ -1144,7 +1150,7 @@ hexDigitToInt 'f' = 15 ...@@ -1144,7 +1150,7 @@ hexDigitToInt 'f' = 15
hexDigitToInt 'F' = 15 hexDigitToInt 'F' = 15
hexDigitToInt c = digitToInt c hexDigitToInt c = digitToInt c
IsIdentChar :: !Char !Context -> Bool IsIdentChar :: !Char !ScanContext -> Bool
IsIdentChar c _ | isAlphanum c = True IsIdentChar c _ | isAlphanum c = True
IsIdentChar '_' _ = True IsIdentChar '_' _ = True
IsIdentChar '`' _ = True IsIdentChar '`' _ = True
......
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