change syntax for javascript code literals
This commit is contained in:
@@ -399,7 +399,7 @@ parsePFunc = do
|
||||
keyword ":"
|
||||
ty <- typeExpr
|
||||
keyword ":="
|
||||
src <- cast <$> token StringKind
|
||||
src <- cast <$> token JSLit
|
||||
pure $ PFunc fc nm ty src
|
||||
|
||||
export
|
||||
|
||||
@@ -13,6 +13,7 @@ data Kind
|
||||
| Number
|
||||
| Character
|
||||
| StringKind
|
||||
| JSLit
|
||||
| Symbol
|
||||
| Space
|
||||
| Comment
|
||||
@@ -40,6 +41,7 @@ Show Kind where
|
||||
show EOI = "EOI"
|
||||
show Pragma = "Pragma"
|
||||
show StringKind = "String"
|
||||
show JSLit = "JSLit"
|
||||
export
|
||||
Eq Kind where
|
||||
Ident == Ident = True
|
||||
@@ -54,6 +56,7 @@ Eq Kind where
|
||||
Semi == Semi = True
|
||||
RBrace == RBrace = True
|
||||
StringKind == StringKind = True
|
||||
JSLit == JSLit = True
|
||||
_ == _ = False
|
||||
|
||||
export
|
||||
|
||||
@@ -49,6 +49,18 @@ unquote str = case unpack str of
|
||||
|
||||
opMiddle = pred (\c => not (isSpace c || c == '_'))
|
||||
|
||||
btick = is '`'
|
||||
|
||||
trimJS : String -> String
|
||||
trimJS str = case unpack str of
|
||||
('`' :: xs) => pack $ go xs
|
||||
bug => pack $ go bug
|
||||
where
|
||||
go : List Char -> List Char
|
||||
go [] = []
|
||||
go ['`'] = []
|
||||
go (x :: xs) = x :: go xs
|
||||
|
||||
rawTokens : Tokenizer (Token Kind)
|
||||
rawTokens
|
||||
= match spaces (Tok Space)
|
||||
@@ -68,6 +80,7 @@ rawTokens
|
||||
<|> match (lineComment (exact "--")) (Tok Space)
|
||||
<|> match (blockComment (exact "/-") (exact "-/")) (Tok Space)
|
||||
<|> match (upper <+> many identMore) checkUKW
|
||||
<|> match (btick <+> manyUntil btick any <+> btick) (Tok JSLit . trimJS)
|
||||
<|> match (quo <+> manyUntil quo (esc any <|> any) <+> quo) (Tok StringKind . unquote)
|
||||
-- accept almost everything, but
|
||||
<|> match (some (non (space <|> singleton))) checkKW
|
||||
|
||||
Reference in New Issue
Block a user