aboutsummaryrefslogtreecommitdiff
path: root/Sil/Parse.icl
diff options
context:
space:
mode:
Diffstat (limited to 'Sil/Parse.icl')
-rw-r--r--Sil/Parse.icl38
1 files changed, 20 insertions, 18 deletions
diff --git a/Sil/Parse.icl b/Sil/Parse.icl
index 4a345fe..6a3999d 100644
--- a/Sil/Parse.icl
+++ b/Sil/Parse.icl
@@ -175,41 +175,43 @@ where
statement :: Parser Token Statement
statement =
- declaration
- <|> liftM Application (expression <* item TSemicolon)
- <|> return
- <|> if`
- <|> while
- <|> machinecode
+ getPosition >>= \pos ->
+ ( declaration pos
+ <|> liftM (Application pos) (expression <* item TSemicolon)
+ <|> return pos
+ <|> if` pos
+ <|> while pos
+ <|> machinecode pos
+ )
where
- declaration :: Parser Token Statement
- declaration = liftM2 Declaration name (item TAssign *> expression <* item TSemicolon)
+ declaration :: ParsePosition -> Parser Token Statement
+ declaration p = liftM2 (Declaration p) name (item TAssign *> expression <* item TSemicolon)
- return :: Parser Token Statement
- return = liftM Return (item TReturn *> optional expression <* item TSemicolon)
+ return :: ParsePosition -> Parser Token Statement
+ return p = liftM (Return p) (item TReturn *> optional expression <* item TSemicolon)
- machinecode :: Parser Token Statement
- machinecode = (\(TMachineCode s) -> MachineStm s) <$> satisfy isMachineCode
+ machinecode :: ParsePosition -> Parser Token Statement
+ machinecode p = (\(TMachineCode s) -> MachineStm p s) <$> satisfy isMachineCode
where isMachineCode (TMachineCode _) = True; isMachineCode _ = False
- if` :: Parser Token Statement
- if` = item TIf *>
+ if` :: ParsePosition -> Parser Token Statement
+ if` p = item TIf *>
parenthised expression >>= \cond ->
braced codeblock >>= \iftrue ->
many elseif >>= \elseifs ->
optional (item TElse *> braced codeblock) >>= \iffalse ->
- pure $ If [(cond,iftrue):elseifs] iffalse
+ pure $ If p [(cond,iftrue):elseifs] iffalse
where
elseif = list [TElse, TIf] *>
parenthised expression >>= \cond ->
braced codeblock >>= \block ->
pure (cond, block)
- while :: Parser Token Statement
- while = item TWhile *>
+ while :: ParsePosition -> Parser Token Statement
+ while p = item TWhile *>
parenthised expression >>= \cond ->
braced codeblock >>= \do ->
- pure $ While cond do
+ pure $ While p cond do
expression :: Parser Token Expression
expression