forward slash handling and literal handling are all that's left
This commit is contained in:
parent
8bc5c481c1
commit
3c2871217e
1 changed files with 113 additions and 1 deletions
|
|
@ -37,11 +37,123 @@ toTokens = parse tokens
|
||||||
|
|
||||||
displayToken :: (ToText s) => Token s -> s
|
displayToken :: (ToText s) => Token s -> s
|
||||||
displayToken WhiteSpace = fromText " "
|
displayToken WhiteSpace = fromText " "
|
||||||
|
displayToken LineTerminator = fromText "\n"
|
||||||
displayToken (Identifier i) = i
|
displayToken (Identifier i) = i
|
||||||
displayToken (HashBangComment text) = fromText ("#!" <> toText text)
|
displayToken (HashBangComment text) = fromText ("#!" <> toText text)
|
||||||
displayToken (SingleLineComment text) = fromText ("//" <> toText text)
|
displayToken (SingleLineComment text) = fromText ("//" <> toText text)
|
||||||
displayToken (MultiLineComment text) = fromText ("/*" <> toText text <> "*/")
|
displayToken (MultiLineComment text) = fromText ("/*" <> toText text <> "*/")
|
||||||
displayToken _ = error "TODO"
|
displayToken (PrivateIdentifier i) = fromText ("#" <> toText i)
|
||||||
|
displayToken (ReservedWord r) = displayReserved r
|
||||||
|
displayToken (Literal l) = displayLiteral l
|
||||||
|
displayToken (Punc p) = displayPunc p
|
||||||
|
|
||||||
|
displayReserved :: (ToText s) => Reserved -> s
|
||||||
|
displayReserved Await = fromText "await"
|
||||||
|
displayReserved Break = fromText "break"
|
||||||
|
displayReserved Case = fromText "case"
|
||||||
|
displayReserved Catch = fromText "catch"
|
||||||
|
displayReserved Class = fromText "class"
|
||||||
|
displayReserved Const = fromText "const"
|
||||||
|
displayReserved Continue = fromText "continue"
|
||||||
|
displayReserved Debugger = fromText "debugger"
|
||||||
|
displayReserved Default = fromText "default"
|
||||||
|
displayReserved Delete = fromText "delete"
|
||||||
|
displayReserved Do = fromText "do"
|
||||||
|
displayReserved Else = fromText "else"
|
||||||
|
displayReserved Enum = fromText "enum"
|
||||||
|
displayReserved Export = fromText "export"
|
||||||
|
displayReserved Extends = fromText "extends"
|
||||||
|
displayReserved FalseVal = fromText "false"
|
||||||
|
displayReserved Finally = fromText "finally"
|
||||||
|
displayReserved For = fromText "for"
|
||||||
|
displayReserved Function = fromText "function"
|
||||||
|
displayReserved If = fromText "if"
|
||||||
|
displayReserved Import = fromText "import"
|
||||||
|
displayReserved In = fromText "in"
|
||||||
|
displayReserved Instanceof = fromText "instanceof"
|
||||||
|
displayReserved New = fromText "new"
|
||||||
|
displayReserved Null = fromText "null"
|
||||||
|
displayReserved Return = fromText "return"
|
||||||
|
displayReserved Super = fromText "super"
|
||||||
|
displayReserved Switch = fromText "switch"
|
||||||
|
displayReserved This = fromText "this"
|
||||||
|
displayReserved Throw = fromText "throw"
|
||||||
|
displayReserved TrueVal = fromText "true"
|
||||||
|
displayReserved Try = fromText "try"
|
||||||
|
displayReserved Typeof = fromText "typeof"
|
||||||
|
displayReserved Var = fromText "var"
|
||||||
|
displayReserved Void = fromText "void"
|
||||||
|
displayReserved While = fromText "while"
|
||||||
|
displayReserved With = fromText "with"
|
||||||
|
displayReserved Yield = fromText "yield"
|
||||||
|
|
||||||
|
displayLiteral :: (ToText s) => Literal s -> s
|
||||||
|
displayLiteral (Number num) = num
|
||||||
|
displayLiteral (String s) = fromText $ "\"" <> toText s <> "\""
|
||||||
|
displayLiteral (Regex s) = fromText $ "/" <> toText s <> "/"
|
||||||
|
displayLiteral (TemplateFragment frag) = displayTemplateFrag frag
|
||||||
|
|
||||||
|
displayTemplateFrag :: (ToText s) => TemplateFragment s -> s
|
||||||
|
displayTemplateFrag (NoSub s) = fromText $ "`" <> toText s <> "`"
|
||||||
|
displayTemplateFrag (TemplateHead s) = fromText $ "`" <> toText s <> "${"
|
||||||
|
displayTemplateFrag (TemplateMiddle s) = fromText $ "}" <> toText s <> "${"
|
||||||
|
displayTemplateFrag (TemplateTail s) = fromText $ "}" <> toText s <> "`"
|
||||||
|
|
||||||
|
displayPunc :: (ToText s) => Punctuator -> s
|
||||||
|
displayPunc Add = fromText "+"
|
||||||
|
displayPunc Sub = fromText "-"
|
||||||
|
displayPunc Mult = fromText "*"
|
||||||
|
displayPunc Div = fromText "/"
|
||||||
|
displayPunc Mod = fromText "%"
|
||||||
|
displayPunc Exp = fromText "**"
|
||||||
|
displayPunc Inc = fromText "++"
|
||||||
|
displayPunc Dec = fromText "--"
|
||||||
|
displayPunc Utilities.Javascript.LT = fromText "<"
|
||||||
|
displayPunc Utilities.Javascript.GT = fromText ">"
|
||||||
|
displayPunc LTEQ = fromText "<="
|
||||||
|
displayPunc GTEQ = fromText ">="
|
||||||
|
displayPunc DoubleEqual = fromText "=="
|
||||||
|
displayPunc NotEqual = fromText "!="
|
||||||
|
displayPunc TripleEqual = fromText "==="
|
||||||
|
displayPunc DoubleNotEqual = fromText "!=="
|
||||||
|
displayPunc LeftShift = fromText "<<"
|
||||||
|
displayPunc RightShift = fromText ">>"
|
||||||
|
displayPunc UnsignedRightShift = fromText ">>>"
|
||||||
|
displayPunc BitwiseAnd = fromText "&"
|
||||||
|
displayPunc BitwiseOr = fromText "|"
|
||||||
|
displayPunc BitwiseXor = fromText "^"
|
||||||
|
displayPunc BitwiseNot = fromText "~"
|
||||||
|
displayPunc LogicalAnd = fromText "&&"
|
||||||
|
displayPunc LogicalOr = fromText "||"
|
||||||
|
displayPunc LogicalNot = fromText "!"
|
||||||
|
displayPunc Nullish = fromText "??"
|
||||||
|
displayPunc Assign = fromText "="
|
||||||
|
displayPunc AddAssign = fromText "+="
|
||||||
|
displayPunc SubAssign = fromText "-="
|
||||||
|
displayPunc MultAssign = fromText "*="
|
||||||
|
displayPunc DivAssign = fromText "/="
|
||||||
|
displayPunc ModAssign = fromText "%="
|
||||||
|
displayPunc ExpAssign = fromText "**="
|
||||||
|
displayPunc LeftShiftAssign = fromText "<<="
|
||||||
|
displayPunc RightShiftAssign = fromText ">>="
|
||||||
|
displayPunc UnsignedRightShiftAssign = fromText ">>>="
|
||||||
|
displayPunc BitwiseAndAssign = fromText "&="
|
||||||
|
displayPunc BitwiseOrAssign = fromText "|="
|
||||||
|
displayPunc BitwiseXorAssign = fromText "^="
|
||||||
|
displayPunc LogicalAndAssign = fromText "&&="
|
||||||
|
displayPunc LogicalOrAssign = fromText "||="
|
||||||
|
displayPunc NullishAssign = fromText "??="
|
||||||
|
displayPunc LParen = fromText "("
|
||||||
|
displayPunc RParen = fromText ")"
|
||||||
|
displayPunc LCurly = fromText "{"
|
||||||
|
displayPunc RCurly = fromText "}"
|
||||||
|
displayPunc LSquare = fromText "["
|
||||||
|
displayPunc RSquare = fromText "]"
|
||||||
|
displayPunc Dot = fromText "."
|
||||||
|
displayPunc Spread = fromText "..."
|
||||||
|
displayPunc Semicolon = fromText ";"
|
||||||
|
displayPunc Comma = fromText ","
|
||||||
|
displayPunc OptionalChain = fromText "?."
|
||||||
|
|
||||||
-- yeah I guess I'm making a javascript tokenizer
|
-- yeah I guess I'm making a javascript tokenizer
|
||||||
-- s is either Text or String
|
-- s is either Text or String
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue