-/* Cycript - Optimizing JavaScript Compiler/Runtime
- * Copyright (C) 2009-2015 Jay Freeman (saurik)
+/* Cycript - The Truly Universal Scripting Language
+ * Copyright (C) 2009-2016 Jay Freeman (saurik)
*/
/* GNU Affero General Public License, Version 3 {{{ */
#include "Driver.hpp"
#include "Parser.hpp"
#include "Stack.hpp"
+#include "Syntax.hpp"
#define CYNew new(driver.pool_)
@begin ObjectiveC
%union { 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_; }
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; \
@begin E4X ObjectiveC
%token At "@"
-%token Pound "#"
@end
%token Ampersand "&"
%token Comma ","
%token Question "?"
%token SemiColon ";"
+%token Pound "#"
%token NewLine "\n"
%token __ ""
%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
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
;
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; }
: 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_
| { $$ = 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 {{{ */