Rain: fixed the parsing to pass the new literal tests
This commit is contained in:
parent
bb77f3fb91
commit
1d0426ac77
|
@ -42,6 +42,7 @@ $hexDigit = [0-9 a-f A-F]
|
||||||
| "sint8" | "sint16" | "sint32" | "sint64"
|
| "sint8" | "sint16" | "sint32" | "sint64"
|
||||||
| "uint8" | "uint16" | "uint32" | "uint64"
|
| "uint8" | "uint16" | "uint32" | "uint64"
|
||||||
| "int" | "bool"
|
| "int" | "bool"
|
||||||
|
| "true" | "false"
|
||||||
|
|
||||||
|
|
||||||
@identifier = [a-z A-Z _] [a-z A-Z 0-9 _]*
|
@identifier = [a-z A-Z _] [a-z A-Z 0-9 _]*
|
||||||
|
@ -49,7 +50,7 @@ $hexDigit = [0-9 a-f A-F]
|
||||||
$escapeChar = [cnrts \" \' \\ \n]
|
$escapeChar = [cnrts \" \' \\ \n]
|
||||||
@escape = \\ ( $escapeChar | \# $hexDigit $hexDigit )
|
@escape = \\ ( $escapeChar | \# $hexDigit $hexDigit )
|
||||||
|
|
||||||
@stringLiteral = \" ( @escape | [^\"] )* \"
|
@stringLiteral = \" ( @escape | [^\\\"] )* \"
|
||||||
@charLiteral = \' ( @escape | [^\'] ) \'
|
@charLiteral = \' ( @escape | [^\'] ) \'
|
||||||
|
|
||||||
-- Note that occam number literals don't include their signs -- if you say
|
-- Note that occam number literals don't include their signs -- if you say
|
||||||
|
|
11
RainParse.hs
11
RainParse.hs
|
@ -141,12 +141,17 @@ variableId = do {v <- name ; return $ A.Variable (findMeta v) v}
|
||||||
stringLiteral :: RainParser (A.LiteralRepr, A.Dimension)
|
stringLiteral :: RainParser (A.LiteralRepr, A.Dimension)
|
||||||
stringLiteral
|
stringLiteral
|
||||||
= do (m,str) <- getToken testToken
|
= do (m,str) <- getToken testToken
|
||||||
let aes = [A.ArrayElemExpr $ A.Literal m A.Byte $ A.ByteLiteral m [c] | c <- str]
|
let processed = replaceEscapes str
|
||||||
return (A.ArrayLiteral m aes, A.Dimension $ length str)
|
let aes = [A.ArrayElemExpr $ A.Literal m A.Byte $ A.ByteLiteral m [c] | c <- processed]
|
||||||
|
return (A.ArrayLiteral m aes, A.Dimension $ length processed)
|
||||||
<?> "string literal"
|
<?> "string literal"
|
||||||
where
|
where
|
||||||
testToken (L.TokStringLiteral str) = Just str
|
testToken (L.TokStringLiteral str) = Just str
|
||||||
testToken _ = Nothing
|
testToken _ = Nothing
|
||||||
|
replaceEscapes :: String -> String
|
||||||
|
replaceEscapes [] = []
|
||||||
|
replaceEscapes ('\\':(c:cs)) = if c == 'n' then ('\n':replaceEscapes cs) else (c:replaceEscapes cs)
|
||||||
|
replaceEscapes (c:cs) = (c:replaceEscapes cs)
|
||||||
|
|
||||||
literalCharacter :: RainParser A.LiteralRepr
|
literalCharacter :: RainParser A.LiteralRepr
|
||||||
literalCharacter
|
literalCharacter
|
||||||
|
@ -167,6 +172,8 @@ integer
|
||||||
literal :: RainParser A.Expression
|
literal :: RainParser A.Expression
|
||||||
literal = do {(lr, dim) <- stringLiteral ; return $ A.Literal (findMeta lr) (A.Array [dim] A.Byte) lr }
|
literal = do {(lr, dim) <- stringLiteral ; return $ A.Literal (findMeta lr) (A.Array [dim] A.Byte) lr }
|
||||||
<|> do {i <- integer ; return $ A.Literal (findMeta i) A.Int i}
|
<|> do {i <- integer ; return $ A.Literal (findMeta i) A.Int i}
|
||||||
|
<|> do {m <- reserved "true" ; return $ A.True m}
|
||||||
|
<|> do {m <- reserved "false" ; return $ A.False m}
|
||||||
<?> "literal"
|
<?> "literal"
|
||||||
|
|
||||||
expression :: RainParser A.Expression
|
expression :: RainParser A.Expression
|
||||||
|
|
Loading…
Reference in New Issue
Block a user