X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/a87d7060233fff3ecbbc29d0e7e978f3587684ab..561e7f1c23ea3804db1625ab806be939b4e9c5d1:/Cycript.yy.in diff --git a/Cycript.yy.in b/Cycript.yy.in index aa5f535..90588f7 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -39,8 +39,11 @@ #include "E4X/Syntax.hpp" @end +#include "Highlight.hpp" + typedef struct { bool newline_; + hi::Value highlight_; union { bool bool_; @@ -78,6 +81,8 @@ typedef struct { CYString *string_; CYThis *this_; CYTrue *true_; + CYTypeModifier *type_; + CYTypedIdentifier *typed_; CYWord *word_; @begin ObjectiveC @@ -225,6 +230,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %token AtImplementation "@implementation" %token AtImplementation_ ";@implementation" %token AtImport "@import" +%token AtEncode "@encode" %token AtEnd "@end" %token AtSelector "@selector" @end @@ -448,6 +454,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %type WithStatement %type Word %type WordOpt +%type Variable @begin ObjectiveC %type BoxableExpression @@ -464,12 +471,15 @@ int cylex(YYSTYPE *, cy::location *, void *); %type ClassProtocolListOpt %type ClassProtocols %type ClassProtocolsOpt +%type EncodedType %type MessageExpression %type MessageParameter %type MessageParameters %type MessageParameterList %type MessageParameterListOpt %type MessageScope +%type ModifiedType +%type PrefixedType %type SelectorCall_ %type SelectorCall %type SelectorExpression_ @@ -477,7 +487,9 @@ int cylex(YYSTYPE *, cy::location *, void *); %type SelectorExpressionOpt %type SelectorList %type SelectorWordOpt +%type SuffixedType %type TypeOpt +%type TypedIdentifier %type VariadicCall @end @@ -532,15 +544,15 @@ LexSetRegExp ; 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 @@ -713,9 +725,13 @@ ParentheticalOpt | { $$ = NULL; } ; +Variable + : Identifier { $$ = CYNew CYVariable($1); } + ; + PrimaryExpression : "this" { $$ = $1; } - | Identifier { $$ = CYNew CYVariable($1); } + | Variable { $$ = $1; } | Literal { $$ = $1; } | ArrayLiteral { $$ = $1; } | ObjectLiteral { $$ = $1; } @@ -1054,7 +1070,7 @@ StatementList StatementListOpt : StatementList { $$ = $1; } - | LexSetRegExp { $$ = NULL; } + | LexSetStatement LexSetRegExp { $$ = NULL; } ; StatementListItem @@ -1318,11 +1334,41 @@ ProgramBody ProgramBodyOpt : ProgramBody { $$ = $1; } - | { $$ = NULL; } + | LexSetStatement LexSetRegExp { $$ = NULL; } ; /* }}} */ @begin ObjectiveC +/* Cycript (Objective-C): Type Encoding {{{ */ +SuffixedType + : IdentifierOpt { $$ = CYNew CYTypedIdentifier($1); } + | "(" PrefixedType ")" { $$ = $2; } + | SuffixedType "[" NumericLiteral "]" { CYSetLast($1->type_) = CYNew CYTypeArrayOf($3->Value()); $$ = $1; } + ; + +PrefixedType + : SuffixedType { $$ = $1; } + | "const" PrefixedType { CYSetLast($2->type_) = CYNew CYTypeConstant(); $$ = $2; } + | "*" PrefixedType { CYSetLast($2->type_) = CYNew CYTypePointerTo(); $$ = $2; } + ; + +ModifiedType + : Variable { $$ = CYNew CYTypeVariable($1); } + | "const" ModifiedType { $$ = CYNew CYTypeConstant($2); } + ; + +TypedIdentifier + : ModifiedType PrefixedType { CYSetLast($2->type_) = $1; $$ = $2;} + ; + +EncodedType + : TypedIdentifier { $$ = CYNew CYEncodedType($1->type_); } + ; + +PrimaryExpression + : AtEncode "(" EncodedType ")" { $$ = $3; } + ; +/* }}} */ /* Cycript (Objective-C): @class Declaration {{{ */ ClassSuperOpt /* XXX: why the hell did I choose MemberExpression? */ @@ -1345,7 +1391,7 @@ MessageScope ; TypeOpt - : "(" Expression ")" { $$ = $2; } + : "(" EncodedType ")" { $$ = $2; } | "(" LexSetRegExp "void" ")" { $$ = CYNew CYString("v"); } | { $$ = NULL; } ; @@ -1491,7 +1537,7 @@ ImportPath ; StatementListItem - : "@import" ImportPath { $$ = CYNew CYImport(); } + : LexSetStatement LexSetRegExp "@import" ImportPath { $$ = CYNew CYImport(); } ; /* }}} */ /* Cycript (Objective-C): Boxed Expressions {{{ */