Commit 856135ab authored by John van Groningen's avatar John van Groningen
Browse files

refactor, in scanner add function insertBeforeStoredToken and use it instead...

refactor, in scanner add function insertBeforeStoredToken and use it instead of tokenBack and store in ss_tokenBuffer
parent ffcb2215
...@@ -400,6 +400,17 @@ where currentToken scanState=:{ss_tokenBuffer} ...@@ -400,6 +400,17 @@ where currentToken scanState=:{ss_tokenBuffer}
# (ltok,ss_tokenBuffer) = head ss_tokenBuffer # (ltok,ss_tokenBuffer) = head ss_tokenBuffer
= (ltok.lt_token, {scanState & ss_tokenBuffer=ss_tokenBuffer}) = (ltok.lt_token, {scanState & ss_tokenBuffer=ss_tokenBuffer})
insertBeforeStoredToken :: !LongToken !RScanState -> RScanState
insertBeforeStoredToken l_token scanState=:{ss_tokenBuffer=Buffer1 x,ss_input}
# ss_tokenBuffer = Buffer1 l_token
= {scanState & ss_tokenBuffer = ss_tokenBuffer, ss_input = PushedToken x ss_input}
insertBeforeStoredToken l_token scanState=:{ss_tokenBuffer=Buffer2 x y,ss_input}
# ss_tokenBuffer = Buffer2 l_token y
= {scanState & ss_tokenBuffer = ss_tokenBuffer, ss_input = PushedToken x ss_input}
insertBeforeStoredToken l_token scanState=:{ss_tokenBuffer=Buffer3 x y z,ss_input}
# ss_tokenBuffer = Buffer3 l_token y z
= {scanState & ss_tokenBuffer = ss_tokenBuffer, ss_input = PushedToken x ss_input}
notContextDependent :: !Token -> Bool notContextDependent :: !Token -> Bool
notContextDependent token notContextDependent token
= case token of = case token of
...@@ -1862,20 +1873,10 @@ checkOffside pos index token scanState=:{ss_offsides,ss_scanOptions,ss_input} ...@@ -1862,20 +1873,10 @@ checkOffside pos index token scanState=:{ss_offsides,ss_scanOptions,ss_input}
# [(os_col, new_def):_] = ss_offsides # [(os_col, new_def):_] = ss_offsides
col = pos.fp_col col = pos.fp_col
| col == os_col && canBeOffside token | col == os_col && canBeOffside token
# scanState = tokenBack scanState # newToken = NewDefinitionToken
newToken = NewDefinitionToken l_token = {lt_position = pos, lt_index = index, lt_token = newToken, lt_context = FunctionContext}
= ( newToken = (newToken, insertBeforeStoredToken l_token scanState)
, { scanState -->> (token,"NewDefinitionToken generated col==os && canBeOffside",pos,ss_offsides)
& ss_tokenBuffer
= store
{ lt_position = pos
, lt_index = index
, lt_token = newToken
, lt_context = FunctionContext
}
scanState.ss_tokenBuffer
}
) -->> (token,"NewDefinitionToken generated col==os && canBeOffside",pos,ss_offsides)
| token =: InToken | token =: InToken
// = (token, { scanState & ss_offsides = tl ss_offsides }) // = (token, { scanState & ss_offsides = tl ss_offsides })
= (token, scanState) // PK: parser removes offsides = (token, scanState) // PK: parser removes offsides
...@@ -1885,18 +1886,10 @@ checkOffside pos index token scanState=:{ss_offsides,ss_scanOptions,ss_input} ...@@ -1885,18 +1886,10 @@ checkOffside pos index token scanState=:{ss_offsides,ss_scanOptions,ss_input}
scanState = snd (newOffside token scanState) scanState = snd (newOffside token scanState)
scanState = case new_def && col == os_col && canBeOffside token of scanState = case new_def && col == os_col && canBeOffside token of
True True
# scanState = tokenBack scanState # newToken = NewDefinitionToken
newToken = NewDefinitionToken l_token = {lt_position = pos, lt_index = index, lt_token = newToken, lt_context = FunctionContext}
-> { scanState -> insertBeforeStoredToken l_token scanState
& ss_tokenBuffer -->> ("new definition generated",token)
= store
{ lt_position = pos
, lt_index = index
, lt_token = newToken
, lt_context = FunctionContext
}
scanState.ss_tokenBuffer
} -->> ("new definition generated",token)
False False
-> scanState -> scanState
= gen_end_groups n scanState = gen_end_groups n scanState
...@@ -1910,17 +1903,9 @@ checkOffside pos index token scanState=:{ss_offsides,ss_scanOptions,ss_input} ...@@ -1910,17 +1903,9 @@ checkOffside pos index token scanState=:{ss_offsides,ss_scanOptions,ss_input}
gen_end_groups n scanState gen_end_groups n scanState
# newToken = EndGroupToken # newToken = EndGroupToken
scanState = tokenBack scanState // push current token back l_token = {lt_position = pos, lt_index = index, lt_token = newToken, lt_context = FunctionContext}
scanState = { scanState scanState = insertBeforeStoredToken l_token scanState
& ss_tokenBuffer -->> ("end group generated",pos) // insert EndGroupToken
= store
{ lt_position = pos
, lt_index = index
, lt_token = newToken
, lt_context = FunctionContext
}
scanState.ss_tokenBuffer
} -->> ("end group generated",pos) // insert EndGroupToken
| n == 1 | n == 1
// # (new_offsides, scanState) = scanState!ss_offsides // for tracing XXX // # (new_offsides, scanState) = scanState!ss_offsides // for tracing XXX
= (newToken, scanState) // -->> ("new offsides",new_offsides) = (newToken, scanState) // -->> ("new offsides",new_offsides)
...@@ -1935,26 +1920,12 @@ where ...@@ -1935,26 +1920,12 @@ where
scanState = tokenBack scanState scanState = tokenBack scanState
os = os_pos.fp_col os = os_pos.fp_col
| os == 1 | os == 1
# scanState = tokenBack scanState # newToken = ErrorToken "groups should not start in column 1"
newToken = ErrorToken "groups should not start in column 1" l_token = {lt_position = pos, lt_index = index, lt_token = newToken, lt_context = FunctionContext}
= ( newToken = (newToken, insertBeforeStoredToken l_token scanState)
, { scanState
& ss_tokenBuffer
= store
{ lt_position = pos
, lt_index = index
, lt_token = newToken
, lt_context = FunctionContext
}
scanState.ss_tokenBuffer
}
)
// otherwise // os <> 1 // otherwise // os <> 1
= ( token = (token, {scanState & ss_offsides = [(os, needsNewDefinitionToken token) : ss_offsides]})
, { scanState // -->> (token,pos,"New offside defined at ",os_pos,[ (os, token == CaseToken) : ss_offsides ])
& ss_offsides = [ (os, needsNewDefinitionToken token) : ss_offsides ]
}
) // -->> (token,pos,"New offside defined at ",os_pos,[ (os, token == CaseToken) : ss_offsides ])
// otherwise // ~ (definesOffside token) // otherwise // ~ (definesOffside token)
= (token, scanState) -->> (token,pos," not offside") = (token, scanState) -->> (token,pos," not offside")
......
Supports Markdown
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