Update AST location info to match SpiderMonkey

Part of #889
This commit is contained in:
kpdecker
2014-11-26 09:01:03 -06:00
parent 3a9440f954
commit 61dd721ca2
9 changed files with 94 additions and 93 deletions
+24 -24
View File
@@ -9,7 +9,7 @@ root
;
program
: statement* -> new yy.ProgramNode(yy.prepareProgram($1), null, {}, @$)
: statement* -> new yy.ProgramNode(yy.prepareProgram($1), null, {}, yy.locInfo(@$))
;
statement
@@ -18,15 +18,15 @@ statement
| rawBlock -> $1
| partial -> $1
| content -> $1
| COMMENT -> new yy.CommentNode(yy.stripComment($1), yy.stripFlags($1, $1), @$)
| COMMENT -> new yy.CommentNode(yy.stripComment($1), yy.stripFlags($1, $1), yy.locInfo(@$))
;
content
: CONTENT -> new yy.ContentNode($1, @$)
: CONTENT -> new yy.ContentNode($1, yy.locInfo(@$))
;
rawBlock
: openRawBlock content END_RAW_BLOCK -> yy.prepareRawBlock($1, $2, $3, @$)
: openRawBlock content END_RAW_BLOCK -> yy.prepareRawBlock($1, $2, $3, yy.locInfo(@$))
;
openRawBlock
@@ -34,8 +34,8 @@ openRawBlock
;
block
: openBlock program inverseChain? closeBlock -> yy.prepareBlock($1, $2, $3, $4, false, @$)
| openInverse program inverseAndProgram? closeBlock -> yy.prepareBlock($1, $2, $3, $4, true, @$)
: openBlock program inverseChain? closeBlock -> yy.prepareBlock($1, $2, $3, $4, false, yy.locInfo(@$))
| openInverse program inverseAndProgram? closeBlock -> yy.prepareBlock($1, $2, $3, $4, true, yy.locInfo(@$))
;
openBlock
@@ -47,7 +47,7 @@ openInverse
;
openInverseChain
: OPEN_INVERSE_CHAIN sexpr CLOSE -> new yy.MustacheNode($2, null, $1, yy.stripFlags($1, $3), @$)
: OPEN_INVERSE_CHAIN sexpr CLOSE -> new yy.MustacheNode($2, null, $1, yy.stripFlags($1, $3), yy.locInfo(@$))
;
inverseAndProgram
@@ -56,8 +56,8 @@ inverseAndProgram
inverseChain
: openInverseChain program inverseChain? {
var inverse = yy.prepareBlock($1, $2, $3, $3, false, @$),
program = new yy.ProgramNode(yy.prepareProgram([inverse]), null, {}, @$);
var inverse = yy.prepareBlock($1, $2, $3, $3, false, yy.locInfo(@$)),
program = new yy.ProgramNode(yy.prepareProgram([inverse]), null, {}, yy.locInfo(@$));
program.inverse = inverse;
@@ -73,31 +73,31 @@ closeBlock
mustache
// Parsing out the '&' escape token at AST level saves ~500 bytes after min due to the removal of one parser node.
// This also allows for handler unification as all mustache node instances can utilize the same handler
: OPEN sexpr CLOSE -> new yy.MustacheNode($2, null, $1, yy.stripFlags($1, $3), @$)
| OPEN_UNESCAPED sexpr CLOSE_UNESCAPED -> new yy.MustacheNode($2, null, $1, yy.stripFlags($1, $3), @$)
: OPEN sexpr CLOSE -> new yy.MustacheNode($2, null, $1, yy.stripFlags($1, $3), yy.locInfo(@$))
| OPEN_UNESCAPED sexpr CLOSE_UNESCAPED -> new yy.MustacheNode($2, null, $1, yy.stripFlags($1, $3), yy.locInfo(@$))
;
partial
: OPEN_PARTIAL partialName param hash? CLOSE -> new yy.PartialNode($2, $3, $4, yy.stripFlags($1, $5), @$)
| OPEN_PARTIAL partialName hash? CLOSE -> new yy.PartialNode($2, undefined, $3, yy.stripFlags($1, $4), @$)
: OPEN_PARTIAL partialName param hash? CLOSE -> new yy.PartialNode($2, $3, $4, yy.stripFlags($1, $5), yy.locInfo(@$))
| OPEN_PARTIAL partialName hash? CLOSE -> new yy.PartialNode($2, undefined, $3, yy.stripFlags($1, $4), yy.locInfo(@$))
;
sexpr
: path param* hash? -> new yy.SexprNode([$1].concat($2), $3, @$)
| dataName -> new yy.SexprNode([$1], null, @$)
: path param* hash? -> new yy.SexprNode([$1].concat($2), $3, yy.locInfo(@$))
| dataName -> new yy.SexprNode([$1], null, yy.locInfo(@$))
;
param
: path -> $1
| STRING -> new yy.StringNode($1, @$)
| NUMBER -> new yy.NumberNode($1, @$)
| BOOLEAN -> new yy.BooleanNode($1, @$)
| STRING -> new yy.StringNode($1, yy.locInfo(@$))
| NUMBER -> new yy.NumberNode($1, yy.locInfo(@$))
| BOOLEAN -> new yy.BooleanNode($1, yy.locInfo(@$))
| dataName -> $1
| OPEN_SEXPR sexpr CLOSE_SEXPR {$2.isHelper = true; $$ = $2;}
;
hash
: hashSegment+ -> new yy.HashNode($1, @$)
: hashSegment+ -> new yy.HashNode($1, yy.locInfo(@$))
;
hashSegment
@@ -109,17 +109,17 @@ blockParams
;
partialName
: path -> new yy.PartialNameNode($1, @$)
| STRING -> new yy.PartialNameNode(new yy.StringNode($1, @$), @$)
| NUMBER -> new yy.PartialNameNode(new yy.NumberNode($1, @$))
: path -> new yy.PartialNameNode($1, yy.locInfo(@$))
| STRING -> new yy.PartialNameNode(new yy.StringNode($1, yy.locInfo(@$)), yy.locInfo(@$))
| NUMBER -> new yy.PartialNameNode(new yy.NumberNode($1, yy.locInfo(@$)))
;
dataName
: DATA path -> new yy.DataNode($2, @$)
: DATA path -> new yy.DataNode($2, yy.locInfo(@$))
;
path
: pathSegments -> new yy.IdNode($1, @$)
: pathSegments -> new yy.IdNode($1, yy.locInfo(@$))
;
pathSegments