%union { CYForInInitializer *forin_; }
%union { CYFunctionParameter *functionParameter_; }
%union { CYIdentifier *identifier_; }
+%union { CYImportSpecifier *import_; }
%union { CYInfix *infix_; }
%union { CYLiteral *literal_; }
%union { CYMethod *method_; }
%union { CYWord *word_; }
@begin C
+%union { CYTypeIntegral *integral_; }
+%union { CYTypeStructField *structField_; }
%union { CYTypeModifier *modifier_; }
%union { CYTypeSpecifier *specifier_; }
%union { CYTypedIdentifier *typedIdentifier_; }
%token _typedef_ "typedef"
%token _unsigned_ "unsigned"
%token _signed_ "signed"
+%token _struct_ "struct"
%token _extern_ "extern"
@end
%token _null_ "null"
%token _true_ "true"
+%token _as_ "as"
%token _break_ "break"
%token _case_ "case"
%token _catch_ "catch"
%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"
%type <expression_> ExpressionOpt
%type <for_> ExpressionStatement_
%type <statement_> ExpressionStatement
+%type <statement_> ExternC
+%type <statement_> ExternCStatement
+%type <statement_> ExternCStatementListOpt
%type <finally_> Finally
%type <binding_> ForBinding
%type <forin_> ForDeclaration
%type <functionParameter_> FormalParameterList_
%type <functionParameter_> FormalParameterList
%type <functionParameter_> FormalParameters
+%type <string_> FromClause
%type <statement_> FunctionBody
%type <statement_> FunctionDeclaration
%type <target_> FunctionExpression
%type <identifier_> IdentifierNoOf
%type <identifier_> IdentifierType
%type <identifier_> IdentifierTypeNoOf
+%type <identifier_> IdentifierTypeOpt
%type <word_> IdentifierName
%type <variable_> IdentifierReference
%type <statement_> IfStatement
+%type <import_> ImportClause
+%type <statement_> ImportDeclaration
+%type <import_> ImportSpecifier
+%type <identifier_> ImportedBinding
+%type <import_> ImportedDefaultBinding
+%type <import_> ImportsList_
+%type <import_> ImportsList
+%type <import_> ImportsListOpt
%type <target_> IndirectExpression
%type <expression_> Initializer
%type <expression_> InitializerOpt
%type <access_> MemberAccess
%type <target_> MemberExpression
%type <method_> MethodDefinition
+%type <statement_> ModuleBody
+%type <statement_> ModuleBodyOpt
+%type <statement_> ModuleItem
+%type <statement_> ModuleItemList
+%type <statement_> ModuleItemListOpt
%type <module_> ModulePath
+%type <string_> ModuleSpecifier
%type <expression_> MultiplicativeExpression
+%type <import_> NameSpaceImport
+%type <import_> NamedImports
%type <target_> NewExpression
%type <null_> NullLiteral
%type <literal_> ObjectLiteral
%type <bool_> RegularExpressionSlash
%type <expression_> RelationalExpression
%type <statement_> ReturnStatement
+%type <target_> RubyBlockExpression_
+%type <target_> RubyBlockExpression
%type <rubyProc_> RubyProcExpression
%type <functionParameter_> RubyProcParameterList_
%type <functionParameter_> RubyProcParameterList
%type <span_> TemplateSpans
%type <statement_> ThrowStatement
%type <statement_> TryStatement
+%type <statement_> TypeDefinition
%type <expression_> UnaryExpression_
%type <expression_> UnaryExpression
%type <binding_> VariableDeclaration
%type <expression_> YieldExpression
@begin C
-%type <specifier_> IntegerType
-%type <specifier_> IntegerTypeOpt
+%type <integral_> IntegerType
+%type <integral_> IntegerTypeOpt
%type <typedIdentifier_> PrefixedType
%type <specifier_> PrimitiveType
+%type <structField_> StructFieldListOpt
%type <typedIdentifier_> SuffixedType
+%type <typedIdentifier_> SuffixedTypeOpt
%type <typedIdentifier_> TypeSignifier
+%type <typedIdentifier_> TypeSignifierNone
+%type <typedIdentifier_> TypeSignifierOpt
+%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
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); };
| NewLineNot LexOf Terminator
;
+TerminatorHard
+ : ";"
+ | 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_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
IdentifierTypeNoOf
: Identifier_[pass] { $$ = $pass; }
| "abstract" { $$ = CYNew CYIdentifier("abstract"); }
+ | "as" { $$ = CYNew CYIdentifier("as"); }
| "await" { $$ = CYNew CYIdentifier("await"); }
| "boolean" { $$ = CYNew CYIdentifier("boolean"); }
| "byte" { $$ = CYNew CYIdentifier("byte"); }
| "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"); }
| "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"); }
;
SuperProperty
- : "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); }
- | "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
;
SuperCall
- : "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
+ : Super Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
;
Arguments
;
LeftHandSideExpression
- : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
+ : RubyBlockExpression[pass] { $$ = $pass; }
| IndirectExpression[pass] { $$ = $pass; }
;
/* }}} */
/* 12.4 Postfix Expressions {{{ */
PostfixExpression
- : AccessExpression[lhs] LexNewLineOrOpt { $$ = $lhs; }
+ : RubyBlockExpression[pass] { $$ = $pass; }
| AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); }
| AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); }
;
UnaryExpression
: PostfixExpression[expression] { $$ = $expression; }
- | PostfixExpression[expression] "\n" { $$ = $expression; }
| UnaryExpression_[pass] { $$ = $pass; }
;
/* }}} */
;
StatementList
- : StatementListItem[statement] StatementListOpt[next] { $statement->SetNext($next); $$ = $statement; }
+ : StatementListItem[statement] StatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
;
StatementListOpt
;
ForInStatementInitializer
- : LexLet LexOf AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
+ : LexLet LexOf RubyBlockExpression[pass] { $$ = $pass; }
| LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
| LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
| ForDeclaration[pass] { $$ = $pass; }
;
/* }}} */
/* 13.10 The return Statement {{{ */
-Return
- : "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); }
- ;
-
ReturnStatement
: Return TerminatorSoft { $$ = CYNew CYReturn(NULL); }
| Return NewLineNot Expression[value] Terminator { $$ = CYNew CYReturn($value); }
/* }}} */
/* 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 LexOf ImportDeclaration
- | LexSetStatement LexLet LexOf 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" LexOf ModuleSpecifier Terminator
+ : "import" ImportClause[specifiers] FromClause[module] Terminator { $$ = CYNew CYImportDeclaration($specifiers, $module); }
+ | "import" LexOf ModuleSpecifier[module] Terminator { $$ = CYNew CYImportDeclaration(NULL, $module); }
;
ImportClause
- : ImportedDefaultBinding
- | LexOf NameSpaceImport
- | LexOf 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
- : "{" 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
- | LexOf
+ : ImportsList[pass] { $$ = $pass; }
+ | LexOf { $$ = NULL; }
;
ImportSpecifier
- : ImportedBinding
- | LexOf 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 {{{ */
/* 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] PrimitiveType[specifier] TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
+ : 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_, "unexpected identifier"); $$ = $typed; }
;
+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" "(" TypedIdentifierMaybe[typed] ")" { $$ = CYNew CYEncodedType($typed); }
+ : "@encode" "(" TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYEncodedType($typed); }
;
/* }}} */
@end
;
ImplementationFieldListOpt
- : TypedIdentifierMaybe[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
+ : TypedIdentifierField[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
| { $$ = NULL; }
;
TypedParameterListOpt
: TypedParameterList[pass] { $$ = $pass; }
+ | "void" { $$ = NULL; }
| { $$ = NULL; }
;
PrimaryExpression
- : "[" LexOf "&" "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifierMaybe[type] "{" 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 {{{ */
: "typedef" NewLineOpt { $$ = CYNew CYIdentifier("typedef"); }
;
+TypeDefinition
+ : "typedef" NewLineNot TypedIdentifierDefinition[typed] TerminatorHard { $$ = CYNew CYTypeDefinition($typed); }
+ ;
+
Statement__
- : "typedef" NewLineNot TypedIdentifierYes[typed] Terminator { $$ = CYNew CYTypeDefinition($typed); }
+ : TypeDefinition[pass] { $$ = $pass; }
;
PrimaryExpression
- : "(" LexOf "typedef" NewLineOpt TypedIdentifierNo[typed] ")" { $$ = CYNew CYTypeExpression($typed); }
+ : "(" LexOf "typedef" NewLineOpt TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYTypeExpression($typed); }
;
/* }}} */
/* Cycript (C): extern "C" {{{ */
: "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" NewLineNot StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } TypedIdentifierYes[typed] 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
: "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
;
-PostfixExpression
- : PostfixExpression[lhs] RubyProcExpression[rhs] LexNewLineOrOpt { $$ = 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; }
;
/* }}} */