X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/484bab66e94c8bf2c01534ad3cab752ad3a366f0..2c4a8bb6222b88ff96fbf25372179646ce15f706:/Parser.ypp.in diff --git a/Parser.ypp.in b/Parser.ypp.in index 148d2d0..c076967 100644 --- a/Parser.ypp.in +++ b/Parser.ypp.in @@ -1,5 +1,5 @@ -/* 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 {{{ */ @@ -27,6 +27,7 @@ #include "Driver.hpp" #include "Parser.hpp" #include "Stack.hpp" +#include "Syntax.hpp" #define CYNew new(driver.pool_) @begin ObjectiveC @@ -48,11 +49,13 @@ %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 { CYElement *element_; } +%union { CYEnumConstant *constant_; } %union { CYExpression *expression_; } %union { CYFalse *false_; } %union { CYVariable *variable_; } @@ -61,6 +64,7 @@ %union { CYForInInitializer *forin_; } %union { CYFunctionParameter *functionParameter_; } %union { CYIdentifier *identifier_; } +%union { CYImportSpecifier *import_; } %union { CYInfix *infix_; } %union { CYLiteral *literal_; } %union { CYMethod *method_; } @@ -70,7 +74,7 @@ %union { CYParenthetical *parenthetical_; } %union { CYProperty *property_; } %union { CYPropertyName *propertyName_; } -%union { CYRubyProc *rubyProc_; } +%union { CYTypeSigning signing_; } %union { CYSpan *span_; } %union { CYStatement *statement_; } %union { CYString *string_; } @@ -80,16 +84,22 @@ %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 @@ -113,25 +123,13 @@ int cylex(YYSTYPE *, CYLocation *, void *); %code { -typedef cy::parser::token tk; - #undef yylex -_finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) { - if (driver.mark_ == CYMarkIgnore); - else if (driver.mark_ == CYMarkScript) { - driver.mark_ = CYMarkIgnore; - return cy::parser::token::MarkScript; - } else if (driver.mark_ == CYMarkModule) { - driver.mark_ = CYMarkIgnore; - return cy::parser::token::MarkModule; - } - lex: - if (driver.newline_ == CYDriver::NewLineHere) - driver.newline_ = CYDriver::NewLineLast; - else if (driver.newline_ == CYDriver::NewLineLast) - driver.newline_ = CYDriver::NewLineNone; +typedef cy::parser::token tk; +_finline int cylex_(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) { + driver.newline_ = false; + lex: YYSTYPE data; int token(cylex(&data, location, driver.scanner_)); *semantic = data.semantic_; @@ -161,19 +159,27 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY break; case tk::NewLine: - driver.newline_ = CYDriver::NewLineHere; - if (!driver.next_) - goto lex; + driver.newline_ = true; + goto lex; break; } - driver.next_ = false; return token; } +#define yylex_(semantic, location, driver) ({ \ + int type; \ + if (driver.hold_ == cy::parser::empty_symbol) \ + type = yytranslate_(cylex_(semantic, location, driver)); \ + else { \ + type = driver.hold_; \ + driver.hold_ = cy::parser::empty_symbol; \ + } \ +type; }) + #define CYLEX() do if (yyla.empty()) { \ YYCDEBUG << "Mapping a token: "; \ - yyla.type = yytranslate_(yylex(&yyla.value, &yyla.location, driver)); \ + yyla.type = yylex_(&yyla.value, &yyla.location, driver); \ YY_SYMBOL_PRINT("Next token is", yyla); \ } while (false) @@ -183,10 +189,11 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY yyla.type = yytranslate_(token::to); \ } while (false) -#define CYLIN(from) do { \ - CYLEX(); \ - if (yyla.type == yytranslate_(token::from) && driver.newline_ == CYDriver::NewLineLast) \ - yyla.type = yytranslate_(token::from ## _); \ +#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 { \ @@ -215,6 +222,18 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, 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 @@ -249,13 +268,11 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token SlashRight "/>" %token LeftSlash "" -%token EqualRight_ "\n=>" %token Exclamation "!" %token ExclamationEqual "!=" %token ExclamationEqualEqual "!==" %token Hyphen "-" %token HyphenEqual "-=" %token HyphenHyphen "--" -%token HyphenHyphen_ "\n--" %token HyphenRight "->" %token Left "<" %token LeftEqual "<=" @@ -290,7 +305,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token Plus "+" %token PlusEqual "+=" %token PlusPlus "++" -%token PlusPlus_ "\n++" +%token QuestionPeriod "?." %token Right ">" %token RightEqual ">=" %token RightRight ">>" @@ -304,10 +319,13 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token Tilde "~" %token Colon ":" +%token ColonColon "::" %token Comma "," %token Question "?" %token SemiColon ";" +%token Pound "#" %token NewLine "\n" +%token __ "" %token Comment @@ -315,8 +333,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token CloseParen ")" %token OpenBrace "{" -%token OpenBrace_ "\n{" -%token OpenBrace__ ";{" +%token OpenBrace_ ";{" %token OpenBrace_let "let {" %token CloseBrace "}" @@ -334,6 +351,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token _typedef_ "typedef" %token _unsigned_ "unsigned" %token _signed_ "signed" +%token _struct_ "struct" %token _extern_ "extern" @end @@ -359,6 +377,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token _null_ "null" %token _true_ "true" +%token _as_ "as" %token _break_ "break" %token _case_ "case" %token _catch_ "catch" @@ -413,6 +432,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token _goto_ "goto" %token _implements_ "implements" %token _int_ "int" +%token ___int128_ "__int128" %token _interface_ "interface" %token _let_ "let" %token _let__ "!let" @@ -421,6 +441,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token _package_ "package" %token _private_ "private" %token _protected_ "protected" +%token ___proto___ "__proto__" %token _prototype_ "prototype" %token _public_ "public" %token _set_ "set" @@ -429,6 +450,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token _synchronized_ "synchronized" %token _throws_ "throws" %token _transient_ "transient" +%token _typeid_ "typeid" %token _volatile_ "volatile" %token _yield_ "yield" %token _yield__ "!yield" @@ -444,7 +466,6 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token _SEL_ "SEL" @end -%token _auto_ "auto" %token _each_ "each" %token _of_ "of" %token _of__ "!of" @@ -455,7 +476,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY @end %token AutoComplete -%token YieldStar +%token YieldStar "yield *" %token Identifier_ %token NumericLiteral @@ -474,11 +495,11 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type ArgumentListOpt %type Arguments %type ArrayComprehension +%type ArrayElement %type ArrayLiteral %type ArrowFunction %type ArrowParameters %type AssignmentExpression -%type AssignmentExpressionOpt %type BindingIdentifier %type BindingIdentifierOpt %type BindingList_ @@ -490,6 +511,8 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type BindingElement %type BitwiseORExpression %type BitwiseXORExpression +%type BracedExpression_ +%type BracedExpression %type BreakStatement %type BreakableStatement %type CallExpression_ @@ -517,6 +540,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type Declaration_ %type Declaration %type DefaultClause +%type ElementList_ %type ElementList %type ElementListOpt %type ElseStatementOpt @@ -526,6 +550,9 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type ExpressionOpt %type ExpressionStatement_ %type ExpressionStatement +%type ExternC +%type ExternCStatement +%type ExternCStatementListOpt %type Finally %type ForBinding %type ForDeclaration @@ -535,6 +562,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type FormalParameterList_ %type FormalParameterList %type FormalParameters +%type FromClause %type FunctionBody %type FunctionDeclaration %type FunctionExpression @@ -548,9 +576,18 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type IdentifierNoOf %type IdentifierType %type IdentifierTypeNoOf +%type IdentifierTypeOpt %type IdentifierName %type IdentifierReference %type IfStatement +%type ImportClause +%type ImportDeclaration +%type ImportSpecifier +%type ImportedBinding +%type ImportedDefaultBinding +%type ImportsList_ +%type ImportsList +%type ImportsListOpt %type IndirectExpression %type Initializer %type InitializerOpt @@ -571,8 +608,16 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type MemberAccess %type MemberExpression %type MethodDefinition +%type ModuleBody +%type ModuleBodyOpt +%type ModuleItem +%type ModuleItemList +%type ModuleItemListOpt %type ModulePath +%type ModuleSpecifier %type MultiplicativeExpression +%type NameSpaceImport +%type NamedImports %type NewExpression %type NullLiteral %type ObjectLiteral @@ -588,7 +633,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type RegularExpressionSlash %type RelationalExpression %type ReturnStatement -%type RubyProcExpression +%type BracedParameter %type RubyProcParameterList_ %type RubyProcParameterList %type RubyProcParameters @@ -612,6 +657,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type TemplateSpans %type ThrowStatement %type TryStatement +%type TypeDefinition %type UnaryExpression_ %type UnaryExpression %type VariableDeclaration @@ -621,24 +667,44 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type VariableStatement %type WithStatement %type Word +%type WordNoUnary @begin ObjectiveC %type WordOpt @end %type YieldExpression @begin C -%type IntegerType -%type IntegerTypeOpt -%type PrefixedType +%type EnumConstantListOpt_ +%type EnumConstantListOpt +%type IntegerNumber +%type IntegerType +%type IntegerTypeOpt +%type PrefixedType +%type PrimitiveReference %type PrimitiveType -%type SuffixedType -%type TypeSignifier +%type StructFieldListOpt +%type SuffixedType +%type SuffixedTypeOpt +%type TypeSignifier +%type TypeSignifierNone +%type TypeSignifierOpt +%type TypeSigning +%type ParameterTail %type TypeQualifierLeft -%type TypeQualifierRight -%type TypedIdentifier -%type TypedParameterList_ -%type TypedParameterList -%type TypedParameterListOpt +%type TypeQualifierLeftOpt +%type TypeQualifierRight +%type TypeQualifierRightOpt +%type TypedIdentifierDefinition +%type TypedIdentifierEncoding +%type TypedIdentifierField +%type TypedIdentifierMaybe +%type TypedIdentifierNo +%type TypedIdentifierTagged +%type TypedIdentifierYes +%type TypedParameterList_ +%type TypedParameterList +%type TypedParameterListOpt +%type TypedParameters @end @begin ObjectiveC @@ -647,14 +713,16 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type CategoryStatement %type ClassSuperOpt %type ConditionalExpressionClassic -%type ImplementationFieldListOpt -%type ImplementationFields %type ClassMessageDeclaration %type ClassMessageDeclarationListOpt %type ClassProtocolListOpt %type ClassProtocols %type ClassProtocolsOpt +%type ImplementationFieldListOpt %type ImplementationStatement +%type KeyValuePairList_ +%type KeyValuePairList +%type KeyValuePairListOpt %type MessageExpression %type MessageParameter %type MessageParameters @@ -668,7 +736,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type SelectorExpressionOpt %type SelectorList %type SelectorWordOpt -%type TypeOpt +%type TypeOpt %type VariadicCall @end @@ -696,17 +764,22 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY /* Token Priorities {{{ */ %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 {{{ */ @@ -716,17 +789,23 @@ LexPopIn: { driver.in_.pop(); }; 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(); }; -LexNewLine - : { CYMPT(@$); driver.next_ = true; } +LexNewLineOrOpt + : { CYLEX(); if (driver.newline_) { CYHLD(@$, tk::NewLine); } } + ; + +LexNewLineOrNot + : { CYLEX(); CYHLD(@$, driver.newline_ ? tk::NewLine : tk::__); } ; LexNoStar @@ -734,7 +813,7 @@ LexNoStar ; LexNoBrace - : { CYMAP(OpenBrace__, OpenBrace); CYMAP(OpenBrace__, OpenBrace_); } + : { CYMAP(OpenBrace_, OpenBrace); } ; LexNoClass @@ -750,11 +829,6 @@ LexSetStatement ; /* }}} */ /* Virtual Tokens {{{ */ -BRACE - : "{" - | "\n{" - ; - Var_ : "var" ; @@ -768,14 +842,8 @@ IdentifierName | "instanceof" { $$ = CYNew CYWord("instanceof"); } ; -NewLineOpt - : "\n" - | - ; - -Word +WordNoUnary : IdentifierNoOf[pass] { $$ = $pass; } - | "auto" { $$ = CYNew CYWord("auto"); } | "break" { $$ = CYNew CYWord("break"); } | "case" { $$ = CYNew CYWord("case"); } | "catch" { $$ = CYNew CYWord("catch"); } @@ -785,7 +853,6 @@ Word | "continue" { $$ = CYNew CYWord("continue"); } | "debugger" { $$ = CYNew CYWord("debugger"); } | "default" { $$ = CYNew CYWord("default"); } - | "delete" { $$ = CYNew CYWord("delete"); } | "do" { $$ = CYNew CYWord("do"); } | "else" { $$ = CYNew CYWord("else"); } | "enum" { $$ = CYNew CYWord("enum"); } @@ -798,7 +865,6 @@ Word | "import" { $$ = CYNew CYWord("import"); } | "!in" { $$ = CYNew CYWord("in"); } | "!of" { $$ = CYNew CYWord("of"); } - | "new" { $$ = CYNew CYWord("new"); } | "null" { $$ = CYNew CYWord("null"); } | "return" { $$ = CYNew CYWord("return"); } | "super" { $$ = CYNew CYWord("super"); } @@ -807,14 +873,17 @@ Word | "throw" { $$ = CYNew CYWord("throw"); } | "true" { $$ = CYNew CYWord("true"); } | "try" { $$ = CYNew CYWord("try"); } - | "typeof" { $$ = CYNew CYWord("typeof"); } | "var" { $$ = CYNew CYWord("var"); } - | "void" { $$ = CYNew CYWord("void"); } | "while" { $$ = CYNew CYWord("while"); } | "with" { $$ = CYNew CYWord("with"); } - | "yield" { $$ = CYNew CYIdentifier("yield"); } + ; - | Yield LexOf NewLineOpt { $$ = CYNew CYIdentifier("yield"); } +Word + : WordNoUnary[pass] { $$ = $pass; } + | "delete" { $$ = CYNew CYWord("delete"); } + | "typeof" { $$ = CYNew CYWord("typeof"); } + | "void" { $$ = CYNew CYWord("void"); } + | "yield" { $$ = CYNew CYIdentifier("yield"); } ; @begin ObjectiveC @@ -851,14 +920,28 @@ 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_ == CYDriver::NewLineNone) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi + | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi ; TerminatorOpt @@ -892,15 +975,14 @@ LabelIdentifier IdentifierTypeNoOf : Identifier_[pass] { $$ = $pass; } | "abstract" { $$ = CYNew CYIdentifier("abstract"); } + | "as" { $$ = CYNew CYIdentifier("as"); } | "await" { $$ = CYNew CYIdentifier("await"); } | "boolean" { $$ = CYNew CYIdentifier("boolean"); } | "byte" { $$ = CYNew CYIdentifier("byte"); } | "constructor" { $$ = CYNew CYIdentifier("constructor"); } - | "double" { $$ = CYNew CYIdentifier("double"); } | "each" { $$ = CYNew CYIdentifier("each"); } | "eval" { $$ = CYNew CYIdentifier("eval"); } | "final" { $$ = CYNew CYIdentifier("final"); } - | "float" { $$ = CYNew CYIdentifier("float"); } | "from" { $$ = CYNew CYIdentifier("from"); } | "get" { $$ = CYNew CYIdentifier("get"); } | "goto" { $$ = CYNew CYIdentifier("goto"); } @@ -913,6 +995,7 @@ IdentifierTypeNoOf | "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"); } @@ -920,6 +1003,7 @@ IdentifierTypeNoOf | "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"); } @@ -934,18 +1018,24 @@ IdentifierType | "of" { $$ = CYNew CYIdentifier("of"); } ; +IdentifierTypeOpt + : IdentifierType[pass] { $$ = $pass; } + | { $$ = NULL; } + ; + IdentifierNoOf : IdentifierTypeNoOf | "char" { $$ = CYNew CYIdentifier("char"); } + | "double" { $$ = CYNew CYIdentifier("double"); } + | "float" { $$ = CYNew CYIdentifier("float"); } | "int" { $$ = CYNew CYIdentifier("int"); } + | "__int128" { $$ = CYNew CYIdentifier("__int128"); } | "long" { $$ = CYNew CYIdentifier("long"); } | "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 @@ -998,10 +1088,19 @@ ArrayLiteral : "[" ElementListOpt[elements] "]" { $$ = CYNew CYArray($elements); } ; -ElementList - : AssignmentExpressionOpt[value] "," ElementListOpt[next] { $$ = CYNew CYElementValue($value, $next); } +ArrayElement + : AssignmentExpression[value] { $$ = CYNew CYElementValue($value); } | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); } - | AssignmentExpression[value] { $$ = CYNew CYElementValue($value, NULL); } + ; + +ElementList_ + : "," ElementListOpt[elements] { $$ = $elements; } + | { $$ = NULL; } + ; + +ElementList + : ArrayElement[element] ElementList_[next] { $$ = $element; $$->SetNext($next); } + | LexOf "," ElementListOpt[next] { $$ = CYNew CYElementValue(NULL, $next); } ; ElementListOpt @@ -1011,7 +1110,7 @@ ElementListOpt /* }}} */ /* 12.2.6 Object Initializer {{{ */ ObjectLiteral - : BRACE PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); } + : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); } ; PropertyDefinitionList_ @@ -1066,12 +1165,12 @@ InitializerOpt /* 12.2.9 Template Literals {{{ */ TemplateLiteral : NoSubstitutionTemplate[string] { $$ = CYNew CYTemplate($string, NULL); } - | TemplateHead[string] TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); } + | TemplateHead[string] LexPushInOff TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); } ; TemplateSpans : Expression[value] TemplateMiddle[string] TemplateSpans[spans] { $$ = CYNew CYSpan($value, $string, $spans); } - | Expression[value] TemplateTail[string] { $$ = CYNew CYSpan($value, $string, NULL); } + | Expression[value] TemplateTail[string] LexPopIn { $$ = CYNew CYSpan($value, $string, NULL); } ; /* }}} */ @@ -1092,8 +1191,8 @@ MemberExpression ; SuperProperty - : "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); } - | "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); } + : Super "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); } + | Super "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); } ; MetaProperty @@ -1121,7 +1220,7 @@ CallExpression ; SuperCall - : "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); } + : Super Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); } ; Arguments @@ -1149,19 +1248,15 @@ AccessExpression ; LeftHandSideExpression - : AccessExpression[pass] LexCrement { $$ = $pass; } + : BracedExpression[pass] { $$ = $pass; } | IndirectExpression[pass] { $$ = $pass; } ; /* }}} */ /* 12.4 Postfix Expressions {{{ */ -LexCrement - : { CYLIN(PlusPlus); CYLIN(HyphenHyphen); } - ; - PostfixExpression - : AccessExpression[lhs] LexCrement { $$ = $lhs; } - | AccessExpression[lhs] LexCrement "++" { $$ = CYNew CYPostIncrement($lhs); } - | AccessExpression[lhs] LexCrement "--" { $$ = CYNew CYPostDecrement($lhs); } + : BracedExpression[pass] { $$ = $pass; } + | AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); } + | AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); } ; /* }}} */ /* 12.5 Unary Operators {{{ */ @@ -1170,9 +1265,7 @@ UnaryExpression_ | "void" UnaryExpression[rhs] { $$ = CYNew CYVoid($rhs); } | "typeof" UnaryExpression[rhs] { $$ = CYNew CYTypeOf($rhs); } | "++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); } - | "\n++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); } | "--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); } - | "\n--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); } | "+" UnaryExpression[rhs] { $$ = CYNew CYAffirm($rhs); } | "-" UnaryExpression[rhs] { $$ = CYNew CYNegate($rhs); } | "~" UnaryExpression[rhs] { $$ = CYNew CYBitwiseNot($rhs); } @@ -1180,7 +1273,7 @@ UnaryExpression_ ; UnaryExpression - : PostfixExpression[expression] LexOpenBrace { $$ = $expression; } + : PostfixExpression[expression] { $$ = $expression; } | UnaryExpression_[pass] { $$ = $pass; } ; /* }}} */ @@ -1296,11 +1389,6 @@ AssignmentExpression | ArrowFunction[pass] { $$ = $pass; } | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; } ; - -AssignmentExpressionOpt - : AssignmentExpression[pass] { $$ = $pass; } - | LexOf { $$ = NULL; } - ; /* }}} */ /* 12.15 Comma Operator ( , ) {{{ */ Expression @@ -1366,11 +1454,11 @@ BlockStatement ; Block - : BRACE StatementListOpt[code] "}" { $$ = $code; } + : "{" StatementListOpt[code] "}" { $$ = $code; } ; StatementList - : StatementListItem[statement] StatementListOpt[next] { $statement->SetNext($next); $$ = $statement; } + : StatementListItem[statement] StatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; } ; StatementListOpt @@ -1457,7 +1545,7 @@ ObjectBindingPattern ; ArrayBindingPattern - : "let [" { CYNOT(@$); } + : "let [" BindingElementListOpt "]" ; BindingPropertyList_ @@ -1474,6 +1562,17 @@ BindingPropertyListOpt | LexOf ; +BindingElementList + : BindingElementOpt[element] "," BindingElementListOpt[next] + | BindingRestElement[element] + | BindingElement[element] + ; + +BindingElementListOpt + : BindingElementList[pass] + | LexBind LexOf + ; + BindingProperty : SingleNameBinding | LexOf PropertyName ":" BindingElement @@ -1484,12 +1583,17 @@ BindingElement | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); } ; +BindingElementOpt + : BindingElement[pass] + | LexBind LexOf + ; + SingleNameBinding : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); } ; BindingRestElement - : "..." BindingIdentifier + : LexBind LexOf "..." BindingIdentifier ; /* }}} */ /* 13.4 Empty Statement {{{ */ @@ -1533,7 +1637,7 @@ ForStatementInitializer ; ForInStatementInitializer - : LexLet LexOf AccessExpression[pass] LexCrement { $$ = $pass; } + : LexLet LexOf BracedExpression[pass] { $$ = $pass; } | LexLet LexOf IndirectExpression[pass] { $$ = $pass; } | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); } | ForDeclaration[pass] { $$ = $pass; } @@ -1549,33 +1653,21 @@ ForBinding ; /* }}} */ /* 13.8 The continue Statement {{{ */ -Continue - : "continue" LexNewLine - ; - ContinueStatement - : Continue TerminatorSoft { $$ = CYNew CYContinue(NULL); } - | Continue Identifier[label] Terminator { $$ = CYNew CYContinue($label); } + : "continue" TerminatorSoft { $$ = CYNew CYContinue(NULL); } + | "continue" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYContinue($label); } ; /* }}} */ /* 13.9 The break Statement {{{ */ -Break - : "break" LexNewLine - ; - BreakStatement - : Break TerminatorSoft { $$ = CYNew CYBreak(NULL); } - | Break Identifier[label] Terminator { $$ = CYNew CYBreak($label); } + : "break" TerminatorSoft { $$ = CYNew CYBreak(NULL); } + | "break" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYBreak($label); } ; /* }}} */ /* 13.10 The return Statement {{{ */ -Return - : "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); } LexNewLine - ; - ReturnStatement - : Return LexOf TerminatorSoft { $$ = CYNew CYReturn(NULL); } - | Return Expression[value] Terminator { $$ = CYNew CYReturn($value); } + : Return TerminatorSoft { $$ = CYNew CYReturn(NULL); } + | Return NewLineNot Expression[value] Terminator { $$ = CYNew CYReturn($value); } ; /* }}} */ /* 13.11 The with Statement {{{ */ @@ -1589,7 +1681,7 @@ SwitchStatement ; CaseBlock - : BRACE CaseClausesOpt[clauses] "}" { $$ = $clauses; } + : "{" CaseClausesOpt[clauses] "}" { $$ = $clauses; } ; CaseClause @@ -1618,13 +1710,9 @@ LabelledItem ; /* }}} */ /* 13.14 The throw Statement {{{ */ -Throw - : "throw" LexNewLine - ; - ThrowStatement - : Throw[throw] LexOf TerminatorSoft { CYERR(@throw, "throw without exception"); } - | Throw Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); } + : "throw"[throw] TerminatorSoft { CYERR(@throw, "throw without exception"); } + | "throw" NewLineNot Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); } ; /* }}} */ /* 13.15 The try Statement {{{ */ @@ -1655,11 +1743,11 @@ DebuggerStatement /* 14.1 Function Definitions {{{ */ FunctionDeclaration - : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" BRACE LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); } + : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); } ; FunctionExpression - : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" BRACE LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); } + : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); } ; StrictFormalParameters @@ -1677,7 +1765,7 @@ FormalParameterList_ ; FormalParameterList - : LexBind LexOf FunctionRestParameter { CYNOT(@$); } + : FunctionRestParameter { CYNOT(@$); } | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); } ; @@ -1698,12 +1786,8 @@ FunctionStatementList ; /* }}} */ /* 14.2 Arrow Function Definitions {{{ */ -LexEqualRight - : { CYLIN(EqualRight); } - ; - ArrowFunction - : ArrowParameters[parameters] LexEqualRight "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); } + : ArrowParameters[parameters] LexNewLineOrOpt "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); } ; ArrowParameters @@ -1718,10 +1802,10 @@ ConciseBody /* }}} */ /* 14.3 Method Definitions {{{ */ MethodDefinition - : PropertyName[name] "(" StrictFormalParameters[parameters] ")" BRACE FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); } + : PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); } | GeneratorMethod[pass] { $$ = $pass; } - | "get" PropertyName[name] "(" ")" BRACE FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); } - | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" BRACE FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); } + | "get" PropertyName[name] "(" ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); } + | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); } ; PropertySetParameterList @@ -1730,29 +1814,26 @@ PropertySetParameterList /* }}} */ /* 14.4 Generator Function Definitions {{{ */ GeneratorMethod - : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" BRACE GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ } + : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ } ; GeneratorDeclaration - : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" BRACE GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ } + : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ } ; GeneratorExpression - : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" BRACE GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ } + : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ } ; GeneratorBody : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; } ; -Yield - : "!yield" LexNewLine LexNoStar - ; - YieldExpression - : Yield LexOf NewLineOpt { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ } - | Yield AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ } - | Yield LexOf YieldStar AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ } + : "!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 {{{ */ @@ -1765,7 +1846,7 @@ ClassExpression ; ClassTail - : ClassHeritageOpt[tail] { driver.class_.push($tail); } BRACE LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; } + : ClassHeritageOpt[tail] { driver.class_.push($tail); } "{" LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; } ; ClassHeritage @@ -1818,88 +1899,88 @@ ScriptBodyOpt /* }}} */ /* 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 LexLet LexOf ImportDeclaration - | LexSetStatement LexLet LexOf 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" LexOf ModuleSpecifier Terminator + : "import" ImportClause[specifiers] FromClause[module] Terminator { $$ = CYNew CYImportDeclaration($specifiers, $module); } + | "import" LexOf ModuleSpecifier[module] Terminator { $$ = CYNew CYImportDeclaration(NULL, $module); } ; ImportClause - : ImportedDefaultBinding - | LexOf NameSpaceImport - | LexOf 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 - | LexOf + : ImportsList[pass] { $$ = $pass; } + | LexOf { $$ = NULL; } ; ImportSpecifier - : ImportedBinding - | LexOf 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 {{{ */ @@ -1945,64 +2026,155 @@ ExportSpecifier @begin C /* Cycript (C): Type Encoding {{{ */ TypeSignifier - : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); } - | "(" "*" TypeQualifierRight[typed] ")" { $$ = $typed; } + : 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; } + ; + +ParameterTail + : TypedParameterListOpt[formal] ")" { $$ = CYNew CYTypeFunctionWith($formal->variadic_, $formal->parameters_); } ; SuffixedType - : SuffixedType[typed] "[" NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); } - | "(" "^" TypeQualifierRight[typed] ")" "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); } - | TypeSignifier[typed] "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeFunctionWith($parameters, $$->modifier_); } - | "("[parenthesis] TypedParameterListOpt[parameters] ")" { $$ = CYNew CYTypedIdentifier(@parenthesis); $$->modifier_ = CYNew CYTypeFunctionWith($parameters, $$->modifier_); } - | TypeSignifier[pass] { $$ = $pass; } - | { $$ = CYNew CYTypedIdentifier(@$); } + : SuffixedTypeOpt[typed] "[" AssignmentExpression[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[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); } + : "*" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); } ; TypeQualifierLeft - : { $$ = NULL; } - | "const" TypeQualifierLeft[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); } - | "volatile" TypeQualifierLeft[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); } + : "const" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); } + | "volatile" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); } + ; + +TypeQualifierLeftOpt + : TypeQualifierLeft[pass] { $$ = $pass; } + | { $$ = NULL; } ; TypeQualifierRight - : PrefixedType[pass] { $$ = $pass; } - | SuffixedType[pass] { $$ = $pass; } - | "const" TypeQualifierRight[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); } - | "volatile" TypeQualifierRight[typed] { $$ = $typed; $$->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_); } + ; + +TypeQualifierRightOpt + : TypeQualifierRight[pass] { $$ = $pass; } + | TypeSignifierOpt[pass] { $$ = $pass; } ; IntegerType - : "int" { $$ = CYNew CYTypeVariable("int"); } - | "unsigned" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeUnsigned($specifier); } - | "signed" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeSigned($specifier); } - | "long" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeLong($specifier); } - | "short" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeShort($specifier); } + : "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[pass] { $$ = $pass; } - | { $$ = CYNew CYTypeVariable("int"); } + | { $$ = 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[name] { $$ = CYNew CYTypeVariable($name); } | IntegerType[pass] { $$ = $pass; } + | TypeSigning[signing] "char" { $$ = CYNew CYTypeCharacter($signing); } + | TypeSigning[signing] "__int128" { $$ = CYNew CYTypeInt128($signing); } + | "float" { $$ = CYNew CYTypeFloating(0); } + | "double" { $$ = CYNew CYTypeFloating(1); } + | "long" "double" { $$ = CYNew CYTypeFloating(2); } | "void" { $$ = CYNew CYTypeVoid(); } - | "char" { $$ = CYNew CYTypeVariable("char"); } - | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); } - | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); } ; -TypedIdentifier - : TypeQualifierLeft[modifier] PrimitiveType[specifier] TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } +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 + : 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; } + ; + +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; } ; PrimaryExpression - : "@encode" "(" TypedIdentifier[typed] ")" { $$ = CYNew CYEncodedType($typed); } + : "@encode" "(" TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYEncodedType($typed); } ; /* }}} */ @end @@ -2016,26 +2188,22 @@ ClassSuperOpt ; ImplementationFieldListOpt - : TypedIdentifier[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); } + : TypedIdentifierField[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $typed->name_, $next); } | { $$ = NULL; } ; -ImplementationFields - : BRACE ImplementationFieldListOpt[fields] "}" { $$ = $fields; } - ; - MessageScope : "+" { $$ = false; } | "-" { $$ = true; } ; TypeOpt - : "(" TypedIdentifier[type] ")" { if ($type->identifier_ != NULL) CYERR($type->location_, "unexpected identifier"); $$ = $type; } - | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); } + : "(" TypedIdentifierNo[type] ")" { $$ = $type; } + | { $$ = CYNew CYType(CYNew CYTypeVariable("id")); } ; MessageParameter - : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $type->identifier_ = $identifier; $$ = CYNew CYMessageParameter($tag, $type); } + : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $$ = CYNew CYMessageParameter($tag, $type, $identifier); } ; MessageParameterList @@ -2044,16 +2212,16 @@ MessageParameterList MessageParameterListOpt : MessageParameterList[pass] { $$ = $pass; } - | { $$ = NULL; } + | TypedParameterList_[formal] { if ($formal->variadic_) CYERR(@$, "unsupported variadic"); /*XXX*/ if ($formal->parameters_ != NULL) CYERR(@$, "temporarily unsupported"); $$ = NULL; } ; MessageParameters : MessageParameterList[pass] { $$ = $pass; } - | Word[tag] { $$ = CYNew CYMessageParameter($tag, NULL); } + | Word[tag] { $$ = CYNew CYMessageParameter($tag); } ; ClassMessageDeclaration - : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] BRACE LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); } + : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] "{" LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); } ; ClassMessageDeclarationListOpt @@ -2077,7 +2245,7 @@ ClassProtocolListOpt ; ImplementationStatement - : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] ImplementationFields[fields] ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); } + : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] "{" ImplementationFieldListOpt[fields] "}" ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); } ; CategoryName @@ -2162,15 +2330,29 @@ BoxableExpression | BooleanLiteral[pass] { $$ = $pass; } | NumericLiteral[pass] { $$ = $pass; } | StringLiteral[pass] { $$ = $pass; } - | ArrayLiteral[pass] { $$ = $pass; } - | ObjectLiteral[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[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()); } @@ -2180,7 +2362,7 @@ PrimaryExpression /* }}} */ /* Cycript (Objective-C): Block Expressions {{{ */ PrimaryExpression - : "^" TypedIdentifier[type] { if ($type->identifier_ != NULL) CYERR($type->location_, "unexpected identifier"); } BRACE FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); } + : "^" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); } ; /* }}} */ /* Cycript (Objective-C): Instance Literals {{{ */ @@ -2210,41 +2392,93 @@ MemberAccess | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; } ; /* }}} */ -/* Cycript (C): auto Compatibility {{{ */ -Var_ - : "auto" - ; -/* }}} */ /* Cycript (C): Lambda Expressions {{{ */ TypedParameterList_ : "," TypedParameterList[parameters] { $$ = $parameters; } - | { $$ = NULL; } + | { $$ = CYNew CYTypedFormal(false); } ; TypedParameterList - : TypedIdentifier[typed] TypedParameterList_[next] { $$ = CYNew CYTypedParameter($typed, $next); } + : 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[pass] { $$ = $pass; } - | { $$ = NULL; } + | { $$ = 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 - : "[" LexOf "&" "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifier[type] BRACE FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); } + : "(" 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[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($typed); } + : 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[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } TypedIdentifier[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); } Terminator { $$ = CYNew CYExternal($abi, $typed); } + : "extern" NewLineNot ABI[abi] ExternC[pass] { $$ = $pass; } ; -/* }}} */ +PrimaryExpression + : "(" LexOf "extern" NewLineOpt ABI[abi] TypedIdentifierField[typed] ")" { $$ = CYNew CYExternalExpression(CYNew CYString("C"), $typed, $typed->name_); } + ; +/* }}} */ @end @begin E4X @@ -2353,7 +2587,7 @@ XMLTagContent ; XMLExpression - : BRACE LexPushRegExp Expression LexPop "}" + : "{" LexPushRegExp Expression LexPop "}" ; XMLTagName @@ -2464,16 +2698,29 @@ ComprehensionIf : "if" "(" AssignmentExpression[test] ")" { $$ = CYNew CYIfComprehension($test); } ; /* }}} */ -/* JavaScript FTW: Coalesce Operator {{{ */ -ConditionalExpression - : LogicalORExpression[test] "?" LexPushInOff LexOf ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $test, $false); } - ; -/* }}} */ /* JavaScript FTW: Named Arguments {{{ */ ArgumentList - : LexOf Word[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); } + : 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: Undefined Monad {{{ */ +MemberAccess + : "?." IdentifierName[property] { $$ = CYNew CYAttemptMember(NULL, CYNew CYString($property)); } + | "?." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; } ; /* }}} */ + +/* JavaScript FTW: Java "Anonymous Inner Classes" {{{ */ +BracedParameter + : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYExtend(NULL, $properties); } + ; +/* }}} */ + /* JavaScript FTW: Ruby Blocks {{{ */ RubyProcParameterList_ : "," RubyProcParameterList[parameters] { $$ = $parameters; } @@ -2495,20 +2742,34 @@ RubyProcParametersOpt | { $$ = NULL; } ; -LexOpenBrace - : { CYLIN(OpenBrace); } +BracedParameter + : ";{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyBlock(NULL, CYNew CYRubyProc($parameters, $code)); } ; -RubyProcExpression - : "{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); } +PrimaryExpression + : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); } ; -PrimaryExpression - : BRACE RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); } +BracedExpression_ + : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; } + | BracedExpression_[lhs] { if (!$lhs->IsNew()) CYMAP(OpenBrace_, OpenBrace); } BracedParameter[rhs] LexNewLineOrOpt { $rhs->SetLeft($lhs); $$ = $rhs; } ; -PostfixExpression - : PostfixExpression[lhs] LexOpenBrace RubyProcExpression[rhs] { $$ = CYNew CYRubyBlock($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()); } ; /* }}} */