%union { CYBinding *binding_; }
%union { CYBindings *bindings_; }
%union { CYBoolean *boolean_; }
+%union { CYBraced *braced_; }
%union { CYClause *clause_; }
%union { cy::Syntax::Catch *catch_; }
%union { CYClassTail *classTail_; }
%union { CYParenthetical *parenthetical_; }
%union { CYProperty *property_; }
%union { CYPropertyName *propertyName_; }
-%union { CYRubyProc *rubyProc_; }
%union { CYSpan *span_; }
%union { CYStatement *statement_; }
%union { CYString *string_; }
%union { CYTypeStructField *structField_; }
%union { CYTypeModifier *modifier_; }
%union { CYTypeSpecifier *specifier_; }
+%union { CYTypedFormal *typedFormal_; }
%union { CYTypedIdentifier *typedIdentifier_; }
%union { CYTypedParameter *typedParameter_; }
@end
yyla.type = yytranslate_(token::to); \
} while (false)
+#define CYHLD(location, token) do { \
+ if (driver.hold_ != empty_symbol) \
+ CYERR(location, "unexpected hold"); \
+ driver.hold_ = yyla.type; \
+ yyla.type = yytranslate_(token); \
+} while (false)
+
#define CYERR(location, message) do { \
error(location, message); \
YYABORT; \
%token SlashRight "/>"
%token LeftSlash "</"
-%token ColonColon "::"
%token PeriodPeriod ".."
@end
%token Tilde "~"
%token Colon ":"
+%token ColonColon "::"
%token Comma ","
%token Question "?"
%token SemiColon ";"
%token _synchronized_ "synchronized"
%token _throws_ "throws"
%token _transient_ "transient"
+%token _typeid_ "typeid"
%token _volatile_ "volatile"
%token _yield_ "yield"
%token _yield__ "!yield"
%type <binding_> BindingElement
%type <expression_> BitwiseORExpression
%type <expression_> BitwiseXORExpression
+%type <target_> BracedExpression_
+%type <target_> BracedExpression
%type <statement_> BreakStatement
%type <statement_> BreakableStatement
%type <expression_> CallExpression_
%type <bool_> RegularExpressionSlash
%type <expression_> RelationalExpression
%type <statement_> ReturnStatement
-%type <target_> RubyBlockExpression_
-%type <target_> RubyBlockExpression
-%type <rubyProc_> RubyProcExpression
+%type <braced_> BracedParameter
%type <functionParameter_> RubyProcParameterList_
%type <functionParameter_> RubyProcParameterList
%type <functionParameter_> RubyProcParameters
%type <statement_> VariableStatement
%type <statement_> WithStatement
%type <word_> Word
+%type <word_> WordNoUnary
@begin ObjectiveC
%type <word_> WordOpt
@end
%type <typedIdentifier_> TypedIdentifierMaybe
%type <typedIdentifier_> TypedIdentifierNo
%type <typedIdentifier_> TypedIdentifierYes
-%type <typedParameter_> TypedParameterList_
-%type <typedParameter_> TypedParameterList
-%type <typedParameter_> TypedParameterListOpt
+%type <typedFormal_> TypedParameterList_
+%type <typedFormal_> TypedParameterList
+%type <typedFormal_> TypedParameterListOpt
+%type <typedParameter_> TypedParameters
@end
@begin ObjectiveC
/* Token Priorities {{{ */
%nonassoc "if"
%nonassoc "else"
+
+%nonassoc ":"
+%nonassoc "!yield"
/* }}} */
%start Program
LexPopYield: { driver.yield_.pop(); };
LexNewLineOrOpt
- : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); if (driver.newline_) { driver.hold_ = yyla.type; yyla.type = yytranslate_(cy::parser::token::NewLine); } }
+ : { CYLEX(); if (driver.newline_) { CYHLD(@$, tk::NewLine); } }
;
LexNewLineOrNot
- : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); driver.hold_ = yyla.type; yyla.type = yytranslate_(driver.newline_ ? cy::parser::token::NewLine : cy::parser::token::__); }
+ : { CYLEX(); CYHLD(@$, driver.newline_ ? tk::NewLine : tk::__); }
;
LexNoStar
| "instanceof" { $$ = CYNew CYWord("instanceof"); }
;
-Word
+WordNoUnary
: IdentifierNoOf[pass] { $$ = $pass; }
| "break" { $$ = CYNew CYWord("break"); }
| "case" { $$ = CYNew CYWord("case"); }
| "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"); }
| "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"); }
| "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"); }
+ ;
+
+Word
+ : WordNoUnary[pass] { $$ = $pass; }
+ | "delete" { $$ = CYNew CYWord("delete"); }
+ | "typeof" { $$ = CYNew CYWord("typeof"); }
+ | "void" { $$ = CYNew CYWord("void"); }
| "yield" { $$ = CYNew CYIdentifier("yield"); }
;
| "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"); }
;
LeftHandSideExpression
- : RubyBlockExpression[pass] { $$ = $pass; }
+ : BracedExpression[pass] { $$ = $pass; }
| IndirectExpression[pass] { $$ = $pass; }
;
/* }}} */
/* 12.4 Postfix Expressions {{{ */
PostfixExpression
- : RubyBlockExpression[pass] { $$ = $pass; }
+ : BracedExpression[pass] { $$ = $pass; }
| AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); }
| AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); }
;
;
ForInStatementInitializer
- : LexLet LexOf RubyBlockExpression[pass] { $$ = $pass; }
+ : LexLet LexOf BracedExpression[pass] { $$ = $pass; }
| LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
| LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
| ForDeclaration[pass] { $$ = $pass; }
YieldExpression
: "!yield" LexNewLineOrNot "\n" LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
- | "!yield" LexNewLineOrNot "" LexNoStar 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); */ }
;
;
ParameterTail
- : TypedParameterListOpt[parameters] ")" ParameterModifierOpt { $$ = CYNew CYTypeFunctionWith($parameters); }
+ : TypedParameterListOpt[formal] ")" ParameterModifierOpt { $$ = CYNew CYTypeFunctionWith($formal->variadic_, $formal->parameters_); }
;
SuffixedType
: SuffixedTypeOpt[typed] "[" RestrictOpt NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); }
- | "(" "^" TypeQualifierRightOpt[typed] ")" "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->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 CYTypedIdentifier(@parenthesis); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
;
MessageParameterListOpt
: MessageParameterList[pass] { $$ = $pass; }
- | { $$ = NULL; }
+ | TypedParameterList_[formal] { if ($formal->variadic_) CYERR(@$, "unsupported variadic"); /*XXX*/ if ($formal->parameters_ != NULL) CYERR(@$, "temporarily unsupported"); $$ = NULL; }
;
MessageParameters
/* Cycript (C): Lambda Expressions {{{ */
TypedParameterList_
: "," TypedParameterList[parameters] { $$ = $parameters; }
- | { $$ = NULL; }
+ | { $$ = CYNew CYTypedFormal(false); }
;
TypedParameterList
- : TypedIdentifierMaybe[typed] TypedParameterList_[next] { $$ = CYNew CYTypedParameter($typed, $next); }
+ : TypedIdentifierMaybe[typed] TypedParameterList_[formal] { $$ = $formal; $$->parameters_ = CYNew CYTypedParameter($typed, $$->parameters_); }
+ | "..." { $$ = CYNew CYTypedFormal(true); }
;
TypedParameterListOpt
: TypedParameterList[pass] { $$ = $pass; }
- | "void" { $$ = NULL; }
- | { $$ = NULL; }
+ | "void" { $$ = CYNew CYTypedFormal(false); }
+ | { $$ = CYNew CYTypedFormal(false); }
+ ;
+
+TypedParameters
+ : TypedParameterListOpt[formal] { if ($formal->variadic_) CYERR(@$, "unsupported variadic"); $$ = $formal->parameters_; }
;
PrimaryExpression
- : "[" LexOf "&" "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
+ : "[" LexOf "&" "]" "(" TypedParameters[parameters] ")" "->" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
;
/* }}} */
/* Cycript (C): Structure Definitions {{{ */
: "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: Java "Anonymous Inner Classes" {{{ */
+BracedParameter
+ : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYExtend(NULL, $properties); }
;
/* }}} */
+
/* JavaScript FTW: Ruby Blocks {{{ */
RubyProcParameterList_
: "," RubyProcParameterList[parameters] { $$ = $parameters; }
| { $$ = NULL; }
;
-RubyProcExpression
- : "{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
+BracedParameter
+ : ";{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyBlock(NULL, CYNew CYRubyProc($parameters, $code)); }
;
PrimaryExpression
: "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
;
-RubyBlockExpression_
+BracedExpression_
: AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
- | RubyBlockExpression_[lhs] RubyProcExpression[rhs] LexNewLineOrOpt { $$ = CYNew CYRubyBlock($lhs, $rhs); }
+ | BracedExpression_[lhs] { if (!$lhs->IsNew()) CYMAP(OpenBrace_, OpenBrace); } BracedParameter[rhs] LexNewLineOrOpt { $rhs->SetLeft($lhs); $$ = $rhs; }
;
-RubyBlockExpression
- : RubyBlockExpression_[pass] "\n" { $$ = $pass; }
- | RubyBlockExpression_[pass] { $$ = $pass; }
+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()); }
;
/* }}} */