#include "E4X/Syntax.hpp"
@end
+#include "Highlight.hpp"
+
typedef struct {
bool newline_;
+ hi::Value highlight_;
union {
bool bool_;
CYMember *member_;
CYNull *null_;
CYNumber *number_;
+ CYEncodedPart *part_;
CYProgram *program_;
CYProperty *property_;
CYPropertyName *propertyName_;
CYString *string_;
CYThis *this_;
CYTrue *true_;
+ CYEncodedType *type_;
CYWord *word_;
@begin ObjectiveC
%token AtImplementation "@implementation"
%token AtImplementation_ ";@implementation"
%token AtImport "@import"
+%token AtEncode "@encode"
%token AtEnd "@end"
%token AtSelector "@selector"
@end
%token <true_> True "true"
// ES3/ES5/WIE/JSC Reserved
+%token <word_> Auto "auto"
%token <word_> Break "break"
%token <word_> Case "case"
%token <word_> Catch "catch"
%type <expression_> ArrowFunction
%type <functionParameter_> ArrowParameters
%type <expression_> AssignmentExpression
+%type <identifier_> Binding
%type <identifier_> BindingIdentifier
%type <expression_> BitwiseANDExpression
%type <statement_> Block_
%type <clause_> CaseClause
%type <clause_> CaseClausesOpt
%type <catch_> CatchOpt
+%type <comprehension_> ComprehensionForList
+%type <comprehension_> ComprehensionForListOpt
%type <comprehension_> ComprehensionList
%type <comprehension_> ComprehensionListOpt
%type <expression_> ConditionalExpression
%type <statement_> WithStatement
%type <word_> Word
%type <word_> WordOpt
+%type <expression_> Variable
@begin ObjectiveC
%type <expression_> BoxableExpression
%type <statement_> CategoryStatement
%type <expression_> ClassExpression
+%type <field_> ClassFieldListOpt
+%type <field_> ClassFields
%type <statement_> ClassStatement
%type <expression_> ClassSuperOpt
-%type <field_> ClassFieldList
%type <message_> ClassMessageDeclaration
%type <message_> ClassMessageDeclarationListOpt
%type <className_> ClassName
%type <messageParameter_> MessageParameterList
%type <messageParameter_> MessageParameterListOpt
%type <bool_> MessageScope
+%type <type_> ModifiedType
+%type <part_> PrefixedType
%type <argument_> SelectorCall_
%type <argument_> SelectorCall
%type <selector_> SelectorExpression_
%type <selector_> SelectorExpressionOpt
%type <argument_> SelectorList
%type <word_> SelectorWordOpt
+%type <part_> SuffixedType
%type <expression_> TypeOpt
+%type <type_> TypedIdentifier
%type <argument_> VariadicCall
@end
;
LexNoBrace
- : { if (yychar == yyempty_) driver.nobrace_ = true; else if (yychar == token::OpenBrace || yychar == token::OpenBrace_) yychar = token::OpenBrace__; }
+ : { if (yychar == yyempty_) driver.no_.OpenBrace = true; else if (yychar == token::OpenBrace || yychar == token::OpenBrace_) yychar = token::OpenBrace__; }
;
LexNoFunction
- : { if (yychar == token::Function) yychar = token::Function_; }
+ : { if (yychar == yyempty_) driver.no_.Function = true; else if (yychar == token::Function) yychar = token::Function_; }
;
LexNoAtImplementation
- : { if (yychar == token::AtImplementation) yychar = token::AtImplementation_; }
+ : { if (yychar == yyempty_) driver.no_.AtImplementation = true; else if (yychar == token::AtImplementation) yychar = token::AtImplementation_; }
;
LexSetStatement
: "{"
| "\n{"
;
+
+Var_
+ : "var"
+ ;
/* }}} */
/* 7.6 Identifier Names and Identifiers {{{ */
Word
: Identifier { $$ = $1; }
+ | "auto" { $$ = $1; }
| "break" NewLineOpt { $$ = $1; }
| "case" { $$ = $1; }
| "catch" { $$ = $1; }
| { $$ = NULL; }
;
+Variable
+ : Identifier { $$ = CYNew CYVariable($1); }
+ ;
+
PrimaryExpression
: "this" { $$ = $1; }
- | Identifier { $$ = CYNew CYVariable($1); }
+ | Variable { $$ = $1; }
| Literal { $$ = $1; }
| ArrayLiteral { $$ = $1; }
| ObjectLiteral { $$ = $1; }
| LexSetRegExp { $$ = NULL; }
;
/* }}} */
+/* 11.1.4.2 Array Comprehension {{{ */
+PrimaryExpression
+ : "[" LexPushInOff AssignmentExpression ComprehensionForList LexPopIn "]" { $$ = CYNew CYArrayComprehension($3, $4); }
+ ;
+
+ComprehensionForList
+ : "for" Binding "in" Expression ComprehensionForListOpt { $$ = CYNew CYForInComprehension($2, $4, $5); }
+ | "for" Binding "of" Expression ComprehensionForListOpt { $$ = CYNew CYForOfComprehension($2, $4, $5); }
+ ;
+
+ComprehensionForListOpt
+ : ComprehensionForList { $$ = $1; }
+ | "if" Expression { $$ = CYNew CYIfComprehension($2); }
+ | { $$ = NULL; }
+ ;
+/* }}} */
/* 11.1.5 Object Initialiser {{{ */
ObjectLiteral
: BRACE LexPushInOff PropertyDefinitionListOpt LexPopIn "}" { $$ = CYNew CYObject($3); }
StatementListOpt
: StatementList { $$ = $1; }
- | LexSetRegExp { $$ = NULL; }
+ | LexSetStatement LexSetRegExp { $$ = NULL; }
;
StatementListItem
: Identifier { $$ = $1; }
;
+Binding
+ : BindingIdentifier
+ ;
+
// XXX: BindingPattern
/* }}} */
/* 12.2.1 Let and Const Declarations {{{ */
/* }}} */
/* 12.2.2 Variable Statement {{{ */
VariableStatement
- : "var" VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
+ : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
;
VariableDeclarationList_
ForStatementInitialiser
: ExpressionOpt { $$ = $1; }
- | LexSetRegExp "var" VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
+ | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
;
/* }}} */
/* 12.6.4 The for-in and for-of Statements {{{ */
ForInStatementInitialiser
: LeftHandSideExpression { $$ = $1; }
- | LexSetRegExp "var" VariableDeclaration { $$ = $3; }
+ | LexSetRegExp Var_ VariableDeclaration { $$ = $3; }
;
/* }}} */
/* }}} */
/* 13.2 Arrow Function Definitions {{{ */
ArrowFunction
- : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFunctionExpression(NULL, $2, $5); }
+ : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
;
ArrowParameters
ProgramBodyOpt
: ProgramBody { $$ = $1; }
- | { $$ = NULL; }
+ | LexSetStatement LexSetRegExp { $$ = NULL; }
;
/* }}} */
@begin ObjectiveC
+/* Cycript (Objective-C): Type Encoding {{{ */
+SuffixedType
+ : { $$ = NULL; }
+ | "(" PrefixedType ")" { $$ = $2; }
+ | SuffixedType "[" NumericLiteral "]" { $$ = CYNew CYEncodedPart($1, "arrayOf", CYNew CYArgument($3)); }
+ ;
+
+PrefixedType
+ : SuffixedType { $$ = $1; }
+ | "*" PrefixedType { $$ = CYNew CYEncodedPart($2, "pointerTo"); }
+ ;
+
+ModifiedType
+ : Variable { $$ = CYNew CYEncodedType($1); }
+ | "const" ModifiedType { $2->base_ = CYNew CYCall(CYNew CYDirectMember($2->base_, CYNew CYString("constant"))); $$ = $2; }
+ ;
+
+TypedIdentifier
+ : ModifiedType PrefixedType { $1->parts_ = $2; $$ = $1;}
+ ;
+
+PrimaryExpression
+ : AtEncode "(" TypedIdentifier ")" { $$ = $3; }
+ ;
+/* }}} */
/* Cycript (Objective-C): @class Declaration {{{ */
ClassSuperOpt
/* XXX: why the hell did I choose MemberExpression? */
| { $$ = NULL; }
;
-ClassField
- : Expression Identifier ";"
+ClassFieldListOpt
+ : Expression Identifier ";" ClassFieldListOpt { $$ = CYNew CYField($1, $2, $4); }
+ | { $$ = NULL; }
;
-ClassFieldList
- : BRACE ClassFieldListOpt "}" { $$ = NULL; }
- ;
-
-ClassFieldListOpt
- : ClassFieldListOpt ClassField
- |
+ClassFields
+ : BRACE ClassFieldListOpt "}" { $$ = $2; }
;
MessageScope
;
TypeOpt
- : "(" Expression ")" { $$ = $2; }
- | "(" LexSetRegExp "void" ")" { $$ = NULL; }
+ : "(" TypedIdentifier ")" { $$ = $2; }
+ | "(" LexSetRegExp "void" ")" { $$ = CYNew CYString("v"); }
| { $$ = NULL; }
;
;
ClassExpression
- : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt LexPopIn "@end" { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
+ : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt LexPopIn "@end" { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
;
ClassStatement
- : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
+ : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
;
CategoryName
;
StatementListItem
- : "@import" ImportPath { $$ = CYNew CYImport(); }
+ : LexSetStatement LexSetRegExp "@import" ImportPath { $$ = CYNew CYImport(); }
;
/* }}} */
/* Cycript (Objective-C): Boxed Expressions {{{ */
| "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
;
/* }}} */
+/* Cycript (C): auto Compatibility {{{ */
+Var_
+ : "auto"
+ ;
+/* }}} */
@end
/* YUI: Documentation Comments {{{ */
;
ForComprehension
- : "for" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForInComprehension($4, $7); }
- | "for" "each" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForOfComprehension($5, $8); }
+ : "for" "(" Identifier "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
+ | "for" "each" "(" Identifier "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
;
ComprehensionList