Here is some of the code which is causing some very strange errors depending on what is parsed after the token emptyList in the target file.
data Express = Seq [Express]
| ID String
| Num Integer
| BoolConst Bool
| EmptyList String
emptyList :: Parser Express
emptyList = fmap EmptyList (string "[]")
The issue is:
When the string "[]" is followed by anything (including whitespace) other than a digit or the end of the file it causes the following error
(line 1, column 6):
unexpected end of input OR unexpected "d"
expecting digit
*** Exception: user error (parse error)
However when parsed with a digit following the [] it reports no error.
e.g. "[] " error
"[] a" error
"[] 1" successful
Also should the Num Integer be removed from the data definition and elsewhere in the file
number :: Parser Express
number = fmap Num integer
The file will parse fine without anything after the "[]" however parsing will return only up until the first occurrence of "[]" and nothing after it
Thanks in advance.
The issue was coming from the way that the expressions were being delimited, whiteSpace was not being accounted for correctly when dealing with multiple expressions. initially:
seqOfExpr8 =
do list <- (sepBy1 expr8 (string "" ) )
return $ if length list == 1 then head list else Seq list
fixed:
seqOfExpr8 =
do list <- (sepBy1 expr8 whiteSpace )
return $ if length list == 1 then head list else Seq list
where whiteSpace is a lexeme parser from genTokenParser Type.