X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/aaa29c28ae45afad21be2891d38744d68d3c907e..6419a40fb7c8e1c92e2bb7a6691f071fbfa76e77:/Parser.ypp.in diff --git a/Parser.ypp.in b/Parser.ypp.in index 19e235f..0d8e87d 100644 --- a/Parser.ypp.in +++ b/Parser.ypp.in @@ -89,8 +89,10 @@ %union { CYTypeModifier *modifier_; } %union { CYTypeSpecifier *specifier_; } %union { CYTypedFormal *typedFormal_; } -%union { CYTypedIdentifier *typedIdentifier_; } +%union { CYTypedLocation *typedLocation_; } +%union { CYTypedName *typedName_; } %union { CYTypedParameter *typedParameter_; } +%union { CYType *typedThing_; } @end @begin ObjectiveC @@ -228,6 +230,9 @@ type; }) case CYMarkModule: driver.hold_ = yytranslate_(token::MarkModule); break; + case CYMarkExpression: + driver.hold_ = yytranslate_(token::MarkExpression); + break; } }; @@ -675,28 +680,28 @@ type; }) %type IntegerNumber %type IntegerType %type IntegerTypeOpt -%type PrefixedType +%type PrefixedType %type PrimitiveReference %type PrimitiveType %type StructFieldListOpt -%type SuffixedType -%type SuffixedTypeOpt -%type TypeSignifier -%type TypeSignifierNone -%type TypeSignifierOpt +%type SuffixedType +%type SuffixedTypeOpt +%type TypeSignifier +%type TypeSignifierNone +%type TypeSignifierOpt %type TypeSigning %type ParameterTail %type TypeQualifierLeft %type TypeQualifierLeftOpt -%type TypeQualifierRight -%type TypeQualifierRightOpt -%type TypedIdentifierDefinition -%type TypedIdentifierEncoding -%type TypedIdentifierField -%type TypedIdentifierMaybe -%type TypedIdentifierNo -%type TypedIdentifierTagged -%type TypedIdentifierYes +%type TypeQualifierRight +%type TypeQualifierRightOpt +%type TypedIdentifierDefinition +%type TypedIdentifierEncoding +%type TypedIdentifierField +%type TypedIdentifierMaybe +%type TypedIdentifierNo +%type TypedIdentifierTagged +%type TypedIdentifierYes %type TypedParameterList_ %type TypedParameterList %type TypedParameterListOpt @@ -732,7 +737,7 @@ type; }) %type SelectorExpressionOpt %type SelectorList %type SelectorWordOpt -%type TypeOpt +%type TypeOpt %type VariadicCall @end @@ -768,12 +773,14 @@ type; }) %start Program %token MarkModule %token MarkScript +%token MarkExpression %% Program : MarkScript Script | MarkModule Module + | MarkExpression Expression[expression] { driver.context_ = $expression; } ; /* Lexer State {{{ */ @@ -2022,12 +2029,14 @@ ExportSpecifier @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 @@ -2062,7 +2071,7 @@ SuffixedType : SuffixedTypeOpt[typed] "[" RestrictOpt NumericLiteral[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 @@ -2111,7 +2120,7 @@ IntegerTypeOpt ; StructFieldListOpt - : TypedIdentifierField[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $next); } + : TypedIdentifierField[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $typed->name_, $next); } | { $$ = NULL; } ; @@ -2147,6 +2156,8 @@ 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 @@ -2156,11 +2167,11 @@ TypedIdentifierMaybe ; 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 @@ -2170,18 +2181,18 @@ TypedIdentifierTagged TypedIdentifierField : TypedIdentifierYes[pass] { $$ = $pass; } - | TypedIdentifierTagged[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; } + | TypedIdentifierTagged[typed] { if ($typed->name_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; } ; TypedIdentifierEncoding : TypedIdentifierNo[pass] { $$ = $pass; } - | TypedIdentifierTagged[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; } + | TypedIdentifierTagged[typed] { if ($typed->name_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; } | "void" TypeSignifierNone[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); } ; 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; } | "void" TypeSignifier[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); } ; @@ -2200,7 +2211,7 @@ ClassSuperOpt ; ImplementationFieldListOpt - : TypedIdentifierField[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); } + : TypedIdentifierField[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $typed->name_, $next); } | { $$ = NULL; } ; @@ -2211,11 +2222,11 @@ MessageScope 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 @@ -2229,7 +2240,7 @@ MessageParameterListOpt MessageParameters : MessageParameterList[pass] { $$ = $pass; } - | Word[tag] { $$ = CYNew CYMessageParameter($tag, NULL); } + | Word[tag] { $$ = CYNew CYMessageParameter($tag); } ; ClassMessageDeclaration @@ -2411,7 +2422,7 @@ TypedParameterList_ ; TypedParameterList - : TypedIdentifierMaybe[typed] TypedParameterList_[formal] { $$ = $formal; $$->parameters_ = CYNew CYTypedParameter($typed, $$->parameters_); } + : 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); } ; @@ -2440,6 +2451,7 @@ Statement__ PrimaryExpression : "(" 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 {{{ */ @@ -2448,7 +2460,7 @@ IdentifierNoOf ; 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__ @@ -2465,7 +2477,7 @@ IdentifierNoOf ; ExternCStatement - : TypedIdentifierField[typed] TerminatorHard { $$ = CYNew CYExternalDefinition(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; } ; @@ -2488,7 +2500,7 @@ Statement__ ; PrimaryExpression - : "(" LexOf "extern" NewLineOpt ABI[abi] TypedIdentifierField[typed] ")" { $$ = CYNew CYExternalExpression(CYNew CYString("C"), $typed); } + : "(" LexOf "extern" NewLineOpt ABI[abi] TypedIdentifierField[typed] ")" { $$ = CYNew CYExternalExpression(CYNew CYString("C"), $typed, $typed->name_); } ; /* }}} */ @end