diff options
author | Camil Staps | 2017-07-30 08:55:51 +0200 |
---|---|---|
committer | Camil Staps | 2017-07-30 08:55:51 +0200 |
commit | e3caf546e7271cea3bedb8fc00d8380bd54746e0 (patch) | |
tree | fb706a49d79c61d0a0b5bc25b479128aa2951fc4 /Sil/Parse.icl | |
parent | Start with positional errors (see #5) (diff) |
Make ParseState unique to reduce heap use
Diffstat (limited to 'Sil/Parse.icl')
-rw-r--r-- | Sil/Parse.icl | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/Sil/Parse.icl b/Sil/Parse.icl index be8079e..80bca2b 100644 --- a/Sil/Parse.icl +++ b/Sil/Parse.icl @@ -43,12 +43,14 @@ where toString (TField f) = "." +++ f toString TAssign = ":=" toString TTilde = "~" + toString TExclamation = "!" toString TPlus = "+" toString TMinus = "-" toString TStar = "*" toString TSlash = "/" toString TPercent = "%" toString TEquals = "==" + toString TUnequals = "<>" toString TLe = "<=" toString TGe = ">=" toString TLt = "<" @@ -57,13 +59,16 @@ where toString TDoubleAmpersand = "&&" toString (TLit l) = toString l toString TIf = "if" + toString TElse = "else" toString TWhile = "while" toString TReturn = "return" toString (TMachineCode s) = "|~ " +++ s toString (TName s) = s + toString t = "???" instance name Token where + name (TField _) = "field" name (TLit _) = "literal" name (TName _) = "name" name (TMachineCode _) = "machine code" @@ -145,12 +150,9 @@ function = type >>= \t -> getPositioner >>= \pos -> name >>= \n -> - item TParenOpen *> - seplist TComma arg >>= \args -> - item TParenClose *> - item TBraceOpen *> - codeblock >>= \cb -> - item TBraceClose $> pos + parenthised (seplist TComma arg) >>= \args -> + braced codeblock >>= \cb -> + pure $ pos { f_type = t , f_name = n , f_args = args @@ -163,8 +165,7 @@ codeblock = many initialisation >>= \is -> pure {cb_init=flatten is, cb_content=s} initialisation :: Parser Token [Positioned Initialisation] -initialisation = - type >>= \t -> seplist TComma (init t) <* item TSemicolon +initialisation = type >>= \t -> seplist TComma (init t) <* item TSemicolon where init t = getPositioner >>= \pos -> |