-/* Cycript - Optimizing JavaScript Compiler/Runtime
- * Copyright (C) 2009-2015 Jay Freeman (saurik)
+/* Cycript - The Truly Universal Scripting Language
+ * Copyright (C) 2009-2016 Jay Freeman (saurik)
*/
/* GNU Affero General Public License, Version 3 {{{ */
#include "Driver.hpp"
#include "Parser.hpp"
#include "Stack.hpp"
+#include "Syntax.hpp"
#define CYNew new(driver.pool_)
@begin ObjectiveC
%union { CYMember *access_; }
%union { CYArgument *argument_; }
%union { CYAssignment *assignment_; }
+%union { CYBinding *binding_; }
+%union { CYBindings *bindings_; }
%union { CYBoolean *boolean_; }
+%union { CYBraced *braced_; }
%union { CYClause *clause_; }
%union { cy::Syntax::Catch *catch_; }
%union { CYClassTail *classTail_; }
%union { CYComprehension *comprehension_; }
-%union { CYDeclaration *declaration_; }
-%union { CYDeclarations *declarations_; }
%union { CYElement *element_; }
+%union { CYEnumConstant *constant_; }
%union { CYExpression *expression_; }
%union { CYFalse *false_; }
%union { CYVariable *variable_; }
%union { CYForInInitializer *forin_; }
%union { CYFunctionParameter *functionParameter_; }
%union { CYIdentifier *identifier_; }
+%union { CYImportSpecifier *import_; }
%union { CYInfix *infix_; }
%union { CYLiteral *literal_; }
%union { CYMethod *method_; }
%union { CYParenthetical *parenthetical_; }
%union { CYProperty *property_; }
%union { CYPropertyName *propertyName_; }
-%union { CYRubyProc *rubyProc_; }
+%union { CYTypeSigning signing_; }
%union { CYSpan *span_; }
%union { CYStatement *statement_; }
%union { CYString *string_; }
%union { CYWord *word_; }
@begin C
+%union { CYTypeIntegral *integral_; }
+%union { CYTypeStructField *structField_; }
%union { CYTypeModifier *modifier_; }
%union { CYTypeSpecifier *specifier_; }
-%union { CYTypedIdentifier *typedIdentifier_; }
+%union { CYTypedFormal *typedFormal_; }
+%union { CYTypedLocation *typedLocation_; }
+%union { CYTypedName *typedName_; }
%union { CYTypedParameter *typedParameter_; }
+%union { CYType *typedThing_; }
@end
@begin ObjectiveC
+%union { CYObjCKeyValue *keyValue_; }
+%union { CYImplementationField *implementationField_; }
%union { CYMessage *message_; }
%union { CYMessageParameter *messageParameter_; }
-%union { CYImplementationField *implementationField_; }
%union { CYProtocol *protocol_; }
%union { CYSelectorPart *selector_; }
@end
%code {
#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;
- }
+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_;
+
+ switch (token) {
+ case tk::OpenBrace:
+ case tk::OpenBracket:
+ case tk::OpenParen:
+ driver.in_.push(false);
+ break;
+
+ case tk::_in_:
+ if (driver.in_.top())
+ token = tk::_in__;
+ break;
+
+ case tk::CloseBrace:
+ case tk::CloseBracket:
+ case tk::CloseParen:
+ driver.in_.pop();
+ break;
+
+
+ case tk::_yield_:
+ if (driver.yield_.top())
+ token = tk::_yield__;
+ break;
+
+ case tk::NewLine:
+ driver.newline_ = true;
+ goto lex;
+ break;
+ }
+
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 CYHLD(location, token) do { \
+ if (driver.hold_ != empty_symbol) \
+ CYERR(location, "unexpected hold"); \
+ driver.hold_ = yyla.type; \
+ yyla.type = yytranslate_(token); \
+} while (false)
+
#define CYERR(location, message) do { \
error(location, message); \
YYABORT; \
} while (false)
+#define CYEOK() do { \
+ yyerrok; \
+ driver.errors_.pop_back(); \
+} while (false)
+
#define CYNOT(location) \
CYERR(location, "unimplemented feature")
+#define CYMPT(location) do { \
+ if (!yyla.empty() && yyla.type_get() != yyeof_) \
+ CYERR(location, "unexpected lookahead"); \
+} while (false)
+
}
%name-prefix "cy"
%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;
+ case CYMarkExpression:
+ driver.hold_ = yytranslate_(token::MarkExpression);
+ break;
+ }
};
%locations
%token SlashRight "/>"
%token LeftSlash "</"
-%token ColonColon "::"
%token PeriodPeriod ".."
@end
@begin E4X ObjectiveC
%token At "@"
-%token Pound "#"
@end
%token Ampersand "&"
%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 Tilde "~"
%token Colon ":"
+%token ColonColon "::"
%token Comma ","
%token Question "?"
%token SemiColon ";"
+%token Pound "#"
%token NewLine "\n"
+%token __ ""
%token Comment
%token CloseParen ")"
%token OpenBrace "{"
-%token OpenBrace_ "\n{"
-%token OpenBrace__ ";{"
+%token OpenBrace_ ";{"
+%token OpenBrace_let "let {"
%token CloseBrace "}"
%token OpenBracket "["
+%token OpenBracket_let "let ["
%token CloseBracket "]"
%token At_error_ "@error"
%token _typedef_ "typedef"
%token _unsigned_ "unsigned"
%token _signed_ "signed"
+%token _struct_ "struct"
%token _extern_ "extern"
@end
%token _null_ "null"
%token _true_ "true"
+%token _as_ "as"
%token _break_ "break"
%token _case_ "case"
%token _catch_ "catch"
%token _instanceof_ "instanceof"
%token _new_ "new"
%token _return_ "return"
-%token _return__ "!return"
%token _super_ "super"
%token _switch_ "switch"
%token _target_ "target"
%token _goto_ "goto"
%token _implements_ "implements"
%token _int_ "int"
+%token ___int128_ "__int128"
%token _interface_ "interface"
%token _let_ "let"
+%token _let__ "!let"
%token _long_ "long"
%token _native_ "native"
%token _package_ "package"
%token _private_ "private"
%token _protected_ "protected"
+%token ___proto___ "__proto__"
%token _prototype_ "prototype"
%token _public_ "public"
+%token ___restrict_ "__restrict"
+%token _restrict_ "restrict"
%token _set_ "set"
%token _short_ "short"
%token _static_ "static"
%token _synchronized_ "synchronized"
%token _throws_ "throws"
%token _transient_ "transient"
+%token _typeid_ "typeid"
%token _volatile_ "volatile"
%token _yield_ "yield"
%token _yield__ "!yield"
%token _SEL_ "SEL"
@end
-%token _auto_ "auto"
%token _each_ "each"
%token _of_ "of"
+%token _of__ "!of"
@begin E4X
%token _namespace_ "namespace"
@end
%token AutoComplete
-%token YieldStar
+%token YieldStar "yield *"
%token <identifier_> Identifier_
%token <number_> NumericLiteral
%token <string_> StringLiteral
-%token <literal_> RegularExpressionLiteral
+%token <literal_> RegularExpressionLiteral_
%token <string_> NoSubstitutionTemplate
%token <string_> TemplateHead
%token <string_> TemplateMiddle
%token <string_> TemplateTail
+%type <target_> AccessExpression
%type <expression_> AdditiveExpression
%type <argument_> ArgumentList_
%type <argument_> ArgumentList
%type <argument_> ArgumentListOpt
%type <argument_> Arguments
%type <target_> ArrayComprehension
+%type <element_> ArrayElement
%type <literal_> ArrayLiteral
%type <expression_> ArrowFunction
%type <functionParameter_> ArrowParameters
%type <expression_> AssignmentExpression
-%type <expression_> AssignmentExpressionOpt
%type <identifier_> BindingIdentifier
%type <identifier_> BindingIdentifierOpt
-%type <declarations_> BindingList_
-%type <declarations_> BindingList
+%type <bindings_> BindingList_
+%type <bindings_> BindingList
%type <expression_> BitwiseANDExpression
%type <statement_> Block
%type <statement_> BlockStatement
%type <boolean_> BooleanLiteral
-%type <declaration_> BindingElement
+%type <binding_> BindingElement
%type <expression_> BitwiseORExpression
%type <expression_> BitwiseXORExpression
+%type <target_> BracedExpression_
+%type <target_> BracedExpression
%type <statement_> BreakStatement
%type <statement_> BreakableStatement
%type <expression_> CallExpression_
%type <statement_> ConciseBody
%type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
%type <statement_> DebuggerStatement
-%type <statement_> Declaration__
%type <statement_> Declaration_
%type <statement_> Declaration
%type <clause_> DefaultClause
+%type <element_> ElementList_
%type <element_> ElementList
%type <element_> ElementListOpt
%type <statement_> ElseStatementOpt
%type <expression_> ExpressionOpt
%type <for_> ExpressionStatement_
%type <statement_> ExpressionStatement
+%type <statement_> ExternC
+%type <statement_> ExternCStatement
+%type <statement_> ExternCStatementListOpt
%type <finally_> Finally
-%type <declaration_> ForBinding
+%type <binding_> ForBinding
%type <forin_> ForDeclaration
%type <forin_> ForInStatementInitializer
%type <for_> ForStatementInitializer
-%type <declaration_> FormalParameter
+%type <binding_> FormalParameter
%type <functionParameter_> FormalParameterList_
%type <functionParameter_> FormalParameterList
%type <functionParameter_> FormalParameters
+%type <string_> FromClause
%type <statement_> FunctionBody
%type <statement_> FunctionDeclaration
%type <target_> FunctionExpression
%type <method_> GeneratorMethod
%type <statement_> HoistableDeclaration
%type <identifier_> Identifier
+%type <identifier_> IdentifierNoOf
%type <identifier_> IdentifierType
+%type <identifier_> IdentifierTypeNoOf
+%type <identifier_> IdentifierTypeOpt
%type <word_> IdentifierName
%type <variable_> IdentifierReference
%type <statement_> IfStatement
+%type <import_> ImportClause
+%type <statement_> ImportDeclaration
+%type <import_> ImportSpecifier
+%type <identifier_> ImportedBinding
+%type <import_> ImportedDefaultBinding
+%type <import_> ImportsList_
+%type <import_> ImportsList
+%type <import_> ImportsListOpt
+%type <target_> IndirectExpression
%type <expression_> Initializer
%type <expression_> InitializerOpt
%type <statement_> IterationStatement
%type <assignment_> LeftHandSideAssignment
%type <target_> LeftHandSideExpression
%type <bool_> LetOrConst
-%type <declaration_> LexicalBinding
+%type <binding_> LexicalBinding
%type <for_> LexicalDeclaration_
%type <statement_> LexicalDeclaration
%type <literal_> Literal
%type <access_> MemberAccess
%type <target_> MemberExpression
%type <method_> MethodDefinition
+%type <statement_> ModuleBody
+%type <statement_> ModuleBodyOpt
+%type <statement_> ModuleItem
+%type <statement_> ModuleItemList
+%type <statement_> ModuleItemListOpt
%type <module_> ModulePath
+%type <string_> ModuleSpecifier
%type <expression_> MultiplicativeExpression
+%type <import_> NameSpaceImport
+%type <import_> NamedImports
%type <target_> NewExpression
%type <null_> NullLiteral
%type <literal_> ObjectLiteral
%type <property_> PropertyDefinitionList_
%type <property_> PropertyDefinitionList
%type <property_> PropertyDefinitionListOpt
-%type <declaration_> PropertySetParameterList
+%type <functionParameter_> PropertySetParameterList
+%type <literal_> RegularExpressionLiteral
+%type <bool_> RegularExpressionSlash
%type <expression_> RelationalExpression
%type <statement_> ReturnStatement
-%type <rubyProc_> RubyProcExpression
+%type <braced_> BracedParameter
%type <functionParameter_> RubyProcParameterList_
%type <functionParameter_> RubyProcParameterList
%type <functionParameter_> RubyProcParameters
%type <statement_> ScriptBody
%type <statement_> ScriptBodyOpt
%type <expression_> ShiftExpression
-%type <declaration_> SingleNameBinding
+%type <binding_> SingleNameBinding
%type <statement_> Statement__
%type <statement_> Statement_
%type <statement_> Statement
%type <span_> TemplateSpans
%type <statement_> ThrowStatement
%type <statement_> TryStatement
+%type <statement_> TypeDefinition
%type <expression_> UnaryExpression_
%type <expression_> UnaryExpression
-%type <declaration_> VariableDeclaration
-%type <declarations_> VariableDeclarationList_
-%type <declarations_> VariableDeclarationList
+%type <binding_> VariableDeclaration
+%type <bindings_> VariableDeclarationList_
+%type <bindings_> VariableDeclarationList
%type <for_> VariableStatement_
%type <statement_> VariableStatement
%type <statement_> WithStatement
%type <word_> Word
+%type <word_> WordNoUnary
@begin ObjectiveC
%type <word_> WordOpt
@end
%type <expression_> YieldExpression
@begin C
-%type <specifier_> IntegerType
-%type <specifier_> IntegerTypeOpt
-%type <typedIdentifier_> PrefixedType
+%type <constant_> EnumConstantListOpt_
+%type <constant_> EnumConstantListOpt
+%type <number_> IntegerNumber
+%type <integral_> IntegerType
+%type <integral_> IntegerTypeOpt
+%type <typedName_> PrefixedType
+%type <specifier_> PrimitiveReference
%type <specifier_> PrimitiveType
-%type <typedIdentifier_> SuffixedType
-%type <typedIdentifier_> TypeSignifier
+%type <structField_> StructFieldListOpt
+%type <typedName_> SuffixedType
+%type <typedName_> SuffixedTypeOpt
+%type <typedName_> TypeSignifier
+%type <typedName_> TypeSignifierNone
+%type <typedName_> TypeSignifierOpt
+%type <signing_> TypeSigning
+%type <modifier_> ParameterTail
%type <modifier_> TypeQualifierLeft
-%type <typedIdentifier_> TypeQualifierRight
-%type <typedIdentifier_> TypedIdentifier
-%type <typedParameter_> TypedParameterList_
-%type <typedParameter_> TypedParameterList
-%type <typedParameter_> TypedParameterListOpt
+%type <modifier_> TypeQualifierLeftOpt
+%type <typedName_> TypeQualifierRight
+%type <typedName_> TypeQualifierRightOpt
+%type <typedName_> TypedIdentifierDefinition
+%type <typedThing_> TypedIdentifierEncoding
+%type <typedName_> TypedIdentifierField
+%type <typedName_> TypedIdentifierMaybe
+%type <typedLocation_> TypedIdentifierNo
+%type <typedName_> TypedIdentifierTagged
+%type <typedName_> TypedIdentifierYes
+%type <typedFormal_> TypedParameterList_
+%type <typedFormal_> TypedParameterList
+%type <typedFormal_> TypedParameterListOpt
+%type <typedParameter_> TypedParameters
@end
@begin ObjectiveC
%type <statement_> CategoryStatement
%type <expression_> ClassSuperOpt
%type <expression_> ConditionalExpressionClassic
-%type <implementationField_> ImplementationFieldListOpt
-%type <implementationField_> ImplementationFields
%type <message_> ClassMessageDeclaration
%type <message_> ClassMessageDeclarationListOpt
%type <protocol_> ClassProtocolListOpt
%type <protocol_> ClassProtocols
%type <protocol_> ClassProtocolsOpt
+%type <implementationField_> ImplementationFieldListOpt
%type <statement_> ImplementationStatement
+%type <keyValue_> KeyValuePairList_
+%type <keyValue_> KeyValuePairList
+%type <keyValue_> KeyValuePairListOpt
%type <target_> MessageExpression
%type <messageParameter_> MessageParameter
%type <messageParameter_> MessageParameters
%type <selector_> SelectorExpressionOpt
%type <argument_> SelectorList
%type <word_> SelectorWordOpt
-%type <typedIdentifier_> TypeOpt
+%type <typedThing_> TypeOpt
%type <argument_> VariadicCall
@end
%type <attribute_> AttributeIdentifier
/* XXX: %type <statement_> DefaultXMLNamespaceStatement */
%type <expression_> PropertyIdentifier
-%type <expression_> XMLListInitialiser
-%type <expression_> XMLInitialiser
+%type <expression_> XMLListInitilizer
+%type <expression_> XMLInitilizer
@end
/* }}} */
/* Token Priorities {{{ */
-%nonassoc ""
-%left "++" "--" "{"
-
%nonassoc "if"
%nonassoc "else"
+
+%nonassoc ":"
+%nonassoc "!yield"
/* }}} */
%start Program
%token MarkModule
%token MarkScript
+%token MarkExpression
%%
Program
: MarkScript Script
| MarkModule Module
+ | MarkExpression Expression[expression] { driver.context_ = $expression; }
;
/* Lexer State {{{ */
LexPushReturnOn: { driver.return_.push(true); };
LexPopReturn: { driver.return_.pop(); };
+Return: "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); };
LexPushSuperOn: { driver.super_.push(true); };
LexPushSuperOff: { driver.super_.push(false); };
LexPopSuper: { driver.super_.pop(); };
+Super: "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); };
LexPushYieldOn: { driver.yield_.push(true); };
LexPushYieldOff: { driver.yield_.push(false); };
LexPopYield: { driver.yield_.pop(); };
-LexSetRegExp
- : { CYLEX(); if (yyla.type == yytranslate_(token::Slash)) { yyla.clear(); driver.SetRegEx(false); } else if (yyla.type == yytranslate_(token::SlashEqual)) { yyla.clear(); driver.SetRegEx(true); } }
+LexNewLineOrOpt
+ : { CYLEX(); if (driver.newline_) { CYHLD(@$, tk::NewLine); } }
;
-LexNewLine
- : { if (!yyla.empty() && yyla.type_get() != yyeof_) CYERR(@$, "unexpected lookahead"); driver.next_ = true; }
+LexNewLineOrNot
+ : { CYLEX(); CYHLD(@$, driver.newline_ ? tk::NewLine : tk::__); }
;
LexNoStar
;
LexNoBrace
- : { CYMAP(OpenBrace__, OpenBrace); CYMAP(OpenBrace__, OpenBrace_); }
+ : { CYMAP(OpenBrace_, OpenBrace); }
;
LexNoClass
;
/* }}} */
/* Virtual Tokens {{{ */
-BRACE
- : "{"
- | "\n{"
- ;
-
Var_
: "var"
;
/* 11.6 Names and Keywords {{{ */
IdentifierName
- : Word { $$ = $1; }
+ : Word[pass] { $$ = $pass; }
| "for" { $$ = CYNew CYWord("for"); }
| "in" { $$ = CYNew CYWord("in"); }
| "instanceof" { $$ = CYNew CYWord("instanceof"); }
;
-NewLineOpt
- : "\n"
- |
- ;
-
-Word
- : Identifier { $$ = $1; }
- | "auto" { $$ = CYNew CYWord("auto"); }
+WordNoUnary
+ : IdentifierNoOf[pass] { $$ = $pass; }
| "break" { $$ = CYNew CYWord("break"); }
| "case" { $$ = CYNew CYWord("case"); }
| "catch" { $$ = CYNew CYWord("catch"); }
- | "class" { $$ = CYNew CYWord("class"); }
+ | "class" LexOf { $$ = CYNew CYWord("class"); }
| ";class" { $$ = CYNew CYWord("class"); }
| "const" { $$ = CYNew CYWord("const"); }
| "continue" { $$ = CYNew CYWord("continue"); }
| "debugger" { $$ = CYNew CYWord("debugger"); }
| "default" { $$ = CYNew CYWord("default"); }
- | "delete" LexSetRegExp { $$ = CYNew CYWord("delete"); }
| "do" { $$ = CYNew CYWord("do"); }
| "else" { $$ = CYNew CYWord("else"); }
| "enum" { $$ = CYNew CYWord("enum"); }
| "extends" { $$ = CYNew CYWord("extends"); }
| "false" { $$ = CYNew CYWord("false"); }
| "finally" { $$ = CYNew CYWord("finally"); }
- | "function" { $$ = CYNew CYWord("function"); }
+ | "function" LexOf { $$ = CYNew CYWord("function"); }
| "if" { $$ = CYNew CYWord("if"); }
| "import" { $$ = CYNew CYWord("import"); }
| "!in" { $$ = CYNew CYWord("in"); }
- | "new" LexSetRegExp { $$ = CYNew CYWord("new"); }
+ | "!of" { $$ = CYNew CYWord("of"); }
| "null" { $$ = CYNew CYWord("null"); }
| "return" { $$ = CYNew CYWord("return"); }
- | "!return" { $$ = CYNew CYWord("return"); }
| "super" { $$ = CYNew CYWord("super"); }
| "switch" { $$ = CYNew CYWord("switch"); }
| "this" { $$ = CYNew CYWord("this"); }
| "throw" { $$ = CYNew CYWord("throw"); }
| "true" { $$ = CYNew CYWord("true"); }
| "try" { $$ = CYNew CYWord("try"); }
- | "typeof" LexSetRegExp { $$ = CYNew CYWord("typeof"); }
| "var" { $$ = CYNew CYWord("var"); }
- | "void" LexSetRegExp { $$ = CYNew CYWord("void"); }
| "while" { $$ = CYNew CYWord("while"); }
| "with" { $$ = CYNew CYWord("with"); }
- | "yield" { $$ = CYNew CYIdentifier("yield"); }
-
- | Yield LexSetRegExp NewLineOpt { $$ = CYNew CYIdentifier("yield"); }
+ ;
- // XXX: should be Identifier
- | "let" { $$ = CYNew CYIdentifier("let"); }
+Word
+ : WordNoUnary[pass] { $$ = $pass; }
+ | "delete" { $$ = CYNew CYWord("delete"); }
+ | "typeof" { $$ = CYNew CYWord("typeof"); }
+ | "void" { $$ = CYNew CYWord("void"); }
+ | "yield" { $$ = CYNew CYIdentifier("yield"); }
;
@begin ObjectiveC
WordOpt
- : Word { $$ = $1; }
+ : Word[pass] { $$ = $pass; }
| { $$ = NULL; }
;
@end
| "false" { $$ = CYNew CYFalse(); }
;
/* }}} */
+/* 11.8.5 Regular Expression Literals {{{ */
+RegularExpressionSlash
+ : "/" { $$ = false; }
+ | "/=" { $$ = true; }
+ ;
+
+RegularExpressionLiteral
+ : RegularExpressionSlash[equals] { CYMPT(@$); driver.SetRegEx($equals); } RegularExpressionLiteral_[pass] { $$ = $pass; }
+ ;
+/* }}} */
/* 11.9 Automatic Semicolon Insertion {{{ */
StrictSemi
: { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
;
+NewLineNot
+ : LexNewLineOrNot ""
+ ;
+
+NewLineOpt
+ : LexNewLineOrNot "\n"
+ | NewLineNot
+ ;
+
TerminatorSoft
+ : LexNewLineOrNot "\n" StrictSemi
+ | NewLineNot LexOf Terminator
+ ;
+
+TerminatorHard
: ";"
- | "\n" StrictSemi
+ | error { if (yyla.type_get() != yyeof_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
;
Terminator
: ";"
- | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) { CYERR(@1, "required semi-colon"); } else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
+ | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
;
TerminatorOpt
/* 12.1 Identifiers {{{ */
IdentifierReference
- : Identifier { $$ = CYNew CYVariable($1); }
+ : Identifier[pass] { $$ = CYNew CYVariable($pass); }
| "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); }
;
BindingIdentifier
- : Identifier { $$ = $1; }
- | "yield" { $$ = CYNew CYIdentifier("yield"); }
+ : LexOf IdentifierNoOf[pass] { $$ = $pass; }
+ | LexOf "!of" { $$ = CYNew CYIdentifier("of"); }
+ | LexOf "yield" { $$ = CYNew CYIdentifier("yield"); }
;
BindingIdentifierOpt
- : BindingIdentifier { $$ = $1; }
- | { $$ = NULL; }
+ : BindingIdentifier[pass] { $$ = $pass; }
+ | LexOf { $$ = NULL; }
;
LabelIdentifier
- : Identifier { $$ = $1; }
+ : Identifier[pass] { $$ = $pass; }
| "yield" { $$ = CYNew CYIdentifier("yield"); }
;
-IdentifierType
- : Identifier_ { $$ = $1; }
+IdentifierTypeNoOf
+ : Identifier_[pass] { $$ = $pass; }
| "abstract" { $$ = CYNew CYIdentifier("abstract"); }
+ | "as" { $$ = CYNew CYIdentifier("as"); }
| "await" { $$ = CYNew CYIdentifier("await"); }
| "boolean" { $$ = CYNew CYIdentifier("boolean"); }
| "byte" { $$ = CYNew CYIdentifier("byte"); }
| "implements" { $$ = CYNew CYIdentifier("implements"); }
| "Infinity" { $$ = CYNew CYIdentifier("Infinity"); }
| "interface" { $$ = CYNew CYIdentifier("interface"); }
+ | "let" { $$ = CYNew CYIdentifier("let"); }
+ | "!let" LexBind LexOf { $$ = CYNew CYIdentifier("let"); }
| "native" { $$ = CYNew CYIdentifier("native"); }
- | "of" { $$ = CYNew CYIdentifier("of"); }
| "package" { $$ = CYNew CYIdentifier("package"); }
| "private" { $$ = CYNew CYIdentifier("private"); }
| "protected" { $$ = CYNew CYIdentifier("protected"); }
+ | "__proto__" { $$ = CYNew CYIdentifier("__proto__"); }
| "prototype" { $$ = CYNew CYIdentifier("prototype"); }
| "public" { $$ = CYNew CYIdentifier("public"); }
| "set" { $$ = CYNew CYIdentifier("set"); }
| "target" { $$ = CYNew CYIdentifier("target"); }
| "throws" { $$ = CYNew CYIdentifier("throws"); }
| "transient" { $$ = CYNew CYIdentifier("transient"); }
+ | "typeid" { $$ = CYNew CYIdentifier("typeid"); }
| "undefined" { $$ = CYNew CYIdentifier("undefined"); }
@begin ObjectiveC
| "bool" { $$ = CYNew CYIdentifier("bool"); }
@end
;
-Identifier
- : IdentifierType
+IdentifierType
+ : IdentifierTypeNoOf[pass] { $$ = $pass; }
+ | "of" { $$ = CYNew CYIdentifier("of"); }
+ ;
+
+IdentifierTypeOpt
+ : IdentifierType[pass] { $$ = $pass; }
+ | { $$ = NULL; }
+ ;
+
+IdentifierNoOf
+ : IdentifierTypeNoOf
| "char" { $$ = CYNew CYIdentifier("char"); }
| "int" { $$ = CYNew CYIdentifier("int"); }
+ | "__int128" { $$ = CYNew CYIdentifier("__int128"); }
| "long" { $$ = CYNew CYIdentifier("long"); }
+ | "__restrict" { $$ = CYNew CYIdentifier("__restrict"); }
+ | "restrict" { $$ = CYNew CYIdentifier("restrict"); }
| "short" { $$ = CYNew CYIdentifier("short"); }
| "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
| "YES" { $$ = CYNew CYIdentifier("YES"); }
@end
;
+
+Identifier
+ : IdentifierNoOf[pass] { $$ = $pass; }
+ | "of" { $$ = CYNew CYIdentifier("of"); }
+ | "!of" { $$ = CYNew CYIdentifier("of"); }
+ ;
/* }}} */
/* 12.2 Primary Expression {{{ */
PrimaryExpression
: "this" { $$ = CYNew CYThis(); }
- | IdentifierReference { $$ = $1; }
- | Literal { $$ = $1; }
- | ArrayLiteral { $$ = $1; }
- | ObjectLiteral { $$ = $1; }
- | FunctionExpression { $$ = $1; }
- | ClassExpression { $$ = $1; }
- | GeneratorExpression { $$ = $1; }
- | RegularExpressionLiteral { $$ = $1; }
- | TemplateLiteral { $$ = $1; }
- | CoverParenthesizedExpressionAndArrowParameterList { if ($1 == NULL) CYERR(@1, "invalid parenthetical"); $$ = $1; }
+ | IdentifierReference[pass] { $$ = $pass; }
+ | Literal[pass] { $$ = $pass; }
+ | ArrayLiteral[pass] { $$ = $pass; }
+ | ObjectLiteral[pass] { $$ = $pass; }
+ | FunctionExpression[pass] { $$ = $pass; }
+ | ClassExpression[pass] { $$ = $pass; }
+ | GeneratorExpression[pass] { $$ = $pass; }
+ | RegularExpressionLiteral[pass] { $$ = $pass; }
+ | TemplateLiteral[pass] { $$ = $pass; }
+ | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) CYERR(@cover, "invalid parenthetical"); $$ = $cover; }
| AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
;
CoverParenthesizedExpressionAndArrowParameterList
- : "(" LexPushInOff Expression ")" LexPopIn { $$ = CYNew CYParenthetical($3); }
- | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; }
- | "(" LexPushInOff LexSetRegExp "..." BindingIdentifier ")" LexPopIn { CYNOT(@$); }
- | "(" LexPushInOff Expression "," LexSetRegExp "..." BindingIdentifier ")" LexPopIn { CYNOT(@$); }
+ : "(" Expression[expression] ")" { $$ = CYNew CYParenthetical($expression); }
+ | "(" LexOf ")" { $$ = NULL; }
+ | "(" LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
+ | "(" Expression "," LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
;
/* }}} */
/* 12.2.4 Literals {{{ */
Literal
- : NullLiteral { $$ = $1; }
- | BooleanLiteral { $$ = $1; }
- | NumericLiteral { $$ = $1; }
- | StringLiteral { $$ = $1; }
+ : NullLiteral[pass] { $$ = $pass; }
+ | BooleanLiteral[pass] { $$ = $pass; }
+ | NumericLiteral[pass] { $$ = $pass; }
+ | StringLiteral[pass] { $$ = $pass; }
;
/* }}} */
/* 12.2.5 Array Initializer {{{ */
ArrayLiteral
- : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); }
+ : "[" ElementListOpt[elements] "]" { $$ = CYNew CYArray($elements); }
+ ;
+
+ArrayElement
+ : AssignmentExpression[value] { $$ = CYNew CYElementValue($value); }
+ | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
+ ;
+
+ElementList_
+ : "," ElementListOpt[elements] { $$ = $elements; }
+ | { $$ = NULL; }
;
ElementList
- : AssignmentExpressionOpt "," ElementListOpt { $$ = CYNew CYElementValue($1, $3); }
- | LexSetRegExp "..." AssignmentExpression { $$ = CYNew CYElementSpread($3); }
- | AssignmentExpression { $$ = CYNew CYElementValue($1, NULL); }
+ : ArrayElement[element] ElementList_[next] { $$ = $element; $$->SetNext($next); }
+ | LexOf "," ElementListOpt[next] { $$ = CYNew CYElementValue(NULL, $next); }
;
ElementListOpt
- : ElementList { $$ = $1; }
- | LexSetRegExp { $$ = NULL; }
+ : ElementList[pass] { $$ = $pass; }
+ | LexOf { $$ = NULL; }
;
/* }}} */
/* 12.2.6 Object Initializer {{{ */
ObjectLiteral
- : BRACE LexPushInOff PropertyDefinitionListOpt "}" LexPopIn { $$ = CYNew CYObject($3); }
+ : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); }
;
PropertyDefinitionList_
- : "," PropertyDefinitionListOpt { $$ = $2; }
+ : "," PropertyDefinitionListOpt[properties] { $$ = $properties; }
| { $$ = NULL; }
;
PropertyDefinitionList
- : PropertyDefinition PropertyDefinitionList_ { $1->SetNext($2); $$ = $1; }
+ : PropertyDefinition[property] PropertyDefinitionList_[next] { $property->SetNext($next); $$ = $property; }
;
PropertyDefinitionListOpt
- : LexSetRegExp PropertyDefinitionList { $$ = $2; }
- | LexSetRegExp { $$ = NULL; }
+ : PropertyDefinitionList[properties] { $$ = $properties; }
+ | { $$ = NULL; }
;
PropertyDefinition
- : IdentifierReference { $$ = CYNew CYPropertyValue($1->name_, $1); }
- | CoverInitializedName { CYNOT(@$); }
- | PropertyName ":" AssignmentExpression { $$ = CYNew CYPropertyValue($1, $3); }
- | MethodDefinition { $$ = $1; }
+ : IdentifierReference[value] { $$ = CYNew CYPropertyValue($value->name_, $value); }
+ | CoverInitializedName[name] { CYNOT(@$); }
+ | PropertyName[name] ":" AssignmentExpression[value] { $$ = CYNew CYPropertyValue($name, $value); }
+ | MethodDefinition[pass] { $$ = $pass; }
;
PropertyName
- : LiteralPropertyName { $$ = $1; }
- | ComputedPropertyName { $$ = $1; }
+ : LiteralPropertyName[pass] { $$ = $pass; }
+ | ComputedPropertyName[pass] { $$ = $pass; }
;
LiteralPropertyName
- : IdentifierName { $$ = $1; }
- | StringLiteral { $$ = $1; }
- | NumericLiteral { $$ = $1; }
+ : IdentifierName[pass] { $$ = $pass; }
+ | StringLiteral[pass] { $$ = $pass; }
+ | NumericLiteral[pass] { $$ = $pass; }
;
ComputedPropertyName
- : "[" AssignmentExpression "]" { $$ = CYNew CYComputed($2); }
+ : "[" AssignmentExpression[expression] "]" { $$ = CYNew CYComputed($expression); }
;
CoverInitializedName
;
Initializer
- : "=" AssignmentExpression { $$ = $2; }
+ : "=" AssignmentExpression[initializer] { $$ = $initializer; }
;
InitializerOpt
- : Initializer { $$ = $1; }
+ : Initializer[pass] { $$ = $pass; }
| { $$ = NULL; }
;
/* }}} */
/* 12.2.9 Template Literals {{{ */
TemplateLiteral
- : NoSubstitutionTemplate { $$ = CYNew CYTemplate($1, NULL); }
- | TemplateHead TemplateSpans { $$ = CYNew CYTemplate($1, $2); }
+ : NoSubstitutionTemplate[string] { $$ = CYNew CYTemplate($string, NULL); }
+ | TemplateHead[string] LexPushInOff TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); }
;
TemplateSpans
- : Expression TemplateMiddle TemplateSpans { $$ = CYNew CYSpan($1, $2, $3); }
- | Expression TemplateTail { $$ = CYNew CYSpan($1, $2, NULL); }
+ : Expression[value] TemplateMiddle[string] TemplateSpans[spans] { $$ = CYNew CYSpan($value, $string, $spans); }
+ | Expression[value] TemplateTail[string] LexPopIn { $$ = CYNew CYSpan($value, $string, NULL); }
;
/* }}} */
/* 12.3 Left-Hand-Side Expressions {{{ */
MemberAccess
- : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); }
- | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
+ : "[" Expression[property] "]" { $$ = CYNew CYDirectMember(NULL, $property); }
+ | "." IdentifierName[property] { $$ = CYNew CYDirectMember(NULL, CYNew CYString($property)); }
| "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
| TemplateLiteral { CYNOT(@$); }
;
MemberExpression
- : LexSetRegExp PrimaryExpression { $$ = $2; }
- | MemberExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
- | SuperProperty { $$ = $1; }
+ : PrimaryExpression[pass] { $$ = $pass; }
+ | MemberExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
+ | SuperProperty[pass] { $$ = $pass; }
| MetaProperty { CYNOT(@$); }
- | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
+ | "new" MemberExpression[constructor] Arguments[arguments] { $$ = CYNew cy::Syntax::New($constructor, $arguments); }
;
SuperProperty
- : LexSetRegExp "super" { if (!driver.super_.top()) CYERR(@2, "invalid super"); } "[" Expression "]" { $$ = CYNew CYSuperAccess($5); }
- | LexSetRegExp "super" { if (!driver.super_.top()) CYERR(@2, "invalid super"); } "." IdentifierName { $$ = CYNew CYSuperAccess(CYNew CYString($5)); }
+ : Super "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); }
+ | Super "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); }
;
MetaProperty
;
NewTarget
- : LexSetRegExp "new" LexSetRegExp "." "target"
+ : "new" "." "target"
;
NewExpression
- : MemberExpression { $$ = $1; }
- | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
+ : MemberExpression[pass] { $$ = $pass; }
+ | "new" NewExpression[expression] { $$ = CYNew cy::Syntax::New($expression, NULL); }
;
CallExpression_
- : MemberExpression { $$ = $1; }
- | CallExpression { $$ = $1; }
+ : MemberExpression[pass] { $$ = $pass; }
+ | CallExpression[pass] { $$ = $pass; }
;
CallExpression
- : CallExpression_ Arguments { if (!$1->Eval()) $$ = CYNew CYCall($1, $2); else $$ = CYNew CYEval($2); }
- | SuperCall { $$ = $1; }
- | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
+ : CallExpression_[function] Arguments[arguments] { if (!$function->Eval()) $$ = CYNew CYCall($function, $arguments); else $$ = CYNew CYEval($arguments); }
+ | SuperCall[pass] { $$ = $pass; }
+ | CallExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
;
SuperCall
- : LexSetRegExp "super" { if (!driver.super_.top()) CYERR(@2, "invalid super"); } Arguments { $$ = CYNew CYSuperCall($4); }
+ : Super Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
;
Arguments
- : "(" LexPushInOff ArgumentListOpt ")" LexPopIn { $$ = $3; }
+ : "(" ArgumentListOpt[arguments] ")" { $$ = $arguments; }
;
ArgumentList_
- : "," ArgumentList { $$ = $2; }
+ : "," ArgumentList[arguments] { $$ = $arguments; }
| { $$ = NULL; }
;
ArgumentList
- : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
- | LexSetRegExp "..." AssignmentExpression { CYNOT(@$); }
+ : AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
+ | LexOf "..." AssignmentExpression { CYNOT(@$); }
;
ArgumentListOpt
- : ArgumentList { $$ = $1; }
- | LexSetRegExp { $$ = NULL; }
+ : ArgumentList[pass] { $$ = $pass; }
+ | LexOf { $$ = NULL; }
+ ;
+
+AccessExpression
+ : NewExpression[pass] { $$ = $pass; }
+ | CallExpression[pass] { $$ = $pass; }
;
LeftHandSideExpression
- : NewExpression { $$ = $1; }
- | CallExpression { $$ = $1; }
+ : BracedExpression[pass] { $$ = $pass; }
+ | IndirectExpression[pass] { $$ = $pass; }
;
/* }}} */
/* 12.4 Postfix Expressions {{{ */
PostfixExpression
- : %prec "" LeftHandSideExpression { $$ = $1; }
- | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
- | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
+ : BracedExpression[pass] { $$ = $pass; }
+ | AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); }
+ | AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); }
;
/* }}} */
/* 12.5 Unary Operators {{{ */
UnaryExpression_
- : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
- | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
- | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
- | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
- | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
- | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
- | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
- | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
- | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
- | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
- | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
+ : "delete" UnaryExpression[rhs] { $$ = CYNew CYDelete($rhs); }
+ | "void" UnaryExpression[rhs] { $$ = CYNew CYVoid($rhs); }
+ | "typeof" UnaryExpression[rhs] { $$ = CYNew CYTypeOf($rhs); }
+ | "++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); }
+ | "--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); }
+ | "+" UnaryExpression[rhs] { $$ = CYNew CYAffirm($rhs); }
+ | "-" UnaryExpression[rhs] { $$ = CYNew CYNegate($rhs); }
+ | "~" UnaryExpression[rhs] { $$ = CYNew CYBitwiseNot($rhs); }
+ | "!" UnaryExpression[rhs] { $$ = CYNew CYLogicalNot($rhs); }
;
UnaryExpression
- : %prec "" PostfixExpression { $$ = $1; }
- | LexSetRegExp UnaryExpression_ { $$ = $2; }
+ : PostfixExpression[expression] { $$ = $expression; }
+ | UnaryExpression_[pass] { $$ = $pass; }
;
/* }}} */
/* 12.6 Multiplicative Operators {{{ */
MultiplicativeExpression
- : UnaryExpression { $$ = $1; }
- | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
- | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
- | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
+ : UnaryExpression[pass] { $$ = $pass; }
+ | MultiplicativeExpression[lhs] "*" UnaryExpression[rhs] { $$ = CYNew CYMultiply($lhs, $rhs); }
+ | MultiplicativeExpression[lhs] "/" UnaryExpression[rhs] { $$ = CYNew CYDivide($lhs, $rhs); }
+ | MultiplicativeExpression[lhs] "%" UnaryExpression[rhs] { $$ = CYNew CYModulus($lhs, $rhs); }
;
/* }}} */
/* 12.7 Additive Operators {{{ */
AdditiveExpression
- : MultiplicativeExpression { $$ = $1; }
- | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
- | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
+ : MultiplicativeExpression[pass] { $$ = $pass; }
+ | AdditiveExpression[lhs] "+" MultiplicativeExpression[rhs] { $$ = CYNew CYAdd($lhs, $rhs); }
+ | AdditiveExpression[lhs] "-" MultiplicativeExpression[rhs] { $$ = CYNew CYSubtract($lhs, $rhs); }
;
/* }}} */
/* 12.8 Bitwise Shift Operators {{{ */
ShiftExpression
- : AdditiveExpression { $$ = $1; }
- | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
- | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
- | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
+ : AdditiveExpression[pass] { $$ = $pass; }
+ | ShiftExpression[lhs] "<<" AdditiveExpression[rhs] { $$ = CYNew CYShiftLeft($lhs, $rhs); }
+ | ShiftExpression[lhs] ">>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightSigned($lhs, $rhs); }
+ | ShiftExpression[lhs] ">>>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightUnsigned($lhs, $rhs); }
;
/* }}} */
/* 12.9 Relational Operators {{{ */
RelationalExpression
- : ShiftExpression { $$ = $1; }
- | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); }
- | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); }
- | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); }
- | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); }
- | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); }
- | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); }
+ : ShiftExpression[pass] { $$ = $pass; }
+ | RelationalExpression[lhs] "<" ShiftExpression[rhs] { $$ = CYNew CYLess($lhs, $rhs); }
+ | RelationalExpression[lhs] ">" ShiftExpression[rhs] { $$ = CYNew CYGreater($lhs, $rhs); }
+ | RelationalExpression[lhs] "<=" ShiftExpression[rhs] { $$ = CYNew CYLessOrEqual($lhs, $rhs); }
+ | RelationalExpression[lhs] ">=" ShiftExpression[rhs] { $$ = CYNew CYGreaterOrEqual($lhs, $rhs); }
+ | RelationalExpression[lhs] "instanceof" ShiftExpression[rhs] { $$ = CYNew CYInstanceOf($lhs, $rhs); }
+ | RelationalExpression[lhs] "in" ShiftExpression[rhs] { $$ = CYNew CYIn($lhs, $rhs); }
;
/* }}} */
/* 12.10 Equality Operators {{{ */
EqualityExpression
- : RelationalExpression { $$ = $1; }
- | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
- | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
- | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
- | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
+ : RelationalExpression[pass] { $$ = $pass; }
+ | EqualityExpression[lhs] "==" RelationalExpression[rhs] { $$ = CYNew CYEqual($lhs, $rhs); }
+ | EqualityExpression[lhs] "!=" RelationalExpression[rhs] { $$ = CYNew CYNotEqual($lhs, $rhs); }
+ | EqualityExpression[lhs] "===" RelationalExpression[rhs] { $$ = CYNew CYIdentical($lhs, $rhs); }
+ | EqualityExpression[lhs] "!==" RelationalExpression[rhs] { $$ = CYNew CYNotIdentical($lhs, $rhs); }
;
/* }}} */
/* 12.11 Binary Bitwise Operators {{{ */
BitwiseANDExpression
- : EqualityExpression { $$ = $1; }
- | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
+ : EqualityExpression[pass] { $$ = $pass; }
+ | BitwiseANDExpression[lhs] "&" EqualityExpression[rhs] { $$ = CYNew CYBitwiseAnd($lhs, $rhs); }
;
BitwiseXORExpression
- : BitwiseANDExpression { $$ = $1; }
- | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
+ : BitwiseANDExpression[pass] { $$ = $pass; }
+ | BitwiseXORExpression[lhs] "^" BitwiseANDExpression[rhs] { $$ = CYNew CYBitwiseXOr($lhs, $rhs); }
;
BitwiseORExpression
- : BitwiseXORExpression { $$ = $1; }
- | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
+ : BitwiseXORExpression[pass] { $$ = $pass; }
+ | BitwiseORExpression[lhs] "|" BitwiseXORExpression[rhs] { $$ = CYNew CYBitwiseOr($lhs, $rhs); }
;
/* }}} */
/* 12.12 Binary Logical Operators {{{ */
LogicalANDExpression
- : BitwiseORExpression { $$ = $1; }
- | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
+ : BitwiseORExpression[pass] { $$ = $pass; }
+ | LogicalANDExpression[lhs] "&&" BitwiseORExpression[rhs] { $$ = CYNew CYLogicalAnd($lhs, $rhs); }
;
LogicalORExpression
- : LogicalANDExpression { $$ = $1; }
- | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
+ : LogicalANDExpression[pass] { $$ = $pass; }
+ | LogicalORExpression[lhs] "||" LogicalANDExpression[rhs] { $$ = CYNew CYLogicalOr($lhs, $rhs); }
;
/* }}} */
/* 12.13 Conditional Operator ( ? : ) {{{ */
@begin ObjectiveC
ConditionalExpressionClassic
- : LogicalORExpression { $$ = $1; }
- | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpressionClassic { $$ = CYNew CYCondition($1, $4, $7); }
+ : LogicalORExpression[pass] { $$ = $pass; }
+ | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpressionClassic[false] { $$ = CYNew CYCondition($test, $true, $false); }
;
@end
ConditionalExpression
- : LogicalORExpression { $$ = $1; }
- | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
+ : LogicalORExpression[pass] { $$ = $pass; }
+ | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $true, $false); }
;
/* }}} */
/* 12.14 Assignment Operators {{{ */
LeftHandSideAssignment
- : LeftHandSideExpression "=" { $$ = CYNew CYAssign($1, NULL); }
- | LeftHandSideExpression "*=" { $$ = CYNew CYMultiplyAssign($1, NULL); }
- | LeftHandSideExpression "/=" { $$ = CYNew CYDivideAssign($1, NULL); }
- | LeftHandSideExpression "%=" { $$ = CYNew CYModulusAssign($1, NULL); }
- | LeftHandSideExpression "+=" { $$ = CYNew CYAddAssign($1, NULL); }
- | LeftHandSideExpression "-=" { $$ = CYNew CYSubtractAssign($1, NULL); }
- | LeftHandSideExpression "<<=" { $$ = CYNew CYShiftLeftAssign($1, NULL); }
- | LeftHandSideExpression ">>=" { $$ = CYNew CYShiftRightSignedAssign($1, NULL); }
- | LeftHandSideExpression ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($1, NULL); }
- | LeftHandSideExpression "&=" { $$ = CYNew CYBitwiseAndAssign($1, NULL); }
- | LeftHandSideExpression "^=" { $$ = CYNew CYBitwiseXOrAssign($1, NULL); }
- | LeftHandSideExpression "|=" { $$ = CYNew CYBitwiseOrAssign($1, NULL); }
+ : LeftHandSideExpression[lhs] "=" { $$ = CYNew CYAssign($lhs, NULL); }
+ | LeftHandSideExpression[lhs] "*=" { $$ = CYNew CYMultiplyAssign($lhs, NULL); }
+ | LeftHandSideExpression[lhs] "/=" { $$ = CYNew CYDivideAssign($lhs, NULL); }
+ | LeftHandSideExpression[lhs] "%=" { $$ = CYNew CYModulusAssign($lhs, NULL); }
+ | LeftHandSideExpression[lhs] "+=" { $$ = CYNew CYAddAssign($lhs, NULL); }
+ | LeftHandSideExpression[lhs] "-=" { $$ = CYNew CYSubtractAssign($lhs, NULL); }
+ | LeftHandSideExpression[lhs] "<<=" { $$ = CYNew CYShiftLeftAssign($lhs, NULL); }
+ | LeftHandSideExpression[lhs] ">>=" { $$ = CYNew CYShiftRightSignedAssign($lhs, NULL); }
+ | LeftHandSideExpression[lhs] ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($lhs, NULL); }
+ | LeftHandSideExpression[lhs] "&=" { $$ = CYNew CYBitwiseAndAssign($lhs, NULL); }
+ | LeftHandSideExpression[lhs] "^=" { $$ = CYNew CYBitwiseXOrAssign($lhs, NULL); }
+ | LeftHandSideExpression[lhs] "|=" { $$ = CYNew CYBitwiseOrAssign($lhs, NULL); }
;
@begin ObjectiveC
AssignmentExpressionClassic
- : ConditionalExpressionClassic { $$ = $1; }
- | LeftHandSideAssignment AssignmentExpressionClassic { $1->SetRight($2); $$ = $1; }
+ : LexOf ConditionalExpressionClassic[pass] { $$ = $pass; }
+ | LexOf LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
;
@end
AssignmentExpression
- : ConditionalExpression { $$ = $1; }
- | LexSetRegExp YieldExpression { $$ = $2; }
- | ArrowFunction { $$ = $1; }
- | LeftHandSideAssignment AssignmentExpression { $1->SetRight($2); $$ = $1; }
- ;
-
-AssignmentExpressionOpt
- : AssignmentExpression { $$ = $1; }
- | LexSetRegExp { $$ = NULL; }
+ : LexOf ConditionalExpression[pass] { $$ = $pass; }
+ | LexOf YieldExpression[pass] { $$ = $pass; }
+ | ArrowFunction[pass] { $$ = $pass; }
+ | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
;
/* }}} */
/* 12.15 Comma Operator ( , ) {{{ */
Expression
- : AssignmentExpression { $$ = $1; }
- | Expression "," AssignmentExpression { $$ = CYNew CYCompound($1, $3); }
+ : AssignmentExpression[pass] { $$ = $pass; }
+ | Expression[expression] "," AssignmentExpression[next] { $$ = CYNew CYCompound($expression, $next); }
;
ExpressionOpt
- : Expression { $$ = $1; }
- | LexSetRegExp { $$ = NULL; }
+ : Expression[pass] { $$ = $pass; }
+ | LexOf { $$ = NULL; }
;
/* }}} */
/* 13 Statements and Declarations {{{ */
Statement__
- : BlockStatement { $$ = $1; }
- | VariableStatement { $$ = $1; }
- | EmptyStatement { $$ = $1; }
- | IfStatement { $$ = $1; }
- | BreakableStatement { $$ = $1; }
- | ContinueStatement { $$ = $1; }
- | BreakStatement { $$ = $1; }
- | ReturnStatement { $$ = $1; }
- | WithStatement { $$ = $1; }
- | LabelledStatement { $$ = $1; }
- | ThrowStatement { $$ = $1; }
- | TryStatement { $$ = $1; }
- | DebuggerStatement { $$ = $1; }
+ : BlockStatement[pass] { $$ = $pass; }
+ | VariableStatement[pass] { $$ = $pass; }
+ | EmptyStatement[pass] { $$ = $pass; }
+ | IfStatement[pass] { $$ = $pass; }
+ | BreakableStatement[pass] { $$ = $pass; }
+ | ContinueStatement[pass] { $$ = $pass; }
+ | BreakStatement[pass] { $$ = $pass; }
+ | ReturnStatement[pass] { $$ = $pass; }
+ | WithStatement[pass] { $$ = $pass; }
+ | LabelledStatement[pass] { $$ = $pass; }
+ | ThrowStatement[pass] { $$ = $pass; }
+ | TryStatement[pass] { $$ = $pass; }
+ | DebuggerStatement[pass] { $$ = $pass; }
;
Statement_
- : LexSetRegExp Statement__ { $$ = $2; }
- | ExpressionStatement { $$ = $1; }
+ : LexOf Statement__[pass] { $$ = $pass; }
+ | ExpressionStatement[pass] { $$ = $pass; }
;
Statement
- : LexSetStatement Statement_ { $$ = $2; }
- ;
-
-Declaration__
- : HoistableDeclaration { $$ = $1; }
- | ClassDeclaration { $$ = $1; }
- | LexicalDeclaration { $$ = $1; }
+ : LexSetStatement LexLet Statement_[pass] { $$ = $pass; }
;
Declaration_
- : LexSetRegExp Declaration__ { $$ = $2; }
+ : HoistableDeclaration[pass] { $$ = $pass; }
+ | ClassDeclaration[pass] { $$ = $pass; }
;
Declaration
- : LexSetStatement Declaration_ { $$ = $2; }
+ : LexSetStatement LexLet LexOf Declaration_[pass] { $$ = $pass; }
+ | LexSetStatement LexicalDeclaration[pass] { $$ = $pass; }
;
HoistableDeclaration
- : FunctionDeclaration { $$ = $1; }
- | GeneratorDeclaration { $$ = $1; }
+ : FunctionDeclaration[pass] { $$ = $pass; }
+ | GeneratorDeclaration[pass] { $$ = $pass; }
;
BreakableStatement
- : IterationStatement { $$ = $1; }
- | SwitchStatement { $$ = $1; }
+ : IterationStatement[pass] { $$ = $pass; }
+ | SwitchStatement[pass] { $$ = $pass; }
;
/* }}} */
/* 13.2 Block {{{ */
BlockStatement
- : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
+ : ";{" StatementListOpt[code] "}" { $$ = CYNew CYBlock($code); }
;
Block
- : BRACE StatementListOpt "}" { $$ = $2; }
+ : "{" StatementListOpt[code] "}" { $$ = $code; }
;
StatementList
- : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
+ : StatementListItem[statement] StatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
;
StatementListOpt
- : StatementList { $$ = $1; }
- | LexSetStatement LexSetRegExp { $$ = NULL; }
+ : StatementList[pass] { $$ = $pass; }
+ | LexSetStatement LexLet LexOf { $$ = NULL; }
;
StatementListItem
- : Statement { $$ = $1; }
- | Declaration { $$ = $1; }
+ : Statement[pass] { $$ = $pass; }
+ | Declaration[pass] { $$ = $pass; }
;
/* }}} */
/* 13.3 Let and Const Declarations {{{ */
LexicalDeclaration_
- : LetOrConst BindingList { $$ = CYNew CYLet($1, $2); }
+ : LetOrConst[constant] BindingList[bindings] { $$ = CYNew CYLexical($constant, $bindings); }
;
LexicalDeclaration
- : LexicalDeclaration_ Terminator { $$ = $1; }
+ : LexicalDeclaration_[statement] Terminator { $$ = $statement; }
+ ;
+
+LexLet
+ : { CYMAP(_let__, _let_); }
+ ;
+
+LexOf
+ : { CYMAP(_of__, _of_); }
+ ;
+
+LexBind
+ : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); }
;
LetOrConst
- : "let" { $$ = false; }
- | "const" { $$ = true; }
+ : LexLet LexOf "!let" LexBind LexOf { $$ = false; }
+ | LexLet LexOf "const" { $$ = true; }
;
BindingList_
- : "," BindingList { $$ = $2; }
+ : "," LexBind BindingList[bindings] { $$ = $bindings; }
| { $$ = NULL; }
;
BindingList
- : LexicalBinding BindingList_ { $$ = CYNew CYDeclarations($1, $2); }
+ : LexicalBinding[binding] BindingList_[next] { $$ = CYNew CYBindings($binding, $next); }
;
LexicalBinding
- : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
- | BindingPattern Initializer { CYNOT(@1); }
+ : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
+ | LexOf BindingPattern Initializer { CYNOT(@$); }
;
/* }}} */
/* 13.3.2 Variable Statement {{{ */
VariableStatement_
- : Var_ VariableDeclarationList { $$ = CYNew CYVar($2); }
+ : Var_ VariableDeclarationList[bindings] { $$ = CYNew CYVar($bindings); }
;
VariableStatement
- : VariableStatement_ Terminator { $$ = $1; }
+ : VariableStatement_[statement] Terminator { $$ = $statement; }
;
VariableDeclarationList_
- : "," VariableDeclarationList { $$ = $2; }
+ : "," VariableDeclarationList[bindings] { $$ = $bindings; }
| { $$ = NULL; }
;
VariableDeclarationList
- : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
+ : LexBind VariableDeclaration[binding] VariableDeclarationList_[next] { $$ = CYNew CYBindings($binding, $next); }
;
VariableDeclaration
- : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
- | BindingPattern Initializer { CYNOT(@1); }
+ : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
+ | LexOf BindingPattern Initializer { CYNOT(@$); }
;
/* }}} */
/* 13.3.3 Destructuring Binding Patterns {{{ */
;
ObjectBindingPattern
- : BRACE BindingPropertyListOpt "}"
+ : "let {" BindingPropertyListOpt "}"
;
ArrayBindingPattern
- : "[" { 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
- : SingleNameBinding { $$ = $1; }
- | BindingPattern InitializerOpt { CYNOT(@$); }
+ : LexBind SingleNameBinding[pass] { $$ = $pass; }
+ | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); }
+ ;
+
+BindingElementOpt
+ : BindingElement[pass]
+ | LexBind LexOf
;
SingleNameBinding
- : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
+ : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
;
BindingRestElement
- : "..." BindingIdentifier
+ : LexBind LexOf "..." BindingIdentifier
;
/* }}} */
/* 13.4 Empty Statement {{{ */
/* }}} */
/* 13.5 Expression Statement {{{ */
ExpressionStatement_
- : Expression { $$ = CYNew CYExpress($1); }
+ : Expression[expression] { $$ = CYNew CYExpress($[expression]); }
ExpressionStatement
- : ExpressionStatement_ Terminator { $$ = $1; }
+ : ExpressionStatement_[statement] Terminator { $$ = $statement; }
;
/* }}} */
/* 13.6 The if Statement {{{ */
ElseStatementOpt
- : "else" Statement { $$ = $2; }
+ : "else" Statement[false] { $$ = $false; }
| %prec "if" { $$ = NULL; }
;
IfStatement
- : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
+ : "if" "(" Expression[test] ")" Statement[true] ElseStatementOpt[false] { $$ = CYNew CYIf($test, $true, $false); }
;
/* }}} */
/* 13.7 Iteration Statements {{{ */
IterationStatement
- : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
- | "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
- | "for" "(" LexPushInOn ForStatementInitializer LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $6, $8, $10); }
- | "for" "(" LexPushInOn LexSetRegExp Var_ BindingIdentifier Initializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForInitialized(CYNew CYDeclaration($6, $7), $10, $12); }
- | "for" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
- | "for" "(" LexPushInOn ForInStatementInitializer "of" LexPopIn AssignmentExpression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
+ : "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 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
- : LexSetRegExp EmptyStatement { $$ = $2; }
- | ExpressionStatement_ ";" { $$ = $1; }
- | LexSetRegExp VariableStatement_ ";" { $$ = $2; }
- | LexSetRegExp LexicalDeclaration_ ";" { $$ = $2; }
+ : LexLet LexOf EmptyStatement[pass] { $$ = $pass; }
+ | LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; }
+ | LexLet LexOf VariableStatement_[initializer] ";" { $$ = $initializer; }
+ | LexicalDeclaration_[initializer] ";" { $$ = $initializer; }
;
ForInStatementInitializer
- : LeftHandSideExpression { $$ = $1; }
- | LexSetRegExp Var_ ForBinding { $$ = CYNew CYForVariable($3); }
- | LexSetRegExp ForDeclaration { $$ = $2; }
+ : LexLet LexOf BracedExpression[pass] { $$ = $pass; }
+ | LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
+ | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
+ | ForDeclaration[pass] { $$ = $pass; }
;
ForDeclaration
- : LetOrConst ForBinding { $$ = CYNew CYForLexical($1, $2); }
+ : LetOrConst[constant] ForBinding[binding] { $$ = CYNew CYForLexical($constant, $binding); }
;
ForBinding
- : BindingIdentifier { $$ = CYNew CYDeclaration($1, NULL); }
- | BindingPattern { CYNOT(@1); }
+ : BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); }
+ | LexOf BindingPattern { CYNOT(@$); }
;
/* }}} */
/* 13.8 The continue Statement {{{ */
-Continue
- : "continue" LexNewLine
- ;
-
ContinueStatement
- : Continue TerminatorSoft { $$ = CYNew CYContinue(NULL); }
- | Continue Identifier Terminator { $$ = CYNew CYContinue($2); }
+ : "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 Terminator { $$ = CYNew CYBreak($2); }
+ : "break" TerminatorSoft { $$ = CYNew CYBreak(NULL); }
+ | "break" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYBreak($label); }
;
/* }}} */
/* 13.10 The return Statement {{{ */
-Return
- : "!return" LexNewLine
- ;
-
ReturnStatement
- : Return LexSetRegExp TerminatorSoft { $$ = CYNew CYReturn(NULL); }
- | Return Expression Terminator { $$ = CYNew CYReturn($2); }
+ : Return TerminatorSoft { $$ = CYNew CYReturn(NULL); }
+ | Return NewLineNot Expression[value] Terminator { $$ = CYNew CYReturn($value); }
;
/* }}} */
/* 13.11 The with Statement {{{ */
WithStatement
- : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
+ : "with" "(" Expression[scope] ")" Statement[code] { $$ = CYNew CYWith($scope, $code); }
;
/* }}} */
/* 13.12 The switch Statement {{{ */
SwitchStatement
- : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
+ : "switch" "(" Expression[value] ")" CaseBlock[clauses] { $$ = CYNew CYSwitch($value, $clauses); }
;
CaseBlock
- : BRACE CaseClausesOpt "}" { $$ = $2; }
+ : "{" CaseClausesOpt[clauses] "}" { $$ = $clauses; }
;
CaseClause
- : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
+ : "case" Expression[value] ":" StatementListOpt[code] { $$ = CYNew CYClause($value, $code); }
;
CaseClausesOpt
- : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
- | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
+ : CaseClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
+ | DefaultClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
| { $$ = NULL; }
;
// XXX: the standard makes certain you can only have one of these
DefaultClause
- : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
+ : "default" ":" StatementListOpt[code] { $$ = CYNew CYClause(NULL, $code); }
;
/* }}} */
/* 13.13 Labelled Statements {{{ */
LabelledStatement
- : LabelIdentifier ":" LabelledItem { $$ = CYNew CYLabel($1, $3); }
+ : LabelIdentifier[name] ":" LabelledItem[statement] { $$ = CYNew CYLabel($name, $statement); }
;
LabelledItem
- : Statement { $$ = $1; }
- | LexSetStatement LexSetRegExp FunctionDeclaration { $$ = $3; }
+ : Statement[pass] { $$ = $pass; }
+ | LexSetStatement LexLet LexOf FunctionDeclaration[pass] { $$ = $pass; }
;
/* }}} */
/* 13.14 The throw Statement {{{ */
-Throw
- : "throw" LexNewLine
- ;
-
ThrowStatement
- : Throw LexSetRegExp TerminatorSoft { CYERR(@1, "throw without exception"); }
- | Throw Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
+ : "throw"[throw] TerminatorSoft { CYERR(@throw, "throw without exception"); }
+ | "throw" NewLineNot Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); }
;
/* }}} */
/* 13.15 The try Statement {{{ */
TryStatement
- : "try" Block Catch { $$ = CYNew cy::Syntax::Try($2, $3, NULL); }
- | "try" Block Finally { $$ = CYNew cy::Syntax::Try($2, NULL, $3); }
- | "try" Block Catch Finally { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
+ : "try" Block[code] Catch[catch] { $$ = CYNew cy::Syntax::Try($code, $catch, NULL); }
+ | "try" Block[code] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, NULL, $finally); }
+ | "try" Block[code] Catch[catch] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, $catch, $finally); }
;
Catch
- : "catch" "(" CatchParameter ")" Block { $$ = CYNew cy::Syntax::Catch($3, $5); }
+ : "catch" "(" LexBind CatchParameter[name] ")" Block[code] { $$ = CYNew cy::Syntax::Catch($name, $code); }
;
Finally
- : "finally" Block { $$ = CYNew CYFinally($2); }
+ : "finally" Block[code] { $$ = CYNew CYFinally($code); }
;
CatchParameter
- : BindingIdentifier { $$ = $1; }
- | BindingPattern { CYNOT(@$); }
+ : BindingIdentifier[pass] { $$ = $pass; }
+ | LexOf BindingPattern { CYNOT(@$); }
;
/* }}} */
/* 13.16 The debugger Statement {{{ */
/* 14.1 Function Definitions {{{ */
FunctionDeclaration
- : ";function" BindingIdentifier "(" FormalParameters ")" BRACE LexPushSuperOff FunctionBody "}" LexPopSuper { $$ = CYNew CYFunctionStatement($2, $4, $8); }
+ : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); }
;
FunctionExpression
- : "function" BindingIdentifierOpt "(" LexPushInOff FormalParameters ")" LexPopIn BRACE LexPushSuperOff LexPushInOff FunctionBody "}" LexPopIn LexPopSuper { $$ = CYNew CYFunctionExpression($2, $5, $11); }
+ : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); }
;
StrictFormalParameters
- : FormalParameters { $$ = $1; }
+ : FormalParameters[pass] { $$ = $pass; }
;
FormalParameters
- : { $$ = NULL; }
+ : LexBind LexOf { $$ = NULL; }
| FormalParameterList
;
FormalParameterList_
- : "," FormalParameterList { $$ = $2; }
+ : "," FormalParameterList[parameters] { $$ = $parameters; }
| { $$ = NULL; }
;
FormalParameterList
: FunctionRestParameter { CYNOT(@$); }
- | FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
+ | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); }
;
FunctionRestParameter
;
FormalParameter
- : BindingElement { $$ = $1; }
+ : BindingElement[pass] { $$ = $pass; }
;
FunctionBody
- : LexPushYieldOff FunctionStatementList LexPopYield { $$ = $2; }
+ : LexPushYieldOff FunctionStatementList[code] LexPopYield { $$ = $code; }
;
FunctionStatementList
- : LexPushReturnOn StatementListOpt LexPopReturn { $$ = $2; }
+ : LexPushReturnOn StatementListOpt[code] LexPopReturn { $$ = $code; }
;
/* }}} */
/* 14.2 Arrow Function Definitions {{{ */
ArrowFunction
- : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
+ : ArrowParameters[parameters] LexNewLineOrOpt "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); }
;
ArrowParameters
- : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
- | CoverParenthesizedExpressionAndArrowParameterList { if ($1 == NULL) $$ = NULL; else { $$ = $1->expression_->Parameter(); if ($$ == NULL) CYERR(@1, "invalid parameter list"); } }
+ : BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); }
+ | LexOf CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } }
;
ConciseBody
- : AssignmentExpression { $$ = CYNew CYReturn($1); }
- | LexSetRegExp ";{" LexPushInOff FunctionBody "}" LexPopIn { $$ = $4; }
+ : AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); }
+ | LexOf ";{" FunctionBody[code] "}" { $$ = $code; }
;
/* }}} */
/* 14.3 Method Definitions {{{ */
MethodDefinition
- : PropertyName "(" StrictFormalParameters ")" BRACE FunctionBody "}" { $$ = CYNew CYPropertyMethod($1, $3, $6); }
- | GeneratorMethod { $$ = $1; }
- | "get" PropertyName "(" ")" BRACE FunctionBody "}" { $$ = CYNew CYPropertyGetter($2, $6); }
- | "set" PropertyName "(" PropertySetParameterList ")" BRACE FunctionBody "}" { $$ = CYNew CYPropertySetter($2, CYNew CYFunctionParameter($4), $7); }
+ : PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); }
+ | GeneratorMethod[pass] { $$ = $pass; }
+ | "get" PropertyName[name] "(" ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); }
+ | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); }
;
PropertySetParameterList
- : FormalParameter { $$ = $1; }
+ : FormalParameter[binding] { $$ = CYNew CYFunctionParameter($binding); }
;
/* }}} */
/* 14.4 Generator Function Definitions {{{ */
GeneratorMethod
- : "*" PropertyName "(" StrictFormalParameters ")" BRACE GeneratorBody "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($2, $4, $7); */ }
+ : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ }
;
GeneratorDeclaration
- : ";function" "*" BindingIdentifier "(" FormalParameters ")" BRACE GeneratorBody "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($3, $5, $8); */ }
+ : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ }
;
GeneratorExpression
- : "function" "*" BindingIdentifierOpt "(" FormalParameters ")" BRACE GeneratorBody "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($3, $5, $8); */ }
+ : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ }
;
GeneratorBody
- : LexPushYieldOn FunctionStatementList LexPopYield { $$ = $2; }
- ;
-
-Yield
- : "!yield" LexNewLine LexNoStar
+ : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; }
;
YieldExpression
- : Yield LexSetRegExp NewLineOpt { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
- | Yield AssignmentExpression { CYNOT(@$); /* $$ = CYNew CYYieldValue($2); */ }
- | Yield LexSetRegExp YieldStar AssignmentExpression { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($4); */ }
+ : "!yield" LexNewLineOrNot "\n" LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
+ | "!yield" LexNewLineOrNot "" LexNoStar LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ } %prec "!yield"
+ | "!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" BindingIdentifier ClassTail { $$ = CYNew CYClassStatement($2, $3); }
+ : ";class" BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); }
;
ClassExpression
- : "class" BindingIdentifierOpt ClassTail { $$ = CYNew CYClassExpression($2, $3); }
+ : "class" BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); }
;
ClassTail
- : ClassHeritageOpt { driver.class_.push($1); } BRACE LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $1; }
+ : ClassHeritageOpt[tail] { driver.class_.push($tail); } "{" LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; }
;
ClassHeritage
- : "extends" LeftHandSideExpression { $$ = CYNew CYClassTail($2); }
+ : "extends" AccessExpression[extends] { $$ = CYNew CYClassTail($extends); }
;
ClassHeritageOpt
- : ClassHeritage { $$ = $1; }
+ : ClassHeritage[pass] { $$ = $pass; }
| { $$ = CYNew CYClassTail(NULL); }
;
;
ClassElement
- : MethodDefinition { if (CYFunctionExpression *constructor = $1->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$1; }
- | "static" MethodDefinition { driver.class_.top()->static_->*$2; }
+ : MethodDefinition[method] { if (CYFunctionExpression *constructor = $method->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$method; }
+ | "static" MethodDefinition[method] { driver.class_.top()->static_->*$method; }
| ";"
;
/* }}} */
/* 15.1 Scripts {{{ */
Script
- : ScriptBodyOpt { driver.script_ = CYNew CYScript($1); }
+ : ScriptBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
;
ScriptBody
- : StatementList { $$ = $1; }
+ : StatementList[pass] { $$ = $pass; }
;
ScriptBodyOpt
- : ScriptBody { $$ = $1; }
- | LexSetStatement LexSetRegExp { $$ = NULL; }
+ : ScriptBody[pass] { $$ = $pass; }
+ | LexSetStatement LexLet LexOf { $$ = NULL; }
;
/* }}} */
/* 15.2 Modules {{{ */
Module
- : ModuleBodyOpt
+ : ModuleBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
;
ModuleBody
- : ModuleItemList
+ : ModuleItemList[pass] { $$ = $pass; }
;
ModuleBodyOpt
- : ModuleBody
- |
+ : ModuleBody[pass] { $$ = $pass; }
+ | LexSetStatement LexLet LexOf { $$ = NULL; }
;
ModuleItemList
- : ModuleItemListOpt ModuleItem
+ : ModuleItem[statement] ModuleItemListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
;
ModuleItemListOpt
- : ModuleItemList
- |
+ : ModuleItemList[pass] { $$ = $pass; }
+ | LexSetStatement LexLet LexOf { $$ = NULL; }
;
ModuleItem
- : LexSetStatement LexSetRegExp ImportDeclaration
- | LexSetStatement LexSetRegExp ExportDeclaration
- | StatementListItem
+ : LexSetStatement LexLet LexOf ImportDeclaration[pass] { $$ = $pass; }
+ | LexSetStatement LexLet LexOf ExportDeclaration { CYNOT(@$); }
+ | StatementListItem[pass] { $$ = $pass; }
;
/* }}} */
/* 15.2.2 Imports {{{ */
ImportDeclaration
- : "import" ImportClause FromClause Terminator
- | "import" ModuleSpecifier Terminator
+ : "import" ImportClause[specifiers] FromClause[module] Terminator { $$ = CYNew CYImportDeclaration($specifiers, $module); }
+ | "import" LexOf ModuleSpecifier[module] Terminator { $$ = CYNew CYImportDeclaration(NULL, $module); }
;
ImportClause
- : ImportedDefaultBinding
- | NameSpaceImport
- | NamedImports
- | ImportedDefaultBinding "," NameSpaceImport
- | ImportedDefaultBinding "," NamedImports
+ : ImportedDefaultBinding[default] { $$ = $default; }
+ | LexOf NameSpaceImport[pass] { $$ = $pass; }
+ | LexOf NamedImports[pass] { $$ = $pass; }
+ | ImportedDefaultBinding[default] "," NameSpaceImport[next] { $$ = $default; CYSetLast($$) = $next; }
+ | ImportedDefaultBinding[default] "," NamedImports[next] { $$ = $default; CYSetLast($$) = $next; }
;
ImportedDefaultBinding
- : ImportedBinding
+ : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(CYNew CYIdentifier("default"), $binding); }
;
NameSpaceImport
- : "*" "as" ImportedBinding
+ : "*" "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(NULL, $binding); }
;
NamedImports
- : BRACE ImportsListOpt "}"
+ : "{" ImportsListOpt[pass] "}" { $$ = $pass; }
;
FromClause
- : "from" ModuleSpecifier
+ : "from" ModuleSpecifier[pass] { $$ = $pass; }
;
ImportsList_
- : "," ImportsListOpt
- |
+ : "," ImportsListOpt[pass] { $$ = $pass; }
+ | { $$ = NULL; }
;
ImportsList
- : ImportSpecifier ImportsList_
+ : ImportSpecifier[import] ImportsList_[next] { $$ = $import; CYSetLast($$) = $next; }
;
ImportsListOpt
- : ImportsList
- |
+ : ImportsList[pass] { $$ = $pass; }
+ | LexOf { $$ = NULL; }
;
ImportSpecifier
- : ImportedBinding
- | IdentifierName "as" ImportedBinding
+ : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($binding, $binding); }
+ | LexOf IdentifierName[name] "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($name, $binding); }
;
ModuleSpecifier
- : StringLiteral
+ : StringLiteral[pass] { $$ = $pass; }
;
ImportedBinding
- : BindingIdentifier
+ : BindingIdentifier[pass] { $$ = $pass; }
;
/* }}} */
/* 15.2.3 Exports {{{ */
| ExportClause FromClause Terminator
| ExportClause Terminator
| VariableStatement
- | "default" LexSetStatement LexSetRegExp HoistableDeclaration
- | "default" LexSetStatement LexSetRegExp ClassDeclaration
+ | "default" LexSetStatement LexOf HoistableDeclaration
+ | "default" LexSetStatement LexOf ClassDeclaration
| "default" LexSetStatement AssignmentExpression Terminator
;
ExportDeclaration
- : "export" LexSetStatement LexSetRegExp ExportDeclaration_
+ : "export" LexSetStatement LexLet LexOf ExportDeclaration_
| "export" Declaration
;
@begin C
/* Cycript (C): Type Encoding {{{ */
TypeSignifier
- : IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); }
- | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; }
+ : IdentifierType[name] { $$ = CYNew CYTypedName(@name, $name); }
+ | StringLiteral[name] { $$ = CYNew CYTypedName(@name, $name); }
+ | NumericLiteral[name] { $$ = CYNew CYTypedName(@name, $name); }
+ | "(" "*" TypeQualifierRightOpt[typed] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
+ ;
+
+TypeSignifierNone
+ : { $$ = CYNew CYTypedName(@$); }
+ ;
+
+TypeSignifierOpt
+ : TypeSignifier[pass] { $$ = $pass; }
+ | TypeSignifierNone[pass] { $$ = $pass; }
+ ;
+
+Restrict
+ : "__restrict"
+ | "restrict"
+ ;
+
+RestrictOpt
+ : Restrict
+ |
+ ;
+
+ParameterModifier
+ : "throw" "(" ")"
+ ;
+
+ParameterModifierOpt
+ : ParameterModifier
+ |
+ ;
+
+ParameterTail
+ : TypedParameterListOpt[formal] ")" ParameterModifierOpt { $$ = CYNew CYTypeFunctionWith($formal->variadic_, $formal->parameters_); }
;
SuffixedType
- : SuffixedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
- | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
- | TypeSignifier "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($4, $$->modifier_); }
- | "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); }
- | TypeSignifier { $$ = $1; }
- | { $$ = CYNew CYTypedIdentifier(@$); }
+ : SuffixedTypeOpt[typed] "[" RestrictOpt NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); }
+ | "(" "^" TypeQualifierRightOpt[typed] ")" "(" TypedParameters[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); }
+ | TypeSignifier[typed] "(" ParameterTail[modifier] { $$ = $typed; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
+ | "("[parenthesis] ParameterTail[modifier] { $$ = CYNew CYTypedName(@parenthesis); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
+ ;
+
+SuffixedTypeOpt
+ : SuffixedType[pass] { $$ = $pass; }
+ | TypeSignifierOpt[pass] { $$ = $pass; }
;
PrefixedType
- : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
+ : "*" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
;
TypeQualifierLeft
- : { $$ = NULL; }
- | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
- | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); }
+ : "const" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); }
+ | "volatile" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); }
+ ;
+
+TypeQualifierLeftOpt
+ : TypeQualifierLeft[pass] { $$ = $pass; }
+ | { $$ = NULL; }
;
TypeQualifierRight
- : PrefixedType { $$ = $1; }
- | SuffixedType { $$ = $1; }
- | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
- | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
+ : SuffixedType[pass] { $$ = $pass; }
+ | PrefixedType[pass] { $$ = $pass; }
+ | "const" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
+ | "volatile" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
+ | Restrict TypeQualifierRightOpt[typed] { $$ = $typed; }
+ ;
+
+TypeQualifierRightOpt
+ : TypeQualifierRight[pass] { $$ = $pass; }
+ | TypeSignifierOpt[pass] { $$ = $pass; }
;
IntegerType
- : "int" { $$ = CYNew CYTypeVariable("int"); }
- | "unsigned" IntegerTypeOpt { $$ = CYNew CYTypeUnsigned($2); }
- | "signed" IntegerTypeOpt { $$ = CYNew CYTypeSigned($2); }
- | "long" IntegerTypeOpt { $$ = CYNew CYTypeLong($2); }
- | "short" IntegerTypeOpt { $$ = CYNew CYTypeShort($2); }
+ : "int" { $$ = CYNew CYTypeIntegral(CYTypeNeutral); }
+ | "unsigned" IntegerTypeOpt[integral] { $$ = $integral->Unsigned(); if ($$ == NULL) CYERR(@1, "incompatible unsigned"); }
+ | "signed" IntegerTypeOpt[integral] { $$ = $integral->Signed(); if ($$ == NULL) CYERR(@1, "incompatible signed"); }
+ | "long" IntegerTypeOpt[integral] { $$ = $integral->Long(); if ($$ == NULL) CYERR(@1, "incompatible long"); }
+ | "short" IntegerTypeOpt[integral] { $$ = $integral->Short(); if ($$ == NULL) CYERR(@1, "incompatible short"); }
;
IntegerTypeOpt
- : IntegerType { $$ = $1; }
- | { $$ = CYNew CYTypeVariable("int"); }
+ : IntegerType[pass] { $$ = $pass; }
+ | { $$ = CYNew CYTypeIntegral(CYTypeNeutral); }
+ ;
+
+StructFieldListOpt
+ : TypedIdentifierField[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $typed->name_, $next); }
+ | { $$ = NULL; }
+ ;
+
+IntegerNumber
+ : NumericLiteral[pass] { $$ = $pass; }
+ | "-" NumericLiteral[positive] { $$ = $positive; $$->value_ = -$$->value_; }
+ ;
+
+EnumConstantListOpt_
+ : "," EnumConstantListOpt[pass] { $$ = $pass; }
+ | { $$ = NULL; }
+ ;
+
+EnumConstantListOpt
+ : IdentifierType[name] "=" IntegerNumber[value] EnumConstantListOpt_[next] { $$ = CYNew CYEnumConstant($name, $value, $next); }
+ | { $$ = NULL; }
+ ;
+
+TypeSigning
+ : { $$ = CYTypeNeutral; }
+ | "signed" { $$ = CYTypeSigned; }
+ | "unsigned" { $$ = CYTypeUnsigned; }
;
PrimitiveType
- : IdentifierType { $$ = CYNew CYTypeVariable($1); }
- | IntegerType { $$ = $1; }
- | "void" { $$ = CYNew CYTypeVoid(); }
- | "char" { $$ = CYNew CYTypeVariable("char"); }
- | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
- | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
+ : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); }
+ | IntegerType[pass] { $$ = $pass; }
+ | TypeSigning[signing] "char" { $$ = CYNew CYTypeCharacter($signing); }
+ | TypeSigning[signing] "__int128" { $$ = CYNew CYTypeInt128($signing); }
;
-TypedIdentifier
- : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
+PrimitiveReference
+ : PrimitiveType[pass] { $$ = $pass; }
+ | "struct" IdentifierType[name] { $$ = CYNew CYTypeReference(CYTypeReferenceStruct, $name); }
+ | "enum" IdentifierType[name] { $$ = CYNew CYTypeReference(CYTypeReferenceEnum, $name); }
+ | "struct" AutoComplete { driver.mode_ = CYDriver::AutoStruct; YYACCEPT; }
+ | "enum" AutoComplete { driver.mode_ = CYDriver::AutoEnum; YYACCEPT; }
+ ;
+
+TypedIdentifierMaybe
+ : TypeQualifierLeft[modifier] "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
+ | "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); }
+ | TypeQualifierLeftOpt[modifier] PrimitiveReference[specifier] TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
+ ;
+
+TypedIdentifierYes
+ : TypedIdentifierMaybe[typed] { if ($typed->name_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; }
+ ;
+
+TypedIdentifierNo
+ : TypedIdentifierMaybe[typed] { if ($typed->name_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; }
+ ;
+
+TypedIdentifierTagged
+ : TypeQualifierLeftOpt[modifier] "struct" "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeStruct(NULL, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
+ | TypeQualifierLeftOpt[modifier] "enum" ":" PrimitiveType[specifier] "{" EnumConstantListOpt[constants] "}" TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeEnum(NULL, $specifier, $constants); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
+ ;
+
+TypedIdentifierField
+ : TypedIdentifierYes[pass] { $$ = $pass; }
+ | TypedIdentifierTagged[typed] { if ($typed->name_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; }
+ ;
+
+TypedIdentifierEncoding
+ : TypedIdentifierNo[pass] { $$ = $pass; }
+ | TypedIdentifierTagged[typed] { if ($typed->name_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; }
+ | "void" TypeSignifierNone[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); }
+ ;
+
+TypedIdentifierDefinition
+ : TypedIdentifierYes[pass] { $$ = $pass; }
+ | TypeQualifierLeftOpt[modifier] "struct" IdentifierTypeOpt[name] "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { if ($typed->name_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; $$->specifier_ = CYNew CYTypeStruct($name, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
+ | "void" TypeSignifier[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); }
;
PrimaryExpression
- : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); }
+ : "@encode" "(" TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYEncodedType($typed); }
;
/* }}} */
@end
/* Cycript (Objective-C): @class Declaration {{{ */
ClassSuperOpt
/* XXX: why the hell did I choose MemberExpression? */
- : ":" LexSetRegExp MemberExpression { $$ = $3; }
+ : ":" MemberExpression[extends] { $$ = $extends; }
| { $$ = NULL; }
;
ImplementationFieldListOpt
- : LexSetRegExp TypedIdentifier ";" ImplementationFieldListOpt { $$ = CYNew CYImplementationField($2, $4); }
- | LexSetRegExp { $$ = NULL; }
- ;
-
-ImplementationFields
- : BRACE ImplementationFieldListOpt "}" { $$ = $2; }
+ : TypedIdentifierField[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $typed->name_, $next); }
+ | { $$ = NULL; }
;
MessageScope
;
TypeOpt
- : "(" LexSetRegExp TypedIdentifier ")" { if ($3->identifier_ != NULL) CYERR($3->location_, "unexpected identifier"); $$ = $3; }
- | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
+ : "(" TypedIdentifierNo[type] ")" { $$ = $type; }
+ | { $$ = CYNew CYType(CYNew CYTypeVariable("id")); }
;
MessageParameter
- : Word ":" TypeOpt Identifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); }
+ : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $$ = CYNew CYMessageParameter($tag, $type, $identifier); }
;
MessageParameterList
- : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
+ : MessageParameter[parameter] MessageParameterListOpt[next] { $parameter->SetNext($next); $$ = $parameter; }
;
MessageParameterListOpt
- : MessageParameterList { $$ = $1; }
- | { $$ = NULL; }
+ : MessageParameterList[pass] { $$ = $pass; }
+ | TypedParameterList_[formal] { if ($formal->variadic_) CYERR(@$, "unsupported variadic"); /*XXX*/ if ($formal->parameters_ != NULL) CYERR(@$, "temporarily unsupported"); $$ = NULL; }
;
MessageParameters
- : MessageParameterList { $$ = $1; }
- | Word { $$ = CYNew CYMessageParameter($1, NULL); }
+ : MessageParameterList[pass] { $$ = $pass; }
+ | Word[tag] { $$ = CYNew CYMessageParameter($tag); }
;
ClassMessageDeclaration
- : MessageScope TypeOpt MessageParameters BRACE LexPushSuperOn FunctionBody "}" LexPopSuper { $$ = CYNew CYMessage($1, $2, $3, $6); }
+ : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] "{" LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); }
;
ClassMessageDeclarationListOpt
- : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
+ : ClassMessageDeclarationListOpt[next] ClassMessageDeclaration[message] { $message->SetNext($next); $$ = $message; }
| { $$ = NULL; }
;
// XXX: this should be AssignmentExpressionNoRight
ClassProtocols
- : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
+ : ShiftExpression[name] ClassProtocolsOpt[next] { $$ = CYNew CYProtocol($name, $next); }
;
ClassProtocolsOpt
- : "," ClassProtocols { $$ = $2; }
+ : "," ClassProtocols[protocols] { $$ = $protocols; }
| { $$ = NULL; }
;
ClassProtocolListOpt
- : "<" ClassProtocols ">" { $$ = $2; }
+ : "<" ClassProtocols[protocols] ">" { $$ = $protocols; }
| { $$ = NULL; }
;
ImplementationStatement
- : "@implementation" Identifier ClassSuperOpt ClassProtocolListOpt ImplementationFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYImplementation($2, $3, $4, $5, $6); }
+ : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] "{" ImplementationFieldListOpt[fields] "}" ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); }
;
CategoryName
;
CategoryStatement
- : "@implementation" Identifier CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
+ : "@implementation" Identifier[name] CategoryName ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYCategory($name, $messages); }
;
Statement__
- : ImplementationStatement { $$ = $1; }
- | CategoryStatement { $$ = $1; }
+ : ImplementationStatement[pass] { $$ = $pass; }
+ | CategoryStatement[pass] { $$ = $pass; }
;
/* }}} */
/* Cycript (Objective-C): Send Message {{{ */
VariadicCall
- : "," AssignmentExpressionClassic VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
+ : "," AssignmentExpressionClassic[value] VariadicCall[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
| { $$ = NULL; }
;
SelectorWordOpt
- : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
+ : WordOpt[name] { driver.contexts_.back().words_.push_back($name); } { $$ = $name; }
| AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
;
SelectorCall_
- : SelectorCall { $$ = $1; }
- | VariadicCall { $$ = $1; }
+ : SelectorCall[pass] { $$ = $pass; }
+ | VariadicCall[pass] { $$ = $pass; }
;
SelectorCall
- : SelectorWordOpt ":" AssignmentExpressionClassic SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); }
+ : SelectorWordOpt[name] ":" AssignmentExpressionClassic[value] SelectorCall_[next] { $$ = CYNew CYArgument($name ?: CYNew CYWord(""), $value, $next); }
;
SelectorList
- : SelectorCall { $$ = $1; }
- | Word { $$ = CYNew CYArgument($1, NULL); }
+ : SelectorCall[pass] { $$ = $pass; }
+ | Word[name] { $$ = CYNew CYArgument($name, NULL); }
;
MessageExpression
- : "[" LexPushInOff AssignmentExpressionClassic { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
- | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" LexPopIn { $$ = CYNew CYSendSuper($6); }
+ : "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); }
+ | "[" LexOf "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); }
;
SelectorExpression_
- : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
+ : WordOpt[name] ":" SelectorExpressionOpt[next] { $$ = CYNew CYSelectorPart($name, true, $next); }
;
SelectorExpression
- : SelectorExpression_ { $$ = $1; }
- | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
+ : SelectorExpression_[pass] { $$ = $pass; }
+ | Word[name] { $$ = CYNew CYSelectorPart($name, false, NULL); }
;
SelectorExpressionOpt
- : SelectorExpression_ { $$ = $1; }
+ : SelectorExpression_[pass] { $$ = $pass; }
| { $$ = NULL; }
;
PrimaryExpression
- : MessageExpression { $$ = $1; }
- | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); }
+ : MessageExpression[pass] { $$ = $pass; }
+ | "@selector" "(" SelectorExpression[parts] ")" { $$ = CYNew CYSelector($parts); }
;
/* }}} */
@end
/* Cycript: @import Directive {{{ */
ModulePath
- : ModulePath "." Word { $$ = CYNew CYModule($3, $1); }
- | Word { $$ = CYNew CYModule($1); }
+ : ModulePath[next] "." Word[part] { $$ = CYNew CYModule($part, $next); }
+ | Word[part] { $$ = CYNew CYModule($part); }
;
-Declaration__
- : "@import" ModulePath { $$ = CYNew CYImport($2); }
+Declaration_
+ : "@import" ModulePath[path] { $$ = CYNew CYImport($path); }
;
/* }}} */
@begin ObjectiveC
/* Cycript (Objective-C): Boxed Expressions {{{ */
BoxableExpression
- : NullLiteral { $$ = $1; }
- | BooleanLiteral { $$ = $1; }
- | NumericLiteral { $$ = $1; }
- | StringLiteral { $$ = $1; }
- | ArrayLiteral { $$ = $1; }
- | ObjectLiteral { $$ = $1; }
- | CoverParenthesizedExpressionAndArrowParameterList { $$ = $1; }
+ : NullLiteral[pass] { $$ = $pass; }
+ | BooleanLiteral[pass] { $$ = $pass; }
+ | NumericLiteral[pass] { $$ = $pass; }
+ | StringLiteral[pass] { $$ = $pass; }
+ | CoverParenthesizedExpressionAndArrowParameterList[pass] { $$ = $pass; }
| "YES" { $$ = CYNew CYTrue(); }
| "NO" { $$ = CYNew CYFalse(); }
;
+KeyValuePairList_
+ : "," KeyValuePairListOpt[next] { $$ = $next; }
+ | { $$ = NULL; }
+
+KeyValuePairList
+ : AssignmentExpression[key] ":" AssignmentExpression[value] KeyValuePairList_[next] { $$ = CYNew CYObjCKeyValue($key, $value, $next); }
+ ;
+
+KeyValuePairListOpt
+ : KeyValuePairList[pass] { $$ = $pass; }
+ | LexOf { $$ = NULL; }
+ ;
+
PrimaryExpression
- : "@" BoxableExpression { $$ = CYNew CYBox($2); }
+ : "@" BoxableExpression[expression] { $$ = CYNew CYBox($expression); }
+ | "@" "[" ElementListOpt[elements] "]" { $$ = CYNew CYObjCArray($elements); }
+ | "@" "{" KeyValuePairListOpt[pairs] "}" { $$ = CYNew CYObjCDictionary($pairs); }
+
| "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
| "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
| "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
/* }}} */
/* Cycript (Objective-C): Block Expressions {{{ */
PrimaryExpression
- : "^" TypedIdentifier { if ($2->identifier_ != NULL) CYERR($2->location_, "unexpected identifier"); } BRACE LexPushInOff FunctionBody "}" LexPopIn { if (CYTypeFunctionWith *function = $2->Function()) $$ = CYNew CYObjCBlock($2, function->parameters_, $6); else CYERR($2->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 {{{ */
PrimaryExpression
- : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); }
+ : "#" NumericLiteral[address] { $$ = CYNew CYInstanceLiteral($address); }
;
/* }}} */
@end
@begin C
/* Cycript (C): Pointer Indirection/Addressing {{{ */
-LeftHandSideExpression
- : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
+UnaryExpression_
+ : IndirectExpression[pass] { $$ = $pass; }
+ ;
+
+IndirectExpression
+ : "*" UnaryExpression[rhs] { $$ = CYNew CYIndirect($rhs); }
;
UnaryExpression_
- : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
+ : "&" UnaryExpression[rhs] { $$ = CYNew CYAddressOf($rhs); }
;
MemberAccess
- : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
- | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
+ : "->" "[" Expression[property] "]" { $$ = CYNew CYIndirectMember(NULL, $property); }
+ | "->" IdentifierName[property] { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($property)); }
| "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
;
/* }}} */
-/* Cycript (C): auto Compatibility {{{ */
-Var_
- : "auto"
- ;
-/* }}} */
/* Cycript (C): Lambda Expressions {{{ */
TypedParameterList_
- : "," TypedParameterList { $$ = $2; }
- | { $$ = NULL; }
+ : "," TypedParameterList[parameters] { $$ = $parameters; }
+ | { $$ = CYNew CYTypedFormal(false); }
;
TypedParameterList
- : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
+ : TypedIdentifierMaybe[typed] TypedParameterList_[formal] { CYIdentifier *identifier; if ($typed->name_ == NULL) identifier = NULL; else { identifier = $typed->name_->Identifier(); if (identifier == NULL) CYERR($typed->location_, "invalid identifier"); } $$ = $formal; $$->parameters_ = CYNew CYTypedParameter($typed, identifier, $$->parameters_); }
+ | "..." { $$ = CYNew CYTypedFormal(true); }
;
TypedParameterListOpt
- : TypedParameterList { $$ = $1; }
- | { $$ = NULL; }
+ : TypedParameterList[pass] { $$ = $pass; }
+ | "void" { $$ = CYNew CYTypedFormal(false); }
+ | { $$ = CYNew CYTypedFormal(false); }
+ ;
+
+TypedParameters
+ : TypedParameterListOpt[formal] { if ($formal->variadic_) CYERR(@$, "unsupported variadic"); $$ = $formal->parameters_; }
+ ;
+
+PrimaryExpression
+ : "[" LexOf "&" "]" "(" TypedParameters[parameters] ")" "->" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
+ ;
+/* }}} */
+/* Cycript (C): Structure Definitions {{{ */
+IdentifierNoOf
+ : "struct" NewLineOpt { $$ = CYNew CYIdentifier("struct"); }
+ ;
+
+Statement__
+ : "struct" NewLineNot IdentifierType[name] "{" StructFieldListOpt[fields] "}" { $$ = CYNew CYStructDefinition($name, CYNew CYStructTail($fields)); }
;
PrimaryExpression
- : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
+ : "(" LexOf "struct" NewLineOpt IdentifierType[name] TypeQualifierRightOpt[typed] ")" { $typed->specifier_ = CYNew CYTypeReference(CYTypeReferenceStruct, $name); $$ = CYNew CYTypeExpression($typed); }
+ | "(" LexOf "struct" NewLineOpt AutoComplete { driver.mode_ = CYDriver::AutoStruct; YYACCEPT; }
;
/* }}} */
/* Cycript (C): Type Definitions {{{ */
+IdentifierNoOf
+ : "typedef" NewLineOpt { $$ = CYNew CYIdentifier("typedef"); }
+ ;
+
+TypeDefinition
+ : "typedef" NewLineNot TypedIdentifierDefinition[typed] TerminatorHard { CYIdentifier *identifier; if ($typed->name_ == NULL) identifier = NULL; else { identifier = $typed->name_->Identifier(); if (identifier == NULL) CYERR($typed->location_, "invalid identifier"); } $$ = CYNew CYTypeDefinition($typed, identifier); }
+ ;
+
Statement__
- : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) CYERR($2->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($2); }
+ : TypeDefinition[pass] { $$ = $pass; }
+ ;
+
+PrimaryExpression
+ : "(" LexOf "typedef" NewLineOpt TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYTypeExpression($typed); }
;
/* }}} */
/* Cycript (C): extern "C" {{{ */
+IdentifierNoOf
+ : "extern" NewLineOpt { $$ = CYNew CYIdentifier("extern"); }
+ ;
+
+ExternCStatement
+ : TypedIdentifierField[typed] TerminatorHard { CYIdentifier *identifier; if ($typed->name_ == NULL) identifier = NULL; else { identifier = $typed->name_->Identifier(); if (identifier == NULL) CYERR($typed->location_, "invalid identifier"); } $$ = CYNew CYExternalDefinition(CYNew CYString("C"), $typed, identifier); }
+ | TypeDefinition[pass] { $$ = $pass; }
+ ;
+
+ExternCStatementListOpt
+ : ExternCStatement[statement] ExternCStatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
+ | { $$ = NULL; }
+ ;
+
+ExternC
+ : "{" ExternCStatementListOpt[pass] "}" { $$ = $pass; }
+ | ExternCStatement[pass] { $$ = $pass; }
+ ;
+
+ABI
+ : StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); }
+ ;
+
Statement__
- : "extern" StringLiteral { if (strcmp($2->Value(), "C") != 0) CYERR(@2, "unknown extern binding"); } TypedIdentifier { if ($4->identifier_ == NULL) CYERR($4->location_, "expected identifier"); } Terminator { $$ = CYNew CYExternal($2, $4); }
+ : "extern" NewLineNot ABI[abi] ExternC[pass] { $$ = $pass; }
;
-/* }}} */
+PrimaryExpression
+ : "(" LexOf "extern" NewLineOpt ABI[abi] TypedIdentifierField[typed] ")" { $$ = CYNew CYExternalExpression(CYNew CYString("C"), $typed, $typed->name_); }
+ ;
+/* }}} */
@end
@begin E4X
/* 11.1 Primary Expressions {{{ */
PrimaryExpression
: PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
- | XMLInitialiser { $$ = $1; }
- | XMLListInitialiser { $$ = $1; }
+ | XMLInitilizer { $$ = $1; }
+ | XMLListInitilizer { $$ = $1; }
;
PropertyIdentifier
PropertySelector_
: PropertySelector { $$ = $1; }
- | "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYSelector($3); }
+ | "[" Expression "]" { $$ = CYNew CYSelector($2); }
;
PropertySelector
;
/* }}} */
/* 11.1.4 XML Initializer {{{ */
-XMLInitialiser
+XMLInitilizer
: XMLMarkup { $$ = $1; }
| XMLElement { $$ = $1; }
;
;
XMLExpression
- : BRACE LexPushRegExp Expression LexPop "}"
+ : "{" LexPushRegExp Expression LexPop "}"
;
XMLTagName
;
/* }}} */
/* 11.1.5 XMLList Initializer {{{ */
-XMLListInitialiser
+XMLListInitilizer
: "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
;
/* }}} */
/* JavaScript FTL: Array Comprehensions {{{ */
Comprehension
- : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); }
+ : AssignmentExpression[expression] ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
;
ComprehensionFor
- : "for" "each" "(" LexPushInOn LexicalBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($5, $8); }
+ : "for" "each" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
;
/* }}} */
/* JavaScript FTL: for each {{{ */
IterationStatement
- : "for" "each" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
+ : "for" "each" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
;
/* }}} */
;
ArrayComprehension
- : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; }
+ : "[" Comprehension[comprehension] "]" { $$ = $comprehension; }
;
Comprehension
- : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); }
+ : LexOf ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
;
ComprehensionTail
: { $$ = NULL; }
- | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); }
- | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); }
+ | ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
+ | ComprehensionIf[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
;
ComprehensionFor
- : "for" "(" LexPushInOn ForBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForInComprehension($4, $7); }
- | "for" "(" LexPushInOn ForBinding "of" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($4, $7); }
+ : "for" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForInComprehension($binding, $iterable); }
+ | "for" "(" LexPushInOn LexBind ForBinding[binding] "of" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
;
ComprehensionIf
- : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); }
- ;
-/* }}} */
-/* JavaScript FTW: Coalesce Operator {{{ */
-ConditionalExpression
- : LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); }
+ : "if" "(" AssignmentExpression[test] ")" { $$ = CYNew CYIfComprehension($test); }
;
/* }}} */
/* JavaScript FTW: Named Arguments {{{ */
ArgumentList
- : LexSetRegExp Word ":" AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument($2, $4, $5); }
+ : LexOf WordNoUnary[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); }
;
/* }}} */
+/* JavaScript FTW: Subscript Access {{{ */
+MemberAccess
+ : "." "[" AssignmentExpression[property] "]" { $$ = CYNew CYSubscriptMember(NULL, $property); }
+ ;
+/* }}} */
+
+/* JavaScript FTW: Java "Anonymous Inner Classes" {{{ */
+BracedParameter
+ : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYExtend(NULL, $properties); }
+ ;
+/* }}} */
+
/* JavaScript FTW: Ruby Blocks {{{ */
RubyProcParameterList_
- : "," RubyProcParameterList { $$ = $2; }
+ : "," RubyProcParameterList[parameters] { $$ = $parameters; }
| { $$ = NULL; }
;
RubyProcParameterList
- : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
- | { $$ = NULL; }
+ : BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); }
+ | LexOf { $$ = NULL; }
;
RubyProcParameters
- : LexSetRegExp "|" RubyProcParameterList "|" { $$ = $3; }
- | LexSetRegExp "||" { $$ = NULL; }
+ : "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; }
+ | "||" { $$ = NULL; }
;
RubyProcParametersOpt
- : RubyProcParameters { $$ = $1; }
- | LexSetRegExp { $$ = NULL; }
+ : RubyProcParameters[pass] { $$ = $pass; }
+ | { $$ = NULL; }
;
-RubyProcExpression
- : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
+BracedParameter
+ : ";{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyBlock(NULL, CYNew CYRubyProc($parameters, $code)); }
;
PrimaryExpression
- : BRACE LexPushInOff RubyProcParameters StatementListOpt "}" LexPopIn { $$ = CYNew CYRubyProc($3, $4); }
+ : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
;
-PostfixExpression
- : PostfixExpression RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }
+BracedExpression_
+ : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
+ | BracedExpression_[lhs] { if (!$lhs->IsNew()) CYMAP(OpenBrace_, OpenBrace); } BracedParameter[rhs] LexNewLineOrOpt { $rhs->SetLeft($lhs); $$ = $rhs; }
+ ;
+
+BracedExpression
+ : BracedExpression_[pass] "\n" { $$ = $pass; }
+ | BracedExpression_[pass] { $$ = $pass; }
+ ;
+/* }}} */
+/* JavaScript FTW: Ruby Scopes {{{ */
+MemberAccess
+ : "::" "[" Expression[property] "]" { $$ = CYNew CYResolveMember(NULL, $property); }
+ | "::" IdentifierName[property] { $$ = CYNew CYResolveMember(NULL, CYNew CYString($property)); }
+ | "::" AutoComplete { driver.mode_ = CYDriver::AutoResolve; YYACCEPT; }
+ ;
+/* }}} */
+/* JavaScript FTW: Ruby Symbols {{{ */
+PrimaryExpression
+ : ":" Word[name] { $$ = CYNew CYSymbol($name->Word()); }
;
/* }}} */