X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/09fc3efbc1e9a22b345b6e542737fc682a1f4332..0559abf83c4cc9bbd896b69dfaae1e8422521479:/Parser.ypp.in diff --git a/Parser.ypp.in b/Parser.ypp.in index 594dd52..2a1bf22 100644 --- a/Parser.ypp.in +++ b/Parser.ypp.in @@ -61,6 +61,7 @@ %union { CYForInInitializer *forin_; } %union { CYFunctionParameter *functionParameter_; } %union { CYIdentifier *identifier_; } +%union { CYImportSpecifier *import_; } %union { CYInfix *infix_; } %union { CYLiteral *literal_; } %union { CYMethod *method_; } @@ -80,6 +81,8 @@ %union { CYWord *word_; } @begin C +%union { CYTypeIntegral *integral_; } +%union { CYTypeStructField *structField_; } %union { CYTypeModifier *modifier_; } %union { CYTypeSpecifier *specifier_; } %union { CYTypedIdentifier *typedIdentifier_; } @@ -87,9 +90,9 @@ @end @begin ObjectiveC +%union { CYImplementationField *implementationField_; } %union { CYMessage *message_; } %union { CYMessageParameter *messageParameter_; } -%union { CYImplementationField *implementationField_; } %union { CYProtocol *protocol_; } %union { CYSelectorPart *selector_; } @end @@ -113,25 +116,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 +152,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,12 +182,6 @@ _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 ## _); \ -} while (false) - #define CYERR(location, message) do { \ error(location, message); \ YYABORT; \ @@ -215,6 +208,15 @@ _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; + } }; %locations @@ -267,14 +269,12 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %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 "<=" @@ -290,7 +290,6 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token Plus "+" %token PlusEqual "+=" %token PlusPlus "++" -%token PlusPlus_ "\n++" %token Right ">" %token RightEqual ">=" %token RightRight ">>" @@ -308,6 +307,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token Question "?" %token SemiColon ";" %token NewLine "\n" +%token __ "" %token Comment @@ -315,8 +315,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 +333,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 +359,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" @@ -421,8 +422,11 @@ _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 ___restrict_ "__restrict" +%token _restrict_ "restrict" %token _set_ "set" %token _short_ "short" %token _static_ "static" @@ -444,7 +448,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 +458,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY @end %token AutoComplete -%token YieldStar +%token YieldStar "yield *" %token Identifier_ %token NumericLiteral @@ -514,7 +517,6 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type ConciseBody %type CoverParenthesizedExpressionAndArrowParameterList %type DebuggerStatement -%type Declaration__ %type Declaration_ %type Declaration %type DefaultClause @@ -527,6 +529,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 @@ -536,6 +541,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 @@ -549,9 +555,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 @@ -572,8 +587,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 @@ -589,6 +612,8 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type RegularExpressionSlash %type RelationalExpression %type ReturnStatement +%type RubyBlockExpression_ +%type RubyBlockExpression %type RubyProcExpression %type RubyProcParameterList_ %type RubyProcParameterList @@ -613,6 +638,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 @@ -628,15 +654,27 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type YieldExpression @begin C -%type IntegerType -%type IntegerTypeOpt +%type IntegerType +%type IntegerTypeOpt %type PrefixedType %type PrimitiveType +%type StructFieldListOpt %type SuffixedType +%type SuffixedTypeOpt %type TypeSignifier +%type TypeSignifierNone +%type TypeSignifierOpt +%type ParameterTail %type TypeQualifierLeft +%type TypeQualifierLeftOpt %type TypeQualifierRight -%type TypedIdentifier +%type TypeQualifierRightOpt +%type TypedIdentifierDefinition +%type TypedIdentifierEncoding +%type TypedIdentifierField +%type TypedIdentifierMaybe +%type TypedIdentifierNo +%type TypedIdentifierYes %type TypedParameterList_ %type TypedParameterList %type TypedParameterListOpt @@ -648,13 +686,12 @@ _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 MessageExpression %type MessageParameter @@ -717,21 +754,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(); }; -LexSetRegExp - : +LexNewLineOrOpt + : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); if (driver.newline_) { driver.hold_ = yyla.type; yyla.type = yytranslate_(cy::parser::token::NewLine); } } ; -LexNewLine - : { CYMPT(@$); driver.next_ = true; } +LexNewLineOrNot + : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); driver.hold_ = yyla.type; yyla.type = yytranslate_(driver.newline_ ? cy::parser::token::NewLine : cy::parser::token::__); } ; LexNoStar @@ -739,7 +778,7 @@ LexNoStar ; LexNoBrace - : { CYMAP(OpenBrace__, OpenBrace); CYMAP(OpenBrace__, OpenBrace_); } + : { CYMAP(OpenBrace_, OpenBrace); } ; LexNoClass @@ -755,11 +794,6 @@ LexSetStatement ; /* }}} */ /* Virtual Tokens {{{ */ -BRACE - : "{" - | "\n{" - ; - Var_ : "var" ; @@ -773,14 +807,8 @@ IdentifierName | "instanceof" { $$ = CYNew CYWord("instanceof"); } ; -NewLineOpt - : "\n" - | - ; - Word : IdentifierNoOf[pass] { $$ = $pass; } - | "auto" { $$ = CYNew CYWord("auto"); } | "break" { $$ = CYNew CYWord("break"); } | "case" { $$ = CYNew CYWord("case"); } | "catch" { $$ = CYNew CYWord("catch"); } @@ -790,7 +818,7 @@ Word | "continue" { $$ = CYNew CYWord("continue"); } | "debugger" { $$ = CYNew CYWord("debugger"); } | "default" { $$ = CYNew CYWord("default"); } - | "delete" LexSetRegExp { $$ = CYNew CYWord("delete"); } + | "delete" { $$ = CYNew CYWord("delete"); } | "do" { $$ = CYNew CYWord("do"); } | "else" { $$ = CYNew CYWord("else"); } | "enum" { $$ = CYNew CYWord("enum"); } @@ -803,7 +831,7 @@ Word | "import" { $$ = CYNew CYWord("import"); } | "!in" { $$ = CYNew CYWord("in"); } | "!of" { $$ = CYNew CYWord("of"); } - | "new" LexSetRegExp { $$ = CYNew CYWord("new"); } + | "new" { $$ = CYNew CYWord("new"); } | "null" { $$ = CYNew CYWord("null"); } | "return" { $$ = CYNew CYWord("return"); } | "super" { $$ = CYNew CYWord("super"); } @@ -812,14 +840,12 @@ Word | "throw" { $$ = CYNew CYWord("throw"); } | "true" { $$ = CYNew CYWord("true"); } | "try" { $$ = CYNew CYWord("try"); } - | "typeof" LexSetRegExp { $$ = CYNew CYWord("typeof"); } + | "typeof" { $$ = CYNew CYWord("typeof"); } | "var" { $$ = CYNew CYWord("var"); } - | "void" LexSetRegExp { $$ = CYNew CYWord("void"); } + | "void" { $$ = CYNew CYWord("void"); } | "while" { $$ = CYNew CYWord("while"); } | "with" { $$ = CYNew CYWord("with"); } | "yield" { $$ = CYNew CYIdentifier("yield"); } - - | Yield LexSetRegExp NewLineOpt { $$ = CYNew CYIdentifier("yield"); } ; @begin ObjectiveC @@ -856,14 +882,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 @@ -879,14 +919,14 @@ IdentifierReference ; BindingIdentifier - : IdentifierNoOf[pass] { $$ = $pass; } - | "!of" { $$ = CYNew CYIdentifier("of"); } - | "yield" { $$ = CYNew CYIdentifier("yield"); } + : LexOf IdentifierNoOf[pass] { $$ = $pass; } + | LexOf "!of" { $$ = CYNew CYIdentifier("of"); } + | LexOf "yield" { $$ = CYNew CYIdentifier("yield"); } ; BindingIdentifierOpt : BindingIdentifier[pass] { $$ = $pass; } - | { $$ = NULL; } + | LexOf { $$ = NULL; } ; LabelIdentifier @@ -897,6 +937,7 @@ 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"); } @@ -913,11 +954,12 @@ IdentifierTypeNoOf | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); } | "interface" { $$ = CYNew CYIdentifier("interface"); } | "let" { $$ = CYNew CYIdentifier("let"); } - | "!let" LexBind { $$ = CYNew CYIdentifier("let"); } + | "!let" LexBind LexOf { $$ = CYNew CYIdentifier("let"); } | "native" { $$ = CYNew CYIdentifier("native"); } | "package" { $$ = CYNew CYIdentifier("package"); } | "private" { $$ = CYNew CYIdentifier("private"); } | "protected" { $$ = CYNew CYIdentifier("protected"); } + | "__proto__" { $$ = CYNew CYIdentifier("__proto__"); } | "prototype" { $$ = CYNew CYIdentifier("prototype"); } | "public" { $$ = CYNew CYIdentifier("public"); } | "set" { $$ = CYNew CYIdentifier("set"); } @@ -939,18 +981,23 @@ IdentifierType | "of" { $$ = CYNew CYIdentifier("of"); } ; +IdentifierTypeOpt + : IdentifierType[pass] { $$ = $pass; } + | { $$ = NULL; } + ; + IdentifierNoOf : IdentifierTypeNoOf | "char" { $$ = CYNew CYIdentifier("char"); } | "int" { $$ = CYNew CYIdentifier("int"); } | "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 @@ -964,6 +1011,7 @@ IdentifierNoOf Identifier : IdentifierNoOf[pass] { $$ = $pass; } | "of" { $$ = CYNew CYIdentifier("of"); } + | "!of" { $$ = CYNew CYIdentifier("of"); } ; /* }}} */ /* 12.2 Primary Expression {{{ */ @@ -984,9 +1032,9 @@ PrimaryExpression CoverParenthesizedExpressionAndArrowParameterList : "(" Expression[expression] ")" { $$ = CYNew CYParenthetical($expression); } - | "(" LexSetRegExp ")" { $$ = NULL; } - | "(" LexSetRegExp "..." BindingIdentifier ")" { CYNOT(@$); } - | "(" Expression "," LexSetRegExp "..." BindingIdentifier ")" { CYNOT(@$); } + | "(" LexOf ")" { $$ = NULL; } + | "(" LexOf "..." BindingIdentifier ")" { CYNOT(@$); } + | "(" Expression "," LexOf "..." BindingIdentifier ")" { CYNOT(@$); } ; /* }}} */ /* 12.2.4 Literals {{{ */ @@ -1004,18 +1052,18 @@ ArrayLiteral ElementList : AssignmentExpressionOpt[value] "," ElementListOpt[next] { $$ = CYNew CYElementValue($value, $next); } - | LexSetRegExp "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); } + | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); } | AssignmentExpression[value] { $$ = CYNew CYElementValue($value, NULL); } ; ElementListOpt : ElementList[pass] { $$ = $pass; } - | LexSetRegExp { $$ = NULL; } + | LexOf { $$ = NULL; } ; /* }}} */ /* 12.2.6 Object Initializer {{{ */ ObjectLiteral - : BRACE PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); } + : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); } ; PropertyDefinitionList_ @@ -1028,8 +1076,8 @@ PropertyDefinitionList ; PropertyDefinitionListOpt - : LexSetRegExp PropertyDefinitionList[properties] { $$ = $properties; } - | LexSetRegExp { $$ = NULL; } + : PropertyDefinitionList[properties] { $$ = $properties; } + | { $$ = NULL; } ; PropertyDefinition @@ -1070,12 +1118,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); } ; /* }}} */ @@ -1088,16 +1136,16 @@ MemberAccess ; MemberExpression - : LexSetRegExp PrimaryExpression[pass] { $$ = $pass; } + : PrimaryExpression[pass] { $$ = $pass; } | MemberExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; } | SuperProperty[pass] { $$ = $pass; } | MetaProperty { CYNOT(@$); } - | LexSetRegExp "new" MemberExpression[constructor] Arguments[arguments] { $$ = CYNew cy::Syntax::New($constructor, $arguments); } + | "new" MemberExpression[constructor] Arguments[arguments] { $$ = CYNew cy::Syntax::New($constructor, $arguments); } ; SuperProperty - : LexSetRegExp "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); } - | LexSetRegExp "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 @@ -1105,12 +1153,12 @@ MetaProperty ; NewTarget - : LexSetRegExp "new" LexSetRegExp "." "target" + : "new" "." "target" ; NewExpression : MemberExpression[pass] { $$ = $pass; } - | LexSetRegExp "new" NewExpression[expression] { $$ = CYNew cy::Syntax::New($expression, NULL); } + | "new" NewExpression[expression] { $$ = CYNew cy::Syntax::New($expression, NULL); } ; CallExpression_ @@ -1125,7 +1173,7 @@ CallExpression ; SuperCall - : LexSetRegExp "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); } + : Super Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); } ; Arguments @@ -1139,12 +1187,12 @@ ArgumentList_ ArgumentList : AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument(NULL, $value, $next); } - | LexSetRegExp "..." AssignmentExpression { CYNOT(@$); } + | LexOf "..." AssignmentExpression { CYNOT(@$); } ; ArgumentListOpt : ArgumentList[pass] { $$ = $pass; } - | LexSetRegExp { $$ = NULL; } + | LexOf { $$ = NULL; } ; AccessExpression @@ -1153,19 +1201,15 @@ AccessExpression ; LeftHandSideExpression - : AccessExpression[pass] LexCrement { $$ = $pass; } - | LexSetRegExp IndirectExpression[pass] { $$ = $pass; } + : RubyBlockExpression[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); } + : RubyBlockExpression[pass] { $$ = $pass; } + | AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); } + | AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); } ; /* }}} */ /* 12.5 Unary Operators {{{ */ @@ -1174,9 +1218,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); } @@ -1184,8 +1226,8 @@ UnaryExpression_ ; UnaryExpression - : PostfixExpression[expression] LexOpenBrace { $$ = $expression; } - | LexSetRegExp UnaryExpression_[pass] { $$ = $pass; } + : PostfixExpression[expression] { $$ = $expression; } + | UnaryExpression_[pass] { $$ = $pass; } ; /* }}} */ /* 12.6 Multiplicative Operators {{{ */ @@ -1289,21 +1331,21 @@ LeftHandSideAssignment @begin ObjectiveC AssignmentExpressionClassic - : ConditionalExpressionClassic[pass] { $$ = $pass; } - | LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; } + : LexOf ConditionalExpressionClassic[pass] { $$ = $pass; } + | LexOf LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; } ; @end AssignmentExpression - : ConditionalExpression[pass] { $$ = $pass; } - | LexSetRegExp YieldExpression[pass] { $$ = $pass; } + : LexOf ConditionalExpression[pass] { $$ = $pass; } + | LexOf YieldExpression[pass] { $$ = $pass; } | ArrowFunction[pass] { $$ = $pass; } - | LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; } + | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; } ; AssignmentExpressionOpt : AssignmentExpression[pass] { $$ = $pass; } - | LexSetRegExp { $$ = NULL; } + | LexOf { $$ = NULL; } ; /* }}} */ /* 12.15 Comma Operator ( , ) {{{ */ @@ -1314,7 +1356,7 @@ Expression ExpressionOpt : Expression[pass] { $$ = $pass; } - | LexSetRegExp { $$ = NULL; } + | LexOf { $$ = NULL; } ; /* }}} */ @@ -1336,7 +1378,7 @@ Statement__ ; Statement_ - : LexSetRegExp Statement__[pass] { $$ = $pass; } + : LexOf Statement__[pass] { $$ = $pass; } | ExpressionStatement[pass] { $$ = $pass; } ; @@ -1344,18 +1386,14 @@ Statement : LexSetStatement LexLet Statement_[pass] { $$ = $pass; } ; -Declaration__ +Declaration_ : HoistableDeclaration[pass] { $$ = $pass; } | ClassDeclaration[pass] { $$ = $pass; } ; -Declaration_ - : LexLet LexSetRegExp Declaration__[pass] { $$ = $pass; } - | LexicalDeclaration[pass] { $$ = $pass; } - ; - Declaration - : LexSetStatement Declaration_[pass] { $$ = $pass; } + : LexSetStatement LexLet LexOf Declaration_[pass] { $$ = $pass; } + | LexSetStatement LexicalDeclaration[pass] { $$ = $pass; } ; HoistableDeclaration @@ -1374,16 +1412,16 @@ 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 : StatementList[pass] { $$ = $pass; } - | LexSetStatement LexLet LexSetRegExp { $$ = NULL; } + | LexSetStatement LexLet LexOf { $$ = NULL; } ; StatementListItem @@ -1409,12 +1447,12 @@ LexOf ; LexBind - : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); } LexOf + : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); } ; LetOrConst - : LexLet LexSetRegExp "!let" LexBind { $$ = false; } - | LexLet LexSetRegExp "const" { $$ = true; } + : LexLet LexOf "!let" LexBind LexOf { $$ = false; } + | LexLet LexOf "const" { $$ = true; } ; BindingList_ @@ -1428,7 +1466,7 @@ BindingList LexicalBinding : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); } - | BindingPattern Initializer { CYNOT(@$); } + | LexOf BindingPattern Initializer { CYNOT(@$); } ; /* }}} */ /* 13.3.2 Variable Statement {{{ */ @@ -1451,7 +1489,7 @@ VariableDeclarationList VariableDeclaration : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); } - | BindingPattern Initializer { CYNOT(@$); } + | LexOf BindingPattern Initializer { CYNOT(@$); } ; /* }}} */ /* 13.3.3 Destructuring Binding Patterns {{{ */ @@ -1465,7 +1503,7 @@ ObjectBindingPattern ; ArrayBindingPattern - : "let [" { CYNOT(@$); } + : "let [" BindingElementListOpt "]" ; BindingPropertyList_ @@ -1479,17 +1517,33 @@ BindingPropertyList BindingPropertyListOpt : BindingPropertyList - | + | LexOf + ; + +BindingElementList + : BindingElementOpt[element] "," BindingElementListOpt[next] + | BindingRestElement[element] + | BindingElement[element] + ; + +BindingElementListOpt + : BindingElementList[pass] + | LexBind LexOf ; BindingProperty : SingleNameBinding - | PropertyName ":" BindingElement + | LexOf PropertyName ":" BindingElement ; BindingElement : LexBind SingleNameBinding[pass] { $$ = $pass; } - | LexBind BindingPattern InitializerOpt[initializer] { CYNOT(@$); } + | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); } + ; + +BindingElementOpt + : BindingElement[pass] + | LexBind LexOf ; SingleNameBinding @@ -1497,7 +1551,7 @@ SingleNameBinding ; BindingRestElement - : "..." BindingIdentifier + : LexBind LexOf "..." BindingIdentifier ; /* }}} */ /* 13.4 Empty Statement {{{ */ @@ -1528,22 +1582,22 @@ IterationStatement : "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 LexSetRegExp Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); } + | "for" "(" LexPushInOn LexLet LexOf Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); } | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForIn($initializer, $iterable, $code); } | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "of" LexPopIn AssignmentExpression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); } ; ForStatementInitializer - : LexLet LexSetRegExp EmptyStatement[pass] { $$ = $pass; } + : LexLet LexOf EmptyStatement[pass] { $$ = $pass; } | LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; } - | LexLet LexSetRegExp VariableStatement_[initializer] ";" { $$ = $initializer; } + | LexLet LexOf VariableStatement_[initializer] ";" { $$ = $initializer; } | LexicalDeclaration_[initializer] ";" { $$ = $initializer; } ; ForInStatementInitializer - : LexLet AccessExpression[pass] LexCrement { $$ = $pass; } - | LexLet LexSetRegExp IndirectExpression[pass] { $$ = $pass; } - | LexLet LexSetRegExp Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); } + : LexLet LexOf RubyBlockExpression[pass] { $$ = $pass; } + | LexLet LexOf IndirectExpression[pass] { $$ = $pass; } + | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); } | ForDeclaration[pass] { $$ = $pass; } ; @@ -1553,37 +1607,25 @@ ForDeclaration ForBinding : BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); } - | BindingPattern { CYNOT(@$); } + | LexOf BindingPattern { CYNOT(@$); } ; /* }}} */ /* 13.8 The continue Statement {{{ */ -Continue - : "continue" LexNewLine - ; - ContinueStatement - : Continue TerminatorSoft { $$ = CYNew CYContinue(NULL); } - | Continue Identifier[label] Terminator { $$ = CYNew CYContinue($label); } + : "continue" TerminatorSoft { $$ = CYNew CYContinue(NULL); } + | "continue" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYContinue($label); } ; /* }}} */ /* 13.9 The break Statement {{{ */ -Break - : "break" LexNewLine - ; - BreakStatement - : Break TerminatorSoft { $$ = CYNew CYBreak(NULL); } - | Break Identifier[label] Terminator { $$ = CYNew CYBreak($label); } + : "break" TerminatorSoft { $$ = CYNew CYBreak(NULL); } + | "break" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYBreak($label); } ; /* }}} */ /* 13.10 The return Statement {{{ */ -Return - : "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); } LexNewLine - ; - ReturnStatement - : Return LexSetRegExp 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 {{{ */ @@ -1597,7 +1639,7 @@ SwitchStatement ; CaseBlock - : BRACE CaseClausesOpt[clauses] "}" { $$ = $clauses; } + : "{" CaseClausesOpt[clauses] "}" { $$ = $clauses; } ; CaseClause @@ -1622,17 +1664,13 @@ LabelledStatement LabelledItem : Statement[pass] { $$ = $pass; } - | LexSetStatement LexLet LexSetRegExp FunctionDeclaration[pass] { $$ = $pass; } + | LexSetStatement LexLet LexOf FunctionDeclaration[pass] { $$ = $pass; } ; /* }}} */ /* 13.14 The throw Statement {{{ */ -Throw - : "throw" LexNewLine - ; - ThrowStatement - : Throw[throw] LexSetRegExp 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 {{{ */ @@ -1652,7 +1690,7 @@ Finally CatchParameter : BindingIdentifier[pass] { $$ = $pass; } - | BindingPattern { CYNOT(@$); } + | LexOf BindingPattern { CYNOT(@$); } ; /* }}} */ /* 13.16 The debugger Statement {{{ */ @@ -1663,11 +1701,11 @@ DebuggerStatement /* 14.1 Function Definitions {{{ */ FunctionDeclaration - : ";function" LexOf BindingIdentifier[name] "(" FormalParameters[parameters] ")" BRACE LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); } + : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); } ; FunctionExpression - : "function" LexOf BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" BRACE LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); } + : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); } ; StrictFormalParameters @@ -1675,7 +1713,7 @@ StrictFormalParameters ; FormalParameters - : LexBind { $$ = NULL; } + : LexBind LexOf { $$ = NULL; } | FormalParameterList ; @@ -1685,7 +1723,7 @@ FormalParameterList_ ; FormalParameterList - : LexBind FunctionRestParameter { CYNOT(@$); } + : FunctionRestParameter { CYNOT(@$); } | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); } ; @@ -1706,30 +1744,26 @@ FunctionStatementList ; /* }}} */ /* 14.2 Arrow Function Definitions {{{ */ -LexEqualRight - : { CYLIN(EqualRight); } - ; - ArrowFunction - : LexSetRegExp ArrowParameters[parameters] LexEqualRight "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); } + : ArrowParameters[parameters] LexNewLineOrOpt "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); } ; ArrowParameters : BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); } - | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } } + | LexOf CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } } ; ConciseBody : AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); } - | LexSetRegExp ";{" FunctionBody[code] "}" { $$ = $code; } + | LexOf ";{" FunctionBody[code] "}" { $$ = $code; } ; /* }}} */ /* 14.3 Method Definitions {{{ */ MethodDefinition - : PropertyName[name] "(" StrictFormalParameters[parameters] ")" BRACE FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); } + : PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); } | GeneratorMethod[pass] { $$ = $pass; } - | "get" PropertyName[name] "(" ")" BRACE FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); } - | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" BRACE FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); } + | "get" PropertyName[name] "(" ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); } + | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); } ; PropertySetParameterList @@ -1738,42 +1772,39 @@ PropertySetParameterList /* }}} */ /* 14.4 Generator Function Definitions {{{ */ GeneratorMethod - : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" BRACE GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ } + : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ } ; GeneratorDeclaration - : ";function" LexOf "*" LexOf BindingIdentifier[name] "(" FormalParameters[code] ")" BRACE GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ } + : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ } ; GeneratorExpression - : "function" LexOf "*" LexOf BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" BRACE GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ } + : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ } ; GeneratorBody : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; } ; -Yield - : "!yield" LexNewLine LexNoStar - ; - YieldExpression - : Yield LexSetRegExp NewLineOpt { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ } - | Yield AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ } - | Yield LexSetRegExp YieldStar AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ } + : "!yield" LexNewLineOrNot "\n" LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ } + | "!yield" LexNewLineOrNot "" LexNoStar LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ } + | "!yield" LexNewLineOrNot "" LexNoStar AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ } + | "!yield" LexNewLineOrNot "" LexNoStar LexOf "yield *" AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ } ; /* }}} */ /* 14.5 Class Definitions {{{ */ ClassDeclaration - : ";class" LexOf BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); } + : ";class" BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); } ; ClassExpression - : "class" LexOf BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); } + : "class" BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); } ; ClassTail - : ClassHeritageOpt[tail] { driver.class_.push($tail); } BRACE LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; } + : ClassHeritageOpt[tail] { driver.class_.push($tail); } "{" LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; } ; ClassHeritage @@ -1821,93 +1852,93 @@ ScriptBody ScriptBodyOpt : ScriptBody[pass] { $$ = $pass; } - | LexSetStatement LexLet LexSetRegExp { $$ = NULL; } + | 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 LexLet LexSetRegExp ImportDeclaration - | LexSetStatement LexLet 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 {{{ */ @@ -1916,13 +1947,13 @@ ExportDeclaration_ | 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 LexLet LexSetRegExp ExportDeclaration_ + : "export" LexSetStatement LexLet LexOf ExportDeclaration_ | "export" Declaration ; @@ -1954,63 +1985,138 @@ ExportSpecifier /* Cycript (C): Type Encoding {{{ */ TypeSignifier : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); } - | "(" "*" TypeQualifierRight[typed] ")" { $$ = $typed; } + | "(" "*" TypeQualifierRightOpt[typed] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); } + ; + +TypeSignifierNone + : { $$ = CYNew CYTypedIdentifier(@$); } + ; + +TypeSignifierOpt + : TypeSignifier[pass] { $$ = $pass; } + | TypeSignifierNone[pass] { $$ = $pass; } + ; + +Restrict + : "__restrict" + | "restrict" + ; + +RestrictOpt + : Restrict + | + ; + +ParameterModifier + : "throw" "(" ")" + ; + +ParameterModifierOpt + : ParameterModifier + | + ; + +ParameterTail + : TypedParameterListOpt[parameters] ")" ParameterModifierOpt { $$ = CYNew CYTypeFunctionWith($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] "[" RestrictOpt NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); } + | "(" "^" TypeQualifierRightOpt[typed] ")" "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); } + | TypeSignifier[typed] "(" ParameterTail[modifier] { $$ = $typed; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } + | "("[parenthesis] ParameterTail[modifier] { $$ = CYNew CYTypedIdentifier(@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_); } + | Restrict TypeQualifierRightOpt[typed] { $$ = $typed; } + ; + +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, $next); } + | { $$ = NULL; } ; PrimitiveType : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); } | IntegerType[pass] { $$ = $pass; } - | "void" { $$ = CYNew CYTypeVoid(); } - | "char" { $$ = CYNew CYTypeVariable("char"); } - | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); } - | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); } + | "char" { $$ = CYNew CYTypeCharacter(CYTypeNeutral); } + | "signed" "char" { $$ = CYNew CYTypeCharacter(CYTypeSigned); } + | "unsigned" "char" { $$ = CYNew CYTypeCharacter(CYTypeUnsigned); } + | "struct" IdentifierType[name] { $$ = CYNew CYTypeReference($name); } + ; + +TypedIdentifierMaybe + : TypeQualifierLeft[modifier] "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } + | "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); } + | TypeQualifierLeftOpt[modifier] PrimitiveType[specifier] TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } + ; + +TypedIdentifierYes + : TypedIdentifierMaybe[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; } + ; + +TypedIdentifierNo + : TypedIdentifierMaybe[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; } ; -TypedIdentifier - : TypeQualifierLeft[modifier] PrimitiveType[specifier] TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } +TypedIdentifierField + : TypedIdentifierYes[pass] { $$ = $pass; } + | TypeQualifierLeftOpt[modifier] "struct" "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; $$->specifier_ = CYNew CYTypeStruct(NULL, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } + ; + +TypedIdentifierEncoding + : TypedIdentifierNo[pass] { $$ = $pass; } + | TypeQualifierLeftOpt[modifier] "struct" "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; $$->specifier_ = CYNew CYTypeStruct(NULL, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } + ; + +TypedIdentifierDefinition + : TypedIdentifierYes[pass] { $$ = $pass; } + | TypeQualifierLeftOpt[modifier] "struct" IdentifierTypeOpt[name] "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { if ($typed->identifier_ == 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 @@ -2019,17 +2125,13 @@ PrimaryExpression /* Cycript (Objective-C): @class Declaration {{{ */ ClassSuperOpt /* XXX: why the hell did I choose MemberExpression? */ - : ":" LexSetRegExp MemberExpression[extends] { $$ = $extends; } + : ":" MemberExpression[extends] { $$ = $extends; } | { $$ = NULL; } ; ImplementationFieldListOpt - : LexSetRegExp TypedIdentifier[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); } - | LexSetRegExp { $$ = NULL; } - ; - -ImplementationFields - : BRACE ImplementationFieldListOpt[fields] "}" { $$ = $fields; } + : TypedIdentifierField[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); } + | { $$ = NULL; } ; MessageScope @@ -2038,7 +2140,7 @@ MessageScope ; TypeOpt - : "(" LexSetRegExp TypedIdentifier[type] ")" { if ($type->identifier_ != NULL) CYERR($type->location_, "unexpected identifier"); $$ = $type; } + : "(" TypedIdentifierNo[type] ")" { $$ = $type; } | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); } ; @@ -2061,7 +2163,7 @@ MessageParameters ; 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 @@ -2085,7 +2187,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 @@ -2128,7 +2230,7 @@ SelectorList MessageExpression : "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); } - | "[" LexSetRegExp "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); } + | "[" LexOf "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); } ; SelectorExpression_ @@ -2158,7 +2260,7 @@ ModulePath | Word[part] { $$ = CYNew CYModule($part); } ; -Declaration__ +Declaration_ : "@import" ModulePath[path] { $$ = CYNew CYImport($path); } ; /* }}} */ @@ -2188,7 +2290,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 {{{ */ @@ -2218,11 +2320,6 @@ MemberAccess | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; } ; /* }}} */ -/* Cycript (C): auto Compatibility {{{ */ -Var_ - : "auto" - ; -/* }}} */ /* Cycript (C): Lambda Expressions {{{ */ TypedParameterList_ : "," TypedParameterList[parameters] { $$ = $parameters; } @@ -2230,29 +2327,73 @@ TypedParameterList_ ; TypedParameterList - : TypedIdentifier[typed] TypedParameterList_[next] { $$ = CYNew CYTypedParameter($typed, $next); } + : TypedIdentifierMaybe[typed] TypedParameterList_[next] { $$ = CYNew CYTypedParameter($typed, $next); } ; TypedParameterListOpt : TypedParameterList[pass] { $$ = $pass; } + | "void" { $$ = NULL; } | { $$ = NULL; } ; PrimaryExpression - : "[" LexSetRegExp "&" LexSetRegExp "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifier[type] BRACE FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); } + : "[" LexOf "&" "]" "(" TypedParameterListOpt[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 "struct" NewLineOpt IdentifierType[name] TypeQualifierRightOpt[typed] ")" { $typed->specifier_ = CYNew CYTypeReference($name); $$ = CYNew CYTypeExpression($typed); } ; /* }}} */ /* Cycript (C): Type Definitions {{{ */ +IdentifierNoOf + : "typedef" NewLineOpt { $$ = CYNew CYIdentifier("typedef"); } + ; + +TypeDefinition + : "typedef" NewLineNot TypedIdentifierDefinition[typed] TerminatorHard { $$ = CYNew CYTypeDefinition($typed); } + ; + 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 { $$ = CYNew CYExternal(CYNew CYString("C"), $typed); } + | TypeDefinition[pass] { $$ = $pass; } + ; + +ExternCStatementListOpt + : ExternCStatement[statement] ExternCStatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; } + | { $$ = NULL; } + ; + +ExternC + : "{" ExternCStatementListOpt[pass] "}" { $$ = $pass; } + | ExternCStatement[pass] { $$ = $pass; } + ; + Statement__ - : "extern" StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } TypedIdentifier[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); } Terminator { $$ = CYNew CYExternal($abi, $typed); } + : "extern" NewLineNot StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } ExternC[pass] { $$ = $pass; } ; /* }}} */ - @end @begin E4X @@ -2361,7 +2502,7 @@ XMLTagContent ; XMLExpression - : BRACE LexPushRegExp Expression LexPop "}" + : "{" LexPushRegExp Expression LexPop "}" ; XMLTagName @@ -2454,7 +2595,7 @@ ArrayComprehension ; Comprehension - : LexSetRegExp ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); } + : LexOf ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); } ; ComprehensionTail @@ -2474,12 +2615,12 @@ ComprehensionIf /* }}} */ /* JavaScript FTW: Coalesce Operator {{{ */ ConditionalExpression - : LogicalORExpression[test] "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $test, $false); } + : LogicalORExpression[test] "?" LexPushInOff LexOf ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $test, $false); } ; /* }}} */ /* JavaScript FTW: Named Arguments {{{ */ ArgumentList - : LexSetRegExp Word[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); } + : LexOf Word[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); } ; /* }}} */ /* JavaScript FTW: Ruby Blocks {{{ */ @@ -2490,21 +2631,17 @@ RubyProcParameterList_ RubyProcParameterList : BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); } - | { $$ = NULL; } + | LexOf { $$ = NULL; } ; RubyProcParameters - : LexSetRegExp "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; } - | LexSetRegExp "||" { $$ = NULL; } + : "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; } + | "||" { $$ = NULL; } ; RubyProcParametersOpt : RubyProcParameters[pass] { $$ = $pass; } - | LexSetRegExp { $$ = NULL; } - ; - -LexOpenBrace - : { CYLIN(OpenBrace); } + | { $$ = NULL; } ; RubyProcExpression @@ -2512,11 +2649,17 @@ RubyProcExpression ; PrimaryExpression - : BRACE RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); } + : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); } ; -PostfixExpression - : PostfixExpression[lhs] LexOpenBrace RubyProcExpression[rhs] { $$ = CYNew CYRubyBlock($lhs, $rhs); } +RubyBlockExpression_ + : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; } + | RubyBlockExpression_[lhs] RubyProcExpression[rhs] LexNewLineOrOpt { $$ = CYNew CYRubyBlock($lhs, $rhs); } + ; + +RubyBlockExpression + : RubyBlockExpression_[pass] "\n" { $$ = $pass; } + | RubyBlockExpression_[pass] { $$ = $pass; } ; /* }}} */