Skip to content

Commit cf3e328

Browse files
committed
Parser: Cleanup (hlint and whitespace)
1 parent 314c33c commit cf3e328

File tree

3 files changed

+57
-81
lines changed

3 files changed

+57
-81
lines changed

src/Language/JavaScript/Parser/Grammar5.y

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ SimpleAssign :: { AST.JSNode }
262262
SimpleAssign : '=' { fp (AST.NT (AST.JSLiteral "=") (ss $1) (gc $1))}
263263

264264
Assign :: { AST.JSNode }
265-
Assign : 'assign' { fp (AST.NT (AST.JSLiteral (token_literal $1)) (ss $1) (gc $1))}
265+
Assign : 'assign' { fp (AST.NT (AST.JSLiteral (tokenLiteral $1)) (ss $1) (gc $1))}
266266

267267
Var :: { AST.JSNode }
268268
Var : 'var' { fp (AST.NT (AST.JSLiteral "var") (ss $1) (gc $1))}
@@ -347,16 +347,16 @@ BooleanLiteral : 'true' { fp (AST.NT (AST.JSLiteral "true") (ss $1) (gc $1)) }
347347
-- | HexIntegerLiteral
348348
-- | OctalLiteral
349349
NumericLiteral :: { AST.JSNode }
350-
NumericLiteral : 'decimal' { fp (AST.NT (AST.JSDecimal (token_literal $1)) (ss $1) (gc $1))}
351-
| 'hexinteger' { fp (AST.NT (AST.JSHexInteger (token_literal $1)) (ss $1) (gc $1)) }
352-
| 'octal' { fp (AST.NT (AST.JSOctal (token_literal $1)) (ss $1) (gc $1)) }
350+
NumericLiteral : 'decimal' { fp (AST.NT (AST.JSDecimal (tokenLiteral $1)) (ss $1) (gc $1))}
351+
| 'hexinteger' { fp (AST.NT (AST.JSHexInteger (tokenLiteral $1)) (ss $1) (gc $1)) }
352+
| 'octal' { fp (AST.NT (AST.JSOctal (tokenLiteral $1)) (ss $1) (gc $1)) }
353353

354354
StringLiteral :: { AST.JSNode }
355-
StringLiteral : 'string' { fp (AST.NT (AST.JSStringLiteral (token_delimiter $1) (token_literal $1)) (ss $1) (gc $1)) }
355+
StringLiteral : 'string' { fp (AST.NT (AST.JSStringLiteral (token_delimiter $1) (tokenLiteral $1)) (ss $1) (gc $1)) }
356356

357357
-- <Regular Expression Literal> ::= RegExp
358358
RegularExpressionLiteral :: { AST.JSNode }
359-
RegularExpressionLiteral : 'regex' { fp (AST.NT (AST.JSRegEx (token_literal $1)) (ss $1) (gc $1)) }
359+
RegularExpressionLiteral : 'regex' { fp (AST.NT (AST.JSRegEx (tokenLiteral $1)) (ss $1) (gc $1)) }
360360

361361
-- PrimaryExpression : See 11.1
362362
-- this
@@ -379,7 +379,7 @@ PrimaryExpression : 'this' { fp (AST.NT (AST.JSLiteral "this")
379379
-- IdentifierStart
380380
-- IdentifierName IdentifierPart
381381
Identifier :: { AST.JSNode }
382-
Identifier : 'ident' { (AST.NT (AST.JSIdentifier (token_literal $1)) (ss $1) (gc $1))}
382+
Identifier : 'ident' { (AST.NT (AST.JSIdentifier (tokenLiteral $1)) (ss $1) (gc $1))}
383383
| 'get' { (AST.NT (AST.JSIdentifier "get") (ss $1) (gc $1))}
384384
| 'set' { (AST.NT (AST.JSIdentifier "set") (ss $1) (gc $1))}
385385

@@ -419,7 +419,7 @@ IdentifierName : Identifier {$1}
419419
| 'void' { fp (AST.NT (AST.JSIdentifier "void") (ss $1) (gc $1))}
420420
| 'while' { fp (AST.NT (AST.JSIdentifier "while") (ss $1) (gc $1))}
421421
| 'with' { fp (AST.NT (AST.JSIdentifier "with") (ss $1) (gc $1))}
422-
| 'future' { fp (AST.NT (AST.JSIdentifier (token_literal $1)) (ss $1) (gc $1))}
422+
| 'future' { fp (AST.NT (AST.JSIdentifier (tokenLiteral $1)) (ss $1) (gc $1))}
423423

424424

425425

@@ -1140,48 +1140,24 @@ combineTop (AST.NN (AST.JSSourceElementsTop xs)) x1 = fp (AST.NN (AST.JSSourceEl
11401140

11411141

11421142
parseError :: Token -> Alex a
1143-
-- parseError = throwError . UnexpectedToken
11441143
parseError tok = alexError (show tok)
11451144

11461145
-- --------------------------------
11471146

1148-
{-
1149-
mex :: [AST.JSNode] -> TokenPosn
1150-
mex [] = tokenPosnEmpty
1151-
mex xs = ex (head xs)
1152-
1153-
ex :: AST.JSNode -> TokenPosn
1154-
ex (AST.NN _node span _c) = span
1155-
-}
1156-
1157-
--ss token = toSrcSpan (token_span token)
11581147
ss :: Token -> TokenPosn
1159-
ss token = token_span token
1148+
ss = tokenSpan
11601149

11611150
-- ------------------------------
11621151

11631152
gc :: Token -> [CommentAnnotation]
1164-
gc token = token_comment token
1153+
gc = tokenComment
11651154
mgc :: [Token] -> [CommentAnnotation]
1166-
mgc xs = concatMap gc xs
1155+
mgc xs = concatMap tokenComment xs
11671156

11681157
-- ---------------------------------------------------------------------
11691158

11701159
fp :: AST.JSNode -> AST.JSNode
11711160
fp (AST.NN x) = (AST.NN x)
11721161
fp (AST.NT x p cs) = (AST.NT x p cs)
1173-
{-
1174-
fp (AST.NN x p cs) = (AST.NN x p' cs)
1175-
where
1176-
p' = case (filter (/= NoComment) cs) of
1177-
[] -> p
1178-
[(CommentA posn _)] -> posn
1179-
((CommentA posn _):_) -> posn
1180-
-}
11811162

11821163
}
1183-
1184-
-- Set emacs mode
1185-
-- Local Variables:
1186-
-- mode:haskell
1187-
-- End:

src/Language/JavaScript/Parser/Lexer.x

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ lexCont cont = do
388388
lexLoop
389389
_other -> do
390390
cs <- getComment
391-
let tok' = tok{ token_comment=(toCommentAnnotation cs) }
391+
let tok' = tok{ tokenComment=(toCommentAnnotation cs) }
392392
setComment []
393393
cont tok'
394394

@@ -398,8 +398,8 @@ toCommentAnnotation [] = [NoComment]
398398
toCommentAnnotation xs =
399399
reverse $ map go xs
400400
where
401-
go tok@(CommentToken {}) = (CommentA (token_span tok) (token_literal tok))
402-
go tok@(WsToken {}) = (WhiteSpace (token_span tok) (token_literal tok))
401+
go tok@(CommentToken {}) = (CommentA (tokenSpan tok) (tokenLiteral tok))
402+
go tok@(WsToken {}) = (WhiteSpace (tokenSpan tok) (tokenLiteral tok))
403403
go _ = error "toCommentAnnotation"
404404

405405
-- ---------------------------------------------------------------------

src/Language/JavaScript/Parser/Token.hs

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -35,62 +35,62 @@ data CommentAnnotation
3535
-- Each may be annotated with any comment occuring between the prior token and this one
3636
data Token
3737
-- Comment
38-
= CommentToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] } -- ^ Single line comment.
39-
| WsToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] } -- ^ White space, for preservation.
38+
= CommentToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] } -- ^ Single line comment.
39+
| WsToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] } -- ^ White space, for preservation.
4040

4141
-- Identifiers
42-
| IdentifierToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] } -- ^ Identifier.
42+
| IdentifierToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] } -- ^ Identifier.
4343

4444
-- Javascript Literals
4545

46-
| DecimalToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
46+
| DecimalToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
4747
-- ^ Literal: Decimal
48-
| HexIntegerToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
48+
| HexIntegerToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
4949
-- ^ Literal: Hexadecimal Integer
50-
| OctalToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
50+
| OctalToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
5151
-- ^ Literal: Octal Integer
52-
| StringToken { tokenSpan :: !TokenPosn, token_literal :: !String, token_delimiter :: !Char, tokenComment :: ![CommentAnnotation] }
52+
| StringToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, token_delimiter :: !Char, tokenComment :: ![CommentAnnotation] }
5353
-- ^ Literal: string, delimited by either single or double quotes
54-
| RegExToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
54+
| RegExToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
5555
-- ^ Literal: Regular Expression
5656

5757
-- Keywords
58-
| BreakToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
59-
| CaseToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
60-
| CatchToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
61-
| ConstToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
62-
| ContinueToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
63-
| DebuggerToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
64-
| DefaultToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
65-
| DeleteToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
66-
| DoToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
67-
| ElseToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
68-
| EnumToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
69-
| FalseToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
70-
| FinallyToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
71-
| ForToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
72-
| FunctionToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
73-
| IfToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
74-
| InToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
75-
| InstanceofToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
76-
| NewToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
77-
| NullToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
78-
| ReturnToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
79-
| SwitchToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
80-
| ThisToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
81-
| ThrowToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
82-
| TrueToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
83-
| TryToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
84-
| TypeofToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
85-
| VarToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
86-
| VoidToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
87-
| WhileToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
88-
| WithToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
58+
| BreakToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
59+
| CaseToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
60+
| CatchToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
61+
| ConstToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
62+
| ContinueToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
63+
| DebuggerToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
64+
| DefaultToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
65+
| DeleteToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
66+
| DoToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
67+
| ElseToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
68+
| EnumToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
69+
| FalseToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
70+
| FinallyToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
71+
| ForToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
72+
| FunctionToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
73+
| IfToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
74+
| InToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
75+
| InstanceofToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
76+
| NewToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
77+
| NullToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
78+
| ReturnToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
79+
| SwitchToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
80+
| ThisToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
81+
| ThrowToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
82+
| TrueToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
83+
| TryToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
84+
| TypeofToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
85+
| VarToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
86+
| VoidToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
87+
| WhileToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
88+
| WithToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
8989
-- Future reserved words
90-
| FutureToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
90+
| FutureToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
9191
-- Needed, not sure what they are though.
92-
| GetToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
93-
| SetToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
92+
| GetToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
93+
| SetToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
9494

9595
-- Delimiters
9696
-- Operators
@@ -105,7 +105,7 @@ data Token
105105
| BitwiseAndToken { tokenSpan :: !TokenPosn, tokenComment :: ![CommentAnnotation] }
106106
| StrictEqToken { tokenSpan :: !TokenPosn, tokenComment :: ![CommentAnnotation] }
107107
| EqToken { tokenSpan :: !TokenPosn, tokenComment :: ![CommentAnnotation] }
108-
| AssignToken { tokenSpan :: !TokenPosn, token_literal :: !String, tokenComment :: ![CommentAnnotation] }
108+
| AssignToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
109109
| SimpleAssignToken { tokenSpan :: !TokenPosn, tokenComment :: ![CommentAnnotation] }
110110
| StrictNeToken { tokenSpan :: !TokenPosn, tokenComment :: ![CommentAnnotation] }
111111
| NeToken { tokenSpan :: !TokenPosn, tokenComment :: ![CommentAnnotation] }

0 commit comments

Comments
 (0)