Skip to content

Commit

Permalink
Close issue #5 by correcting the lexical analyser for DecimalLiteral.…
Browse files Browse the repository at this point in the history
… Version 0.4.8
  • Loading branch information
alanz committed Feb 14, 2012
1 parent e28d42e commit 8296513
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README
Expand Up @@ -35,6 +35,9 @@ dependency in the cabal file.

Changes

0.4.8 Close issue https://github.com/alanz/language-javascript/issues/5 by
correcting the lexical analyser for DecimalLiteral

0.4.7 Continue ECMASCRIPT update, remove incorrect future reserved words for
"code", "mode", "of", "one", "or" and "strict", put in by accident/stupidity.

Expand Down
2 changes: 1 addition & 1 deletion language-javascript.cabal
@@ -1,5 +1,5 @@
Name: language-javascript
Version: 0.4.7
Version: 0.4.8
Synopsis: Parser for JavaScript
Description: Parses Javascript into an Abstract Syntax Tree (AST). Initially intended as frontend to hjsmin.
Homepage: https://github.com/alanz/language-javascript
Expand Down
10 changes: 9 additions & 1 deletion runtests.hs
Expand Up @@ -42,6 +42,9 @@ testSuite = testGroup "Parser"
, testCase "LiteralDecimal10" (testLiteral "0.7e-18" "Right (JSDecimal \"0.7e-18\")")
, testCase "LiteralDecimal11" (testLiteral "1.0e+4" "Right (JSDecimal \"1.0e+4\")")
, testCase "LiteralDecimal12" (testLiteral "1.0e-4" "Right (JSDecimal \"1.0e-4\")")
, testCase "LiteralDecimal13" (testLiteral "1e18" "Right (JSDecimal \"1e18\")")
, testCase "LiteralDecimal14" (testLiteral "1e+18" "Right (JSDecimal \"1e+18\")")
, testCase "LiteralDecimal15" (testLiteral "1e-18" "Right (JSDecimal \"1e-18\")")

, testCase "LiteralString1" (testLiteral "\"hello\\nworld\"" "Right (JSStringLiteral '\"' \"hello\\\\nworld\")")
, testCase "LiteralString2" (testLiteral "'hello\\nworld'" "Right (JSStringLiteral '\\'' \"hello\\\\nworld\")")
Expand Down Expand Up @@ -305,7 +308,12 @@ testSuite = testGroup "Parser"
, testCase "issue4bug2" (testProg "var k = {\ny: mode\n}" "Right (JSSourceElementsTop [JSVariables \"var\" [JSVarDecl (JSIdentifier \"k\") [JSObjectLiteral [JSPropertyNameandValue (JSIdentifier \"y\") [JSIdentifier \"mode\"]]]]])")

-- https://github.com/alanz/language-javascript/issues/5
, testCase "issue5bug1" (testProg "x = { y: 1e8 }" "")
, testCase "issue5bug1" (testProg "x = { y: 1e8 }" "Right (JSSourceElementsTop [JSExpression [JSIdentifier \"x\",JSOperator \"=\",JSObjectLiteral [JSPropertyNameandValue (JSIdentifier \"y\") [JSDecimal \"1e8\"]]]])")
, testCase "issue5ok2" (testProg "{ y: 1e8 }" "Right (JSSourceElementsTop [JSStatementBlock (JSStatementList [JSLabelled (JSIdentifier \"y\") (JSExpression [JSDecimal \"1e8\"])])])")
, testCase "issue5ok3" (testProg "{ y: 18 }" "Right (JSSourceElementsTop [JSStatementBlock (JSStatementList [JSLabelled (JSIdentifier \"y\") (JSExpression [JSDecimal \"18\"])])])")
, testCase "issue5ok4" (testProg "x = { y: 18 }" "Right (JSSourceElementsTop [JSExpression [JSIdentifier \"x\",JSOperator \"=\",JSObjectLiteral [JSPropertyNameandValue (JSIdentifier \"y\") [JSDecimal \"18\"]]]])")


]

srcHelloWorld = "Hello"
Expand Down
23 changes: 18 additions & 5 deletions src/Language/JavaScript/Parser/Lexer.x
Expand Up @@ -225,12 +225,25 @@ tokens :-
-- | {Non Zero Digits}+ {Digit}*
-- | '0'
-- | '0' '.' {Digit}+
<reg,divide> $non_zero_digit $digit* "." $digit* ("e"|"E") ("+"|"-")? $non_zero_digit+ $digit*

-- <reg,divide> $non_zero_digit $digit* "." $digit* ("e"|"E") ("+"|"-")? $non_zero_digit+ $digit*
-- | $non_zero_digit $digit* "." $digit*
-- | "0." $digit+ ("e"|"E") ("+"|"-")? $non_zero_digit+ $digit*
-- | $non_zero_digit+ $digit*
-- | "0"
-- | "0." $digit+ { mkString decimalToken }

<reg,divide> "0" "." $digit* ("e"|"E") ("+"|"-")? $non_zero_digit+ $digit*
| $non_zero_digit $digit* "." $digit* ("e"|"E") ("+"|"-")? $non_zero_digit+ $digit*
| "." $digit+ ("e"|"E") ("+"|"-")? $non_zero_digit+ $digit*
| "0" ("e"|"E") ("+"|"-")? $non_zero_digit+ $digit*
| $non_zero_digit $digit* ("e"|"E") ("+"|"-")? $non_zero_digit+ $digit*

| "0" "." $digit*
| $non_zero_digit $digit* "." $digit*
| "0." $digit+ ("e"|"E") ("+"|"-")? $non_zero_digit+ $digit*
| $non_zero_digit+ $digit*
| "0"
| "0." $digit+ { mkString decimalToken }
| "." $digit+
| "0"
| $non_zero_digit $digit* { mkString decimalToken }


-- beginning of file
Expand Down

0 comments on commit 8296513

Please sign in to comment.