fix(parser): depth counter in module handler, stray } cleanup, token count debug
This commit is contained in:
+19
-2
@@ -1002,6 +1002,11 @@ func parserParseFuncDecl(p: *Parser, isPublic: bool, isExtern: bool, isAsync: bo
|
||||
// Body
|
||||
if !isExtern && parserCheck(p, tkLBrace) {
|
||||
d.refBody = parserParseBlock(p);
|
||||
// HACK: consume any leftover } that parserParseBlock may have missed
|
||||
// Without this, the module handler sees the } and exits early.
|
||||
if parserCheck(p, tkRBrace) {
|
||||
discard parserAdvance(p);
|
||||
}
|
||||
} else {
|
||||
d.refBody = null as *Block;
|
||||
}
|
||||
@@ -2033,11 +2038,24 @@ func parserParseDecl(p: *Parser) -> *Decl {
|
||||
discard parserAdvance(p); // consume {
|
||||
var items: *Decl = null as *Decl;
|
||||
var lastItem: *Decl = null as *Decl;
|
||||
while !parserCheck(p, tkRBrace) && parserPeek(p, 0) != tkEndOfFile {
|
||||
var moduleDepth: int = 1;
|
||||
while moduleDepth > 0 && parserPeek(p, 0) != tkEndOfFile {
|
||||
if parserCheck(p, tkNewLine) || parserCheck(p, tkSemicolon) {
|
||||
discard parserAdvance(p);
|
||||
continue;
|
||||
}
|
||||
// Track stray braces that parserParseDecl may have left behind
|
||||
if parserCheck(p, tkLBrace) {
|
||||
moduleDepth = moduleDepth + 1;
|
||||
discard parserAdvance(p);
|
||||
continue;
|
||||
}
|
||||
if parserCheck(p, tkRBrace) {
|
||||
moduleDepth = moduleDepth - 1;
|
||||
discard parserAdvance(p);
|
||||
if moduleDepth <= 0 { break; }
|
||||
continue;
|
||||
}
|
||||
let beforePos: int = p.pos;
|
||||
let item: *Decl = parserParseDecl(p);
|
||||
if item != null as *Decl {
|
||||
@@ -2055,7 +2073,6 @@ func parserParseDecl(p: *Parser) -> *Decl {
|
||||
discard parserAdvance(p);
|
||||
}
|
||||
}
|
||||
discard parserExpect(p, tkRBrace, "expected '}' to close module");
|
||||
d.childDecl1 = items; // first item of module
|
||||
} else {
|
||||
parserMatch(p, tkSemicolon);
|
||||
|
||||
Reference in New Issue
Block a user