Skip to content

Commit

Permalink
Fixed greedy multiline comment bug, ready for 0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
alanz committed Dec 23, 2010
1 parent d15dc6d commit 6cb1703
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 9 deletions.
12 changes: 12 additions & 0 deletions ANNOUNCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
I am pleased to announce version 0.0.2 of language-javascript, a parser for ECMAScript.

Changes in language-javascript 0.0.2 vs. 0.0.1:

* Multiline comments were processed in greedy form, now end of
comment recognised properly. Thanks to Tony Morris for reporting this.

Distributions can be obtained from hackage

http://hackage.haskell.org/package/language-javascript

language-javascript is distributed under a BSD-style license.
12 changes: 12 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,16 @@ $ cabal install

This will put a utf8 enabled alex in ~/.cabal/bin

To switch back to the standard version,

$ cabal install --reinstall alex

Changes

0.0.2 Multiline comments were processed in greedy form, now end of
comment recognised properly. Thanks to Tony Morris for reporting this.

0.0.1 Initial release

EOF

3 changes: 2 additions & 1 deletion language-javascript.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: language-javascript
Version: 0.0.1
Version: 0.0.2
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 All @@ -13,6 +13,7 @@ Build-type: Simple
homepage: http://github.com/alanz/language-javascript
bug-reports: http://github.com/alanz//language-javascript/issues
Extra-source-files: README
ANNOUNCE
.ghci
buildall.sh

Expand Down
4 changes: 4 additions & 0 deletions runtests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ testSuite = testGroup "Parser"

, testCase "122_jsexec" (testProg "v = getValue(execute(n[0], x)) in getValue(execute(n[1], x));" "Right (JSSourceElementsTop [JSExpression [JSElement \"assignmentExpression\" [JSIdentifier \"v\",JSOperator \"=\",JSExpressionBinary \" in \" [JSIdentifier \"getValue\",JSArguments [[JSIdentifier \"execute\",JSArguments [[JSMemberSquare [JSIdentifier \"n\"] (JSExpression [JSDecimal \"0\"])],[JSIdentifier \"x\"]]]]] [JSIdentifier \"getValue\",JSArguments [[JSIdentifier \"execute\",JSArguments [[JSMemberSquare [JSIdentifier \"n\"] (JSExpression [JSDecimal \"1\"])],[JSIdentifier \"x\"]]]]]]],JSLiteral \";\"])")


, testCase "bug1" (testProg "/* */\nfunction f() {\n/* */\n}\n" "Right (JSSourceElementsTop [JSFunction (JSIdentifier \"f\") [] (JSFunctionBody [])])")
, testCase "bug1" (testProg "/* **/\nfunction f() {\n/* */\n}\n" "Right (JSSourceElementsTop [JSFunction (JSIdentifier \"f\") [] (JSFunctionBody [])])")

]

srcHelloWorld = "Hello"
Expand Down
2 changes: 1 addition & 1 deletion src/Language/JavaScript/Parser/Grammar.y
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ import qualified Language.JavaScript.Parser.AST as AST
-- Comment End = '*/'
-- Comment Line = '//'

-- ! ------------------------------------------------- Rules

-- ! ------------------------------------------------- Rules



Expand Down
24 changes: 23 additions & 1 deletion src/Language/JavaScript/Parser/Lexer.x
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ $RegExpFirstChar = [$printable] # [ $cr $lf \* \\ \/]
-- ~ ( LineTerminator | BSLASH | DIV )
$RegExpChars = [$printable] # [ $cr $lf \\ \/]
$MultiLineNotAsteriskChar = [$any_char] # [\*]
$MultiLineNotForwardSlashOrAsteriskChar = [$any_char] # [\* \/]
-- WhiteSpace ::
-- <TAB>
-- <VT>
Expand All @@ -89,8 +92,27 @@ tokens :-
-- Skip one line comment
<reg,divide> "//"($not_eol_char)* ;
-- ---------------------------------------------------------------------
-- Comment definition from the ECMAScript spec, ver 3
-- MultiLineComment ::
-- /* MultiLineCommentChars(opt) */
-- MultiLineCommentChars ::
-- MultiLineNotAsteriskChar MultiLineCommentChars(opt)
-- * PostAsteriskCommentChars(opt)
-- PostAsteriskCommentChars ::
-- MultiLineNotForwardSlashOrAsteriskChar MultiLineCommentChars(opt)
-- * PostAsteriskCommentChars(opt)
-- MultiLineNotAsteriskChar ::
-- SourceCharacter but not asterisk *
-- MultiLineNotForwardSlashOrAsteriskChar ::
-- SourceCharacter but not forward-slash / or asterisk *
-- Skip multi-line comments. Note: may not nest
<reg,divide> "/*"($any_char)*"*/" ;
-- <reg,divide> "/*"($any_char)*"*/" ;
<reg,divide> "/*" (($MultiLineNotAsteriskChar)*| ("*")+ ($MultiLineNotForwardSlashOrAsteriskChar) )* ("*")+ "/" ;
-- Identifier = {ID Head}{ID Tail}*
Expand Down
12 changes: 6 additions & 6 deletions src/Language/JavaScript/Parser/SrcLocation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ module Language.JavaScript.Parser.SrcLocation (
SrcLocation (..),
SrcSpan (..),
Span (..),
spanning,
-- spanning,
mkSrcSpan,
combineSrcSpans,
-- combineSrcSpans,
initialSrcLocation,
spanStartPoint,
-- * Modification
incColumn,
decColumn,
incLine,
incTab,
endCol,
-- endCol,
-- * Projection of components of a span
endRow,
startCol,
startRow
-- endRow,
-- startCol,
-- startRow
) where

import Data.Data
Expand Down

0 comments on commit 6cb1703

Please sign in to comment.