-/* 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 { CYComprehension *comprehension_; }
%union { CYElement *element_; }
+%union { CYEnumConstant *constant_; }
%union { CYExpression *expression_; }
%union { CYFalse *false_; }
%union { CYVariable *variable_; }
%union { CYParenthetical *parenthetical_; }
%union { CYProperty *property_; }
%union { CYPropertyName *propertyName_; }
-%union { CYRubyProc *rubyProc_; }
+%union { CYTypeSigning signing_; }
%union { CYSpan *span_; }
%union { CYStatement *statement_; }
%union { CYString *string_; }
%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
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; \
case CYMarkModule:
driver.hold_ = yytranslate_(token::MarkModule);
break;
+ case CYMarkExpression:
+ driver.hold_ = yytranslate_(token::MarkExpression);
+ break;
}
};
%token SlashRight "/>"
%token LeftSlash "</"
-%token ColonColon "::"
%token PeriodPeriod ".."
@end
@begin E4X ObjectiveC
%token At "@"
-%token Pound "#"
@end
%token Ampersand "&"
%token Plus "+"
%token PlusEqual "+="
%token PlusPlus "++"
+%token QuestionPeriod "?."
%token Right ">"
%token RightEqual ">="
%token RightRight ">>"
%token Tilde "~"
%token Colon ":"
+%token ColonColon "::"
%token Comma ","
%token Question "?"
%token SemiColon ";"
+%token Pound "#"
%token NewLine "\n"
%token __ ""
%token _goto_ "goto"
%token _implements_ "implements"
%token _int_ "int"
+%token ___int128_ "__int128"
%token _interface_ "interface"
%token _let_ "let"
%token _let__ "!let"
%token ___proto___ "__proto__"
%token _prototype_ "prototype"
%token _public_ "public"
-%token ___restrict_ "__restrict"
-%token _restrict_ "restrict"
%token _set_ "set"
%token _short_ "short"
%token _static_ "static"
%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 <expression_> YieldExpression
@begin C
+%type <constant_> EnumConstantListOpt_
+%type <constant_> EnumConstantListOpt
+%type <number_> IntegerNumber
%type <integral_> IntegerType
%type <integral_> IntegerTypeOpt
-%type <typedIdentifier_> PrefixedType
+%type <typedName_> PrefixedType
+%type <specifier_> PrimitiveReference
%type <specifier_> PrimitiveType
%type <structField_> StructFieldListOpt
-%type <typedIdentifier_> SuffixedType
-%type <typedIdentifier_> SuffixedTypeOpt
-%type <typedIdentifier_> TypeSignifier
-%type <typedIdentifier_> TypeSignifierNone
-%type <typedIdentifier_> TypeSignifierOpt
+%type <typedName_> SuffixedType
+%type <typedName_> SuffixedTypeOpt
+%type <typedName_> TypeSignifier
+%type <typedName_> TypeSignifierNone
+%type <typedName_> TypeSignifierOpt
+%type <signing_> TypeSigning
%type <modifier_> ParameterTail
%type <modifier_> TypeQualifierLeft
%type <modifier_> TypeQualifierLeftOpt
-%type <typedIdentifier_> TypeQualifierRight
-%type <typedIdentifier_> TypeQualifierRightOpt
-%type <typedIdentifier_> TypedIdentifierDefinition
-%type <typedIdentifier_> TypedIdentifierEncoding
-%type <typedIdentifier_> TypedIdentifierField
-%type <typedIdentifier_> TypedIdentifierMaybe
-%type <typedIdentifier_> TypedIdentifierNo
-%type <typedIdentifier_> TypedIdentifierYes
-%type <typedParameter_> TypedParameterList_
-%type <typedParameter_> TypedParameterList
-%type <typedParameter_> TypedParameterListOpt
+%type <typedName_> TypeQualifierRight
+%type <typedName_> TypeQualifierRightOpt
+%type <typedName_> TypedIdentifierDefinition
+%type <typedThing_> TypedIdentifierEncoding
+%type <typedName_> TypedIdentifierField
+%type <typedName_> TypedIdentifierMaybe
+%type <typedLocation_> TypedIdentifierNo
+%type <typedName_> TypedIdentifierTagged
+%type <typedName_> TypedIdentifierYes
+%type <typedFormal_> TypedParameterList_
+%type <typedFormal_> TypedParameterList
+%type <typedFormal_> TypedParameterListOpt
+%type <typedParameter_> TypedParameters
@end
@begin ObjectiveC
%type <selector_> SelectorExpressionOpt
%type <argument_> SelectorList
%type <word_> SelectorWordOpt
-%type <typedIdentifier_> TypeOpt
+%type <typedThing_> TypeOpt
%type <argument_> VariadicCall
@end
/* 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 {{{ */
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"); }
;
| "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"); }
| "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"); }
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"); }
- | "__restrict" { $$ = CYNew CYIdentifier("__restrict"); }
- | "restrict" { $$ = CYNew CYIdentifier("restrict"); }
| "short" { $$ = CYNew CYIdentifier("short"); }
| "static" { $$ = CYNew CYIdentifier("static"); }
| "volatile" { $$ = CYNew CYIdentifier("volatile"); }
;
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); */ }
;
@begin C
/* Cycript (C): Type Encoding {{{ */
TypeSignifier
- : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); }
+ : 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 CYTypedIdentifier(@$); }
+ : { $$ = CYNew CYTypedName(@$); }
;
TypeSignifierOpt
| TypeSignifierNone[pass] { $$ = $pass; }
;
-Restrict
- : "__restrict"
- | "restrict"
- ;
-
-RestrictOpt
- : Restrict
- |
- ;
-
-ParameterModifier
- : "throw" "(" ")"
- ;
-
-ParameterModifierOpt
- : ParameterModifier
- |
- ;
-
ParameterTail
- : TypedParameterListOpt[parameters] ")" ParameterModifierOpt { $$ = CYNew CYTypeFunctionWith($parameters); }
+ : TypedParameterListOpt[formal] ")" { $$ = 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_); }
+ : 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 CYTypedIdentifier(@parenthesis); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
+ | "("[parenthesis] ParameterTail[modifier] { $$ = CYNew CYTypedName(@parenthesis); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
;
SuffixedTypeOpt
| PrefixedType[pass] { $$ = $pass; }
| "const" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
| "volatile" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
- | Restrict TypeQualifierRightOpt[typed] { $$ = $typed; }
;
TypeQualifierRightOpt
;
StructFieldListOpt
- : TypedIdentifierField[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $next); }
+ : 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; }
- | "char" { $$ = CYNew CYTypeCharacter(CYTypeNeutral); }
- | "signed" "char" { $$ = CYNew CYTypeCharacter(CYTypeSigned); }
- | "unsigned" "char" { $$ = CYNew CYTypeCharacter(CYTypeUnsigned); }
- | "struct" IdentifierType[name] { $$ = CYNew CYTypeReference($name); }
+ | 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(); }
+ ;
+
+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
- : 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; }
+ : TypeQualifierLeftOpt[modifier] PrimitiveReference[specifier] TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
;
TypedIdentifierYes
- : TypedIdentifierMaybe[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; }
+ : TypedIdentifierMaybe[typed] { if ($typed->name_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; }
;
TypedIdentifierNo
- : TypedIdentifierMaybe[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; }
+ : 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; }
- | 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; }
+ | TypedIdentifierTagged[typed] { if ($typed->name_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; }
;
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; }
+ | 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->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; $$->specifier_ = CYNew CYTypeStruct($name, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
+ | 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
;
ImplementationFieldListOpt
- : TypedIdentifierField[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
+ : TypedIdentifierField[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $typed->name_, $next); }
| { $$ = NULL; }
;
TypeOpt
: "(" TypedIdentifierNo[type] ")" { $$ = $type; }
- | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
+ | { $$ = 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
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
/* 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] { 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; }
- | "void" { $$ = NULL; }
- | { $$ = NULL; }
+ | { $$ = 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 {{{ */
;
PrimaryExpression
- : "(" LexOf "struct" NewLineOpt IdentifierType[name] TypeQualifierRightOpt[typed] ")" { $typed->specifier_ = CYNew CYTypeReference($name); $$ = CYNew CYTypeExpression($typed); }
+ : "(" 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 {{{ */
;
TypeDefinition
- : "typedef" NewLineNot TypedIdentifierDefinition[typed] TerminatorHard { $$ = CYNew CYTypeDefinition($typed); }
+ : "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__
;
ExternCStatement
- : TypedIdentifierField[typed] TerminatorHard { $$ = CYNew CYExternal(CYNew CYString("C"), $typed); }
+ : 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; }
;
| ExternCStatement[pass] { $$ = $pass; }
;
+ABI
+ : StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); }
+ ;
+
Statement__
- : "extern" NewLineNot StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } ExternC[pass] { $$ = $pass; }
+ : "extern" NewLineNot ABI[abi] ExternC[pass] { $$ = $pass; }
+ ;
+
+PrimaryExpression
+ : "(" LexOf "extern" NewLineOpt ABI[abi] TypedIdentifierField[typed] ")" { $$ = CYNew CYExternalExpression(CYNew CYString("C"), $typed, $typed->name_); }
;
/* }}} */
@end
: "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; }
| { $$ = 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()); }
;
/* }}} */