%code {
-typedef cy::parser::token tk;
-
#undef yylex
-_finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) {
- if (driver.mark_ == CYMarkIgnore);
- else if (driver.mark_ == CYMarkScript) {
- driver.mark_ = CYMarkIgnore;
- return cy::parser::token::MarkScript;
- } else if (driver.mark_ == CYMarkModule) {
- driver.mark_ = CYMarkIgnore;
- return cy::parser::token::MarkModule;
- }
- lex:
- if (driver.newline_ == CYDriver::NewLineHere)
- driver.newline_ = CYDriver::NewLineLast;
- else if (driver.newline_ == CYDriver::NewLineLast)
- driver.newline_ = CYDriver::NewLineNone;
+typedef cy::parser::token tk;
+_finline int cylex_(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) {
+ driver.newline_ = false;
+ lex:
YYSTYPE data;
int token(cylex(&data, location, driver.scanner_));
*semantic = data.semantic_;
break;
case tk::NewLine:
- driver.newline_ = CYDriver::NewLineHere;
- if (!driver.next_)
- goto lex;
+ driver.newline_ = true;
+ goto lex;
break;
}
- driver.next_ = false;
return token;
}
+#define yylex_(semantic, location, driver) ({ \
+ int type; \
+ if (driver.hold_ == cy::parser::empty_symbol) \
+ type = yytranslate_(cylex_(semantic, location, driver)); \
+ else { \
+ type = driver.hold_; \
+ driver.hold_ = cy::parser::empty_symbol; \
+ } \
+type; })
+
#define CYLEX() do if (yyla.empty()) { \
YYCDEBUG << "Mapping a token: "; \
- yyla.type = yytranslate_(yylex(&yyla.value, &yyla.location, driver)); \
+ yyla.type = yylex_(&yyla.value, &yyla.location, driver); \
YY_SYMBOL_PRINT("Next token is", yyla); \
} while (false)
yyla.type = yytranslate_(token::to); \
} while (false)
-#define CYLIN(from) do { \
- CYLEX(); \
- if (yyla.type == yytranslate_(token::from) && driver.newline_ == CYDriver::NewLineLast) \
- yyla.type = yytranslate_(token::from ## _); \
-} while (false)
-
#define CYERR(location, message) do { \
error(location, message); \
YYABORT; \
%initial-action {
@$.begin.filename = @$.end.filename = &driver.filename_;
+
+ switch (driver.mark_) {
+ case CYMarkScript:
+ driver.hold_ = yytranslate_(token::MarkScript);
+ break;
+ case CYMarkModule:
+ driver.hold_ = yytranslate_(token::MarkModule);
+ break;
+ }
};
%locations
%token EqualEqual "=="
%token EqualEqualEqual "==="
%token EqualRight "=>"
-%token EqualRight_ "\n=>"
%token Exclamation "!"
%token ExclamationEqual "!="
%token ExclamationEqualEqual "!=="
%token Hyphen "-"
%token HyphenEqual "-="
%token HyphenHyphen "--"
-%token HyphenHyphen_ "\n--"
%token HyphenRight "->"
%token Left "<"
%token LeftEqual "<="
%token Plus "+"
%token PlusEqual "+="
%token PlusPlus "++"
-%token PlusPlus_ "\n++"
%token Right ">"
%token RightEqual ">="
%token RightRight ">>"
%token Question "?"
%token SemiColon ";"
%token NewLine "\n"
+%token __ ""
%token Comment
%token CloseParen ")"
%token OpenBrace "{"
-%token OpenBrace_ "\n{"
-%token OpenBrace__ ";{"
+%token OpenBrace_ ";{"
%token OpenBrace_let "let {"
%token CloseBrace "}"
%token _SEL_ "SEL"
@end
-%token _auto_ "auto"
%token _each_ "each"
%token _of_ "of"
%token _of__ "!of"
@end
%token AutoComplete
-%token YieldStar
+%token YieldStar "yield *"
%token <identifier_> Identifier_
%token <number_> NumericLiteral
%type <statement_> ConciseBody
%type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
%type <statement_> DebuggerStatement
-%type <statement_> Declaration__
%type <statement_> Declaration_
%type <statement_> Declaration
%type <clause_> DefaultClause
%type <typedIdentifier_> TypeSignifier
%type <modifier_> TypeQualifierLeft
%type <typedIdentifier_> TypeQualifierRight
-%type <typedIdentifier_> TypedIdentifier
+%type <typedIdentifier_> TypedIdentifierMaybe
+%type <typedIdentifier_> TypedIdentifierNo
+%type <typedIdentifier_> TypedIdentifierYes
%type <typedParameter_> TypedParameterList_
%type <typedParameter_> TypedParameterList
%type <typedParameter_> TypedParameterListOpt
LexPushYieldOff: { driver.yield_.push(false); };
LexPopYield: { driver.yield_.pop(); };
-LexNewLine
- : { CYMPT(@$); driver.next_ = true; }
+LexNewLineOrOpt
+ : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); if (driver.newline_) { driver.hold_ = yyla.type; yyla.type = yytranslate_(cy::parser::token::NewLine); } }
+ ;
+
+LexNewLineOrNot
+ : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); driver.hold_ = yyla.type; yyla.type = yytranslate_(driver.newline_ ? cy::parser::token::NewLine : cy::parser::token::__); }
;
LexNoStar
;
LexNoBrace
- : { CYMAP(OpenBrace__, OpenBrace); CYMAP(OpenBrace__, OpenBrace_); }
+ : { CYMAP(OpenBrace_, OpenBrace); }
;
LexNoClass
;
/* }}} */
/* Virtual Tokens {{{ */
-BRACE
- : "{"
- | "\n{"
- ;
-
Var_
: "var"
;
| "instanceof" { $$ = CYNew CYWord("instanceof"); }
;
-NewLineOpt
- : "\n"
- |
- ;
-
Word
: IdentifierNoOf[pass] { $$ = $pass; }
- | "auto" { $$ = CYNew CYWord("auto"); }
| "break" { $$ = CYNew CYWord("break"); }
| "case" { $$ = CYNew CYWord("case"); }
| "catch" { $$ = CYNew CYWord("catch"); }
| "while" { $$ = CYNew CYWord("while"); }
| "with" { $$ = CYNew CYWord("with"); }
| "yield" { $$ = CYNew CYIdentifier("yield"); }
-
- | Yield NewLineOpt { $$ = CYNew CYIdentifier("yield"); }
;
@begin ObjectiveC
: { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
;
+NewLineNot
+ : LexNewLineOrNot ""
+ ;
+
+NewLineOpt
+ : LexNewLineOrNot "\n"
+ | NewLineNot
+ ;
+
TerminatorSoft
- : ";"
- | "\n" StrictSemi
+ : LexNewLineOrNot "\n" StrictSemi
+ | NewLineNot LexOf Terminator
;
Terminator
: ";"
- | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && driver.newline_ == CYDriver::NewLineNone) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
+ | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
;
TerminatorOpt
;
BindingIdentifier
- : IdentifierNoOf[pass] { $$ = $pass; }
- | "!of" { $$ = CYNew CYIdentifier("of"); }
- | "yield" { $$ = CYNew CYIdentifier("yield"); }
+ : LexOf IdentifierNoOf[pass] { $$ = $pass; }
+ | LexOf "!of" { $$ = CYNew CYIdentifier("of"); }
+ | LexOf "yield" { $$ = CYNew CYIdentifier("yield"); }
;
BindingIdentifierOpt
: BindingIdentifier[pass] { $$ = $pass; }
- | { $$ = NULL; }
+ | LexOf { $$ = NULL; }
;
LabelIdentifier
| "Infinity" { $$ = CYNew CYIdentifier("Infinity"); }
| "interface" { $$ = CYNew CYIdentifier("interface"); }
| "let" { $$ = CYNew CYIdentifier("let"); }
- | "!let" LexBind { $$ = CYNew CYIdentifier("let"); }
+ | "!let" LexBind LexOf { $$ = CYNew CYIdentifier("let"); }
| "native" { $$ = CYNew CYIdentifier("native"); }
| "package" { $$ = CYNew CYIdentifier("package"); }
| "private" { $$ = CYNew CYIdentifier("private"); }
| "static" { $$ = CYNew CYIdentifier("static"); }
| "volatile" { $$ = CYNew CYIdentifier("volatile"); }
@begin C
- | "extern" { $$ = CYNew CYIdentifier("extern"); }
| "signed" { $$ = CYNew CYIdentifier("signed"); }
- | "typedef" { $$ = CYNew CYIdentifier("typedef"); }
| "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
@end
@begin ObjectiveC
Identifier
: IdentifierNoOf[pass] { $$ = $pass; }
| "of" { $$ = CYNew CYIdentifier("of"); }
+ | "!of" { $$ = CYNew CYIdentifier("of"); }
;
/* }}} */
/* 12.2 Primary Expression {{{ */
CoverParenthesizedExpressionAndArrowParameterList
: "(" Expression[expression] ")" { $$ = CYNew CYParenthetical($expression); }
- | "(" ")" { $$ = NULL; }
- | "(" "..." BindingIdentifier ")" { CYNOT(@$); }
- | "(" Expression "," "..." BindingIdentifier ")" { CYNOT(@$); }
+ | "(" LexOf ")" { $$ = NULL; }
+ | "(" LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
+ | "(" Expression "," LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
;
/* }}} */
/* 12.2.4 Literals {{{ */
ElementList
: AssignmentExpressionOpt[value] "," ElementListOpt[next] { $$ = CYNew CYElementValue($value, $next); }
- | "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
+ | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
| AssignmentExpression[value] { $$ = CYNew CYElementValue($value, NULL); }
;
ElementListOpt
: ElementList[pass] { $$ = $pass; }
- | { $$ = NULL; }
+ | LexOf { $$ = NULL; }
;
/* }}} */
/* 12.2.6 Object Initializer {{{ */
ObjectLiteral
- : BRACE PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); }
+ : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); }
;
PropertyDefinitionList_
/* 12.2.9 Template Literals {{{ */
TemplateLiteral
: NoSubstitutionTemplate[string] { $$ = CYNew CYTemplate($string, NULL); }
- | TemplateHead[string] TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); }
+ | TemplateHead[string] LexPushInOff TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); }
;
TemplateSpans
: Expression[value] TemplateMiddle[string] TemplateSpans[spans] { $$ = CYNew CYSpan($value, $string, $spans); }
- | Expression[value] TemplateTail[string] { $$ = CYNew CYSpan($value, $string, NULL); }
+ | Expression[value] TemplateTail[string] LexPopIn { $$ = CYNew CYSpan($value, $string, NULL); }
;
/* }}} */
ArgumentList
: AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
- | "..." AssignmentExpression { CYNOT(@$); }
+ | LexOf "..." AssignmentExpression { CYNOT(@$); }
;
ArgumentListOpt
: ArgumentList[pass] { $$ = $pass; }
- | { $$ = NULL; }
+ | LexOf { $$ = NULL; }
;
AccessExpression
;
LeftHandSideExpression
- : AccessExpression[pass] LexCrement { $$ = $pass; }
+ : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
| IndirectExpression[pass] { $$ = $pass; }
;
/* }}} */
/* 12.4 Postfix Expressions {{{ */
-LexCrement
- : { CYLIN(PlusPlus); CYLIN(HyphenHyphen); }
- ;
-
PostfixExpression
- : AccessExpression[lhs] LexCrement { $$ = $lhs; }
- | AccessExpression[lhs] LexCrement "++" { $$ = CYNew CYPostIncrement($lhs); }
- | AccessExpression[lhs] LexCrement "--" { $$ = CYNew CYPostDecrement($lhs); }
+ : AccessExpression[lhs] LexNewLineOrOpt { $$ = $lhs; }
+ | AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); }
+ | AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); }
;
/* }}} */
/* 12.5 Unary Operators {{{ */
| "void" UnaryExpression[rhs] { $$ = CYNew CYVoid($rhs); }
| "typeof" UnaryExpression[rhs] { $$ = CYNew CYTypeOf($rhs); }
| "++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); }
- | "\n++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); }
| "--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); }
- | "\n--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); }
| "+" UnaryExpression[rhs] { $$ = CYNew CYAffirm($rhs); }
| "-" UnaryExpression[rhs] { $$ = CYNew CYNegate($rhs); }
| "~" UnaryExpression[rhs] { $$ = CYNew CYBitwiseNot($rhs); }
;
UnaryExpression
- : PostfixExpression[expression] LexOpenBrace { $$ = $expression; }
+ : PostfixExpression[expression] { $$ = $expression; }
+ | PostfixExpression[expression] "\n" { $$ = $expression; }
| UnaryExpression_[pass] { $$ = $pass; }
;
/* }}} */
@begin ObjectiveC
AssignmentExpressionClassic
- : ConditionalExpressionClassic[pass] { $$ = $pass; }
- | LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
+ : LexOf ConditionalExpressionClassic[pass] { $$ = $pass; }
+ | LexOf LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
;
@end
AssignmentExpression
- : ConditionalExpression[pass] { $$ = $pass; }
- | YieldExpression[pass] { $$ = $pass; }
+ : LexOf ConditionalExpression[pass] { $$ = $pass; }
+ | LexOf YieldExpression[pass] { $$ = $pass; }
| ArrowFunction[pass] { $$ = $pass; }
- | LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
+ | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
;
AssignmentExpressionOpt
: AssignmentExpression[pass] { $$ = $pass; }
- | { $$ = NULL; }
+ | LexOf { $$ = NULL; }
;
/* }}} */
/* 12.15 Comma Operator ( , ) {{{ */
ExpressionOpt
: Expression[pass] { $$ = $pass; }
- | { $$ = NULL; }
+ | LexOf { $$ = NULL; }
;
/* }}} */
;
Statement_
- : Statement__[pass] { $$ = $pass; }
+ : LexOf Statement__[pass] { $$ = $pass; }
| ExpressionStatement[pass] { $$ = $pass; }
;
: LexSetStatement LexLet Statement_[pass] { $$ = $pass; }
;
-Declaration__
+Declaration_
: HoistableDeclaration[pass] { $$ = $pass; }
| ClassDeclaration[pass] { $$ = $pass; }
;
-Declaration_
- : LexLet Declaration__[pass] { $$ = $pass; }
- | LexicalDeclaration[pass] { $$ = $pass; }
- ;
-
Declaration
- : LexSetStatement Declaration_[pass] { $$ = $pass; }
+ : LexSetStatement LexLet LexOf Declaration_[pass] { $$ = $pass; }
+ | LexSetStatement LexicalDeclaration[pass] { $$ = $pass; }
;
HoistableDeclaration
;
Block
- : BRACE StatementListOpt[code] "}" { $$ = $code; }
+ : "{" StatementListOpt[code] "}" { $$ = $code; }
;
StatementList
StatementListOpt
: StatementList[pass] { $$ = $pass; }
- | LexSetStatement LexLet { $$ = NULL; }
+ | LexSetStatement LexLet LexOf { $$ = NULL; }
;
StatementListItem
;
LexBind
- : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); } LexOf
+ : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); }
;
LetOrConst
- : LexLet "!let" LexBind { $$ = false; }
- | LexLet "const" { $$ = true; }
+ : LexLet LexOf "!let" LexBind LexOf { $$ = false; }
+ | LexLet LexOf "const" { $$ = true; }
;
BindingList_
LexicalBinding
: BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
- | BindingPattern Initializer { CYNOT(@$); }
+ | LexOf BindingPattern Initializer { CYNOT(@$); }
;
/* }}} */
/* 13.3.2 Variable Statement {{{ */
VariableDeclaration
: BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
- | BindingPattern Initializer { CYNOT(@$); }
+ | LexOf BindingPattern Initializer { CYNOT(@$); }
;
/* }}} */
/* 13.3.3 Destructuring Binding Patterns {{{ */
;
ArrayBindingPattern
- : "let [" { CYNOT(@$); }
+ : "let [" BindingElementListOpt "]"
;
BindingPropertyList_
BindingPropertyListOpt
: BindingPropertyList
- |
+ | LexOf
+ ;
+
+BindingElementList
+ : BindingElementOpt[element] "," BindingElementListOpt[next]
+ | BindingRestElement[element]
+ | BindingElement[element]
+ ;
+
+BindingElementListOpt
+ : BindingElementList[pass]
+ | LexBind LexOf
;
BindingProperty
: SingleNameBinding
- | PropertyName ":" BindingElement
+ | LexOf PropertyName ":" BindingElement
;
BindingElement
: LexBind SingleNameBinding[pass] { $$ = $pass; }
- | LexBind BindingPattern InitializerOpt[initializer] { CYNOT(@$); }
+ | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); }
+ ;
+
+BindingElementOpt
+ : BindingElement[pass]
+ | LexBind LexOf
;
SingleNameBinding
;
BindingRestElement
- : "..." BindingIdentifier
+ : LexBind LexOf "..." BindingIdentifier
;
/* }}} */
/* 13.4 Empty Statement {{{ */
: "do" Statement[code] "while" "(" Expression[test] ")" TerminatorOpt { $$ = CYNew CYDoWhile($test, $code); }
| "while" "(" Expression[test] ")" Statement[code] { $$ = CYNew CYWhile($test, $code); }
| "for" "(" LexPushInOn ForStatementInitializer[initializer] LexPopIn ExpressionOpt[test] ";" ExpressionOpt[increment] ")" Statement[code] { $$ = CYNew CYFor($initializer, $test, $increment, $code); }
- | "for" "(" LexPushInOn LexLet Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); }
+ | "for" "(" LexPushInOn LexLet LexOf Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); }
| "for" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForIn($initializer, $iterable, $code); }
| "for" "(" LexPushInOn ForInStatementInitializer[initializer] "of" LexPopIn AssignmentExpression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
;
ForStatementInitializer
- : LexLet EmptyStatement[pass] { $$ = $pass; }
+ : LexLet LexOf EmptyStatement[pass] { $$ = $pass; }
| LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; }
- | LexLet VariableStatement_[initializer] ";" { $$ = $initializer; }
+ | LexLet LexOf VariableStatement_[initializer] ";" { $$ = $initializer; }
| LexicalDeclaration_[initializer] ";" { $$ = $initializer; }
;
ForInStatementInitializer
- : LexLet AccessExpression[pass] LexCrement { $$ = $pass; }
- | LexLet IndirectExpression[pass] { $$ = $pass; }
- | LexLet Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
+ : LexLet LexOf AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
+ | LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
+ | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
| ForDeclaration[pass] { $$ = $pass; }
;
ForBinding
: BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); }
- | BindingPattern { CYNOT(@$); }
+ | LexOf BindingPattern { CYNOT(@$); }
;
/* }}} */
/* 13.8 The continue Statement {{{ */
-Continue
- : "continue" LexNewLine
- ;
-
ContinueStatement
- : Continue TerminatorSoft { $$ = CYNew CYContinue(NULL); }
- | Continue Identifier[label] Terminator { $$ = CYNew CYContinue($label); }
+ : "continue" TerminatorSoft { $$ = CYNew CYContinue(NULL); }
+ | "continue" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYContinue($label); }
;
/* }}} */
/* 13.9 The break Statement {{{ */
-Break
- : "break" LexNewLine
- ;
-
BreakStatement
- : Break TerminatorSoft { $$ = CYNew CYBreak(NULL); }
- | Break Identifier[label] Terminator { $$ = CYNew CYBreak($label); }
+ : "break" TerminatorSoft { $$ = CYNew CYBreak(NULL); }
+ | "break" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYBreak($label); }
;
/* }}} */
/* 13.10 The return Statement {{{ */
Return
- : "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); } LexNewLine
+ : "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); }
;
ReturnStatement
: Return TerminatorSoft { $$ = CYNew CYReturn(NULL); }
- | Return Expression[value] Terminator { $$ = CYNew CYReturn($value); }
+ | Return NewLineNot Expression[value] Terminator { $$ = CYNew CYReturn($value); }
;
/* }}} */
/* 13.11 The with Statement {{{ */
;
CaseBlock
- : BRACE CaseClausesOpt[clauses] "}" { $$ = $clauses; }
+ : "{" CaseClausesOpt[clauses] "}" { $$ = $clauses; }
;
CaseClause
LabelledItem
: Statement[pass] { $$ = $pass; }
- | LexSetStatement LexLet FunctionDeclaration[pass] { $$ = $pass; }
+ | LexSetStatement LexLet LexOf FunctionDeclaration[pass] { $$ = $pass; }
;
/* }}} */
/* 13.14 The throw Statement {{{ */
-Throw
- : "throw" LexNewLine
- ;
-
ThrowStatement
- : Throw[throw] TerminatorSoft { CYERR(@throw, "throw without exception"); }
- | Throw Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); }
+ : "throw"[throw] TerminatorSoft { CYERR(@throw, "throw without exception"); }
+ | "throw" NewLineNot Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); }
;
/* }}} */
/* 13.15 The try Statement {{{ */
CatchParameter
: BindingIdentifier[pass] { $$ = $pass; }
- | BindingPattern { CYNOT(@$); }
+ | LexOf BindingPattern { CYNOT(@$); }
;
/* }}} */
/* 13.16 The debugger Statement {{{ */
/* 14.1 Function Definitions {{{ */
FunctionDeclaration
- : ";function" LexOf BindingIdentifier[name] "(" FormalParameters[parameters] ")" BRACE LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); }
+ : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); }
;
FunctionExpression
- : "function" LexOf BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" BRACE LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); }
+ : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); }
;
StrictFormalParameters
;
FormalParameters
- : LexBind { $$ = NULL; }
+ : LexBind LexOf { $$ = NULL; }
| FormalParameterList
;
;
FormalParameterList
- : LexBind FunctionRestParameter { CYNOT(@$); }
+ : FunctionRestParameter { CYNOT(@$); }
| FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); }
;
;
/* }}} */
/* 14.2 Arrow Function Definitions {{{ */
-LexEqualRight
- : { CYLIN(EqualRight); }
- ;
-
ArrowFunction
- : ArrowParameters[parameters] LexEqualRight "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); }
+ : ArrowParameters[parameters] LexNewLineOrOpt "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); }
;
ArrowParameters
: BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); }
- | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } }
+ | LexOf CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } }
;
ConciseBody
: AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); }
- | ";{" FunctionBody[code] "}" { $$ = $code; }
+ | LexOf ";{" FunctionBody[code] "}" { $$ = $code; }
;
/* }}} */
/* 14.3 Method Definitions {{{ */
MethodDefinition
- : PropertyName[name] "(" StrictFormalParameters[parameters] ")" BRACE FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); }
+ : PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); }
| GeneratorMethod[pass] { $$ = $pass; }
- | "get" PropertyName[name] "(" ")" BRACE FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); }
- | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" BRACE FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); }
+ | "get" PropertyName[name] "(" ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); }
+ | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); }
;
PropertySetParameterList
/* }}} */
/* 14.4 Generator Function Definitions {{{ */
GeneratorMethod
- : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" BRACE GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ }
+ : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ }
;
GeneratorDeclaration
- : ";function" LexOf "*" LexOf BindingIdentifier[name] "(" FormalParameters[code] ")" BRACE GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ }
+ : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ }
;
GeneratorExpression
- : "function" LexOf "*" LexOf BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" BRACE GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ }
+ : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ }
;
GeneratorBody
: LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; }
;
-Yield
- : "!yield" LexNewLine LexNoStar
- ;
-
YieldExpression
- : Yield NewLineOpt { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
- | Yield AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ }
- | Yield YieldStar AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ }
+ : "!yield" LexNewLineOrNot "\n" LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
+ | "!yield" LexNewLineOrNot "" LexNoStar LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
+ | "!yield" LexNewLineOrNot "" LexNoStar AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ }
+ | "!yield" LexNewLineOrNot "" LexNoStar LexOf "yield *" AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ }
;
/* }}} */
/* 14.5 Class Definitions {{{ */
ClassDeclaration
- : ";class" LexOf BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); }
+ : ";class" BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); }
;
ClassExpression
- : "class" LexOf BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); }
+ : "class" BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); }
;
ClassTail
- : ClassHeritageOpt[tail] { driver.class_.push($tail); } BRACE LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; }
+ : ClassHeritageOpt[tail] { driver.class_.push($tail); } "{" LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; }
;
ClassHeritage
ScriptBodyOpt
: ScriptBody[pass] { $$ = $pass; }
- | LexSetStatement LexLet { $$ = NULL; }
+ | LexSetStatement LexLet LexOf { $$ = NULL; }
;
/* }}} */
/* 15.2 Modules {{{ */
;
ModuleItem
- : LexSetStatement LexLet ImportDeclaration
- | LexSetStatement LexLet ExportDeclaration
+ : LexSetStatement LexLet LexOf ImportDeclaration
+ | LexSetStatement LexLet LexOf ExportDeclaration
| StatementListItem
;
/* }}} */
/* 15.2.2 Imports {{{ */
ImportDeclaration
: "import" ImportClause FromClause Terminator
- | "import" ModuleSpecifier Terminator
+ | "import" LexOf ModuleSpecifier Terminator
;
ImportClause
: ImportedDefaultBinding
- | NameSpaceImport
- | NamedImports
+ | LexOf NameSpaceImport
+ | LexOf NamedImports
| ImportedDefaultBinding "," NameSpaceImport
| ImportedDefaultBinding "," NamedImports
;
;
NamedImports
- : BRACE ImportsListOpt "}"
+ : "{" ImportsListOpt "}"
;
FromClause
ImportsListOpt
: ImportsList
- |
+ | LexOf
;
ImportSpecifier
: ImportedBinding
- | IdentifierName "as" ImportedBinding
+ | LexOf IdentifierName "as" ImportedBinding
;
ModuleSpecifier
| ExportClause FromClause Terminator
| ExportClause Terminator
| VariableStatement
- | "default" LexSetStatement HoistableDeclaration
- | "default" LexSetStatement ClassDeclaration
+ | "default" LexSetStatement LexOf HoistableDeclaration
+ | "default" LexSetStatement LexOf ClassDeclaration
| "default" LexSetStatement AssignmentExpression Terminator
;
ExportDeclaration
- : "export" LexSetStatement LexLet ExportDeclaration_
+ : "export" LexSetStatement LexLet LexOf ExportDeclaration_
| "export" Declaration
;
| "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
;
-TypedIdentifier
+TypedIdentifierMaybe
: TypeQualifierLeft[modifier] PrimitiveType[specifier] TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
;
+TypedIdentifierYes
+ : TypedIdentifierMaybe[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; }
+ ;
+
+TypedIdentifierNo
+ : TypedIdentifierMaybe[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; }
+ ;
+
PrimaryExpression
- : "@encode" "(" TypedIdentifier[typed] ")" { $$ = CYNew CYEncodedType($typed); }
+ : "@encode" "(" TypedIdentifierMaybe[typed] ")" { $$ = CYNew CYEncodedType($typed); }
;
/* }}} */
@end
;
ImplementationFieldListOpt
- : TypedIdentifier[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
+ : TypedIdentifierMaybe[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
| { $$ = NULL; }
;
ImplementationFields
- : BRACE ImplementationFieldListOpt[fields] "}" { $$ = $fields; }
+ : "{" ImplementationFieldListOpt[fields] "}" { $$ = $fields; }
;
MessageScope
;
TypeOpt
- : "(" TypedIdentifier[type] ")" { if ($type->identifier_ != NULL) CYERR($type->location_, "unexpected identifier"); $$ = $type; }
+ : "(" TypedIdentifierNo[type] ")" { $$ = $type; }
| { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
;
;
ClassMessageDeclaration
- : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] BRACE LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); }
+ : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] "{" LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); }
;
ClassMessageDeclarationListOpt
MessageExpression
: "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); }
- | "[" "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); }
+ | "[" LexOf "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); }
;
SelectorExpression_
| Word[part] { $$ = CYNew CYModule($part); }
;
-Declaration__
+Declaration_
: "@import" ModulePath[path] { $$ = CYNew CYImport($path); }
;
/* }}} */
/* }}} */
/* Cycript (Objective-C): Block Expressions {{{ */
PrimaryExpression
- : "^" TypedIdentifier[type] { if ($type->identifier_ != NULL) CYERR($type->location_, "unexpected identifier"); } BRACE FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); }
+ : "^" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); }
;
/* }}} */
/* Cycript (Objective-C): Instance Literals {{{ */
| "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
;
/* }}} */
-/* Cycript (C): auto Compatibility {{{ */
-Var_
- : "auto"
- ;
-/* }}} */
/* Cycript (C): Lambda Expressions {{{ */
TypedParameterList_
: "," TypedParameterList[parameters] { $$ = $parameters; }
;
TypedParameterList
- : TypedIdentifier[typed] TypedParameterList_[next] { $$ = CYNew CYTypedParameter($typed, $next); }
+ : TypedIdentifierMaybe[typed] TypedParameterList_[next] { $$ = CYNew CYTypedParameter($typed, $next); }
;
TypedParameterListOpt
;
PrimaryExpression
- : "[" "&" "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifier[type] BRACE FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
+ : "[" LexOf "&" "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifierMaybe[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
;
/* }}} */
/* Cycript (C): Type Definitions {{{ */
+IdentifierNoOf
+ : "typedef" NewLineOpt { $$ = CYNew CYIdentifier("typedef"); }
+ ;
+
Statement__
- : "typedef" TypedIdentifier[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($typed); }
+ : "typedef" NewLineNot TypedIdentifierYes[typed] Terminator { $$ = CYNew CYTypeDefinition($typed); }
+ ;
+
+PrimaryExpression
+ : "(" LexOf "typedef" NewLineOpt TypedIdentifierNo[typed] ")" { $$ = CYNew CYTypeExpression($typed); }
;
/* }}} */
/* Cycript (C): extern "C" {{{ */
+IdentifierNoOf
+ : "extern" NewLineOpt { $$ = CYNew CYIdentifier("extern"); }
+ ;
+
Statement__
- : "extern" StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } TypedIdentifier[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); } Terminator { $$ = CYNew CYExternal($abi, $typed); }
+ : "extern" NewLineNot StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } TypedIdentifierYes[typed] Terminator { $$ = CYNew CYExternal($abi, $typed); }
;
/* }}} */
;
XMLExpression
- : BRACE LexPushRegExp Expression LexPop "}"
+ : "{" LexPushRegExp Expression LexPop "}"
;
XMLTagName
;
Comprehension
- : ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
+ : LexOf ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
;
ComprehensionTail
/* }}} */
/* JavaScript FTW: Coalesce Operator {{{ */
ConditionalExpression
- : LogicalORExpression[test] "?" LexPushInOff ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $test, $false); }
+ : LogicalORExpression[test] "?" LexPushInOff LexOf ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $test, $false); }
;
/* }}} */
/* JavaScript FTW: Named Arguments {{{ */
ArgumentList
- : Word[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); }
+ : LexOf Word[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); }
;
/* }}} */
/* JavaScript FTW: Ruby Blocks {{{ */
RubyProcParameterList
: BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); }
- | { $$ = NULL; }
+ | LexOf { $$ = NULL; }
;
RubyProcParameters
| { $$ = NULL; }
;
-LexOpenBrace
- : { CYLIN(OpenBrace); }
- ;
-
RubyProcExpression
: "{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
;
PrimaryExpression
- : BRACE RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
+ : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
;
PostfixExpression
- : PostfixExpression[lhs] LexOpenBrace RubyProcExpression[rhs] { $$ = CYNew CYRubyBlock($lhs, $rhs); }
+ : PostfixExpression[lhs] RubyProcExpression[rhs] LexNewLineOrOpt { $$ = CYNew CYRubyBlock($lhs, $rhs); }
;
/* }}} */