Skip to content

Instantly share code, notes, and snippets.

@heath
Created January 21, 2013 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heath/4583287 to your computer and use it in GitHub Desktop.
Save heath/4583287 to your computer and use it in GitHub Desktop.
static JSBool
MatchOrInsertSemicolon(JSContext *cx, TokenStream *ts)
{
TokenKind tt = ts->peekTokenSameLine(TSF_OPERAND);
if (tt == TOK_ERROR)
return JS_FALSE;
if (tt != TOK_EOF && tt != TOK_EOL && tt != TOK_SEMI && tt != TOK_RC) {
/* Advance the scanner for proper error location reporting. */
ts->getToken(TSF_OPERAND);
ReportCompileErrorNumber(cx, ts, NULL, JSREPORT_ERROR, JSMSG_SEMI_BEFORE_STMNT);
return JS_FALSE;
}
(void) ts->matchToken(TOK_SEMI);
return JS_TRUE;
}
void Parser::ExpectSemicolon(bool* ok) {
// Check for automatic semicolon insertion according to
// the rules given in ECMA-262, section 7.9, page 21.
Token::Value tok = peek();
if (tok == Token::SEMICOLON) {
Next();
return;
}
if (scanner().HasAnyLineTerminatorBeforeNext() ||
tok == Token::RBRACE ||
tok == Token::EOS) {
return;
}
Expect(Token::SEMICOLON, ok);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment