From b92ceddb344ea82a067100ab116ff59d7f7c96f3 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Fri, 30 Oct 2009 19:21:57 +0000 Subject: [PATCH] Mostly fixed the E4X situation, checkpointing for NoRE hell. --- Cycript.y.in | 55 +++++++++++++++++++++++++++++++------------------- E4X/Syntax.hpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ makefile | 2 +- todo.txt | 3 ++- 4 files changed, 92 insertions(+), 23 deletions(-) diff --git a/Cycript.y.in b/Cycript.y.in index a77265f..1789d47 100644 --- a/Cycript.y.in +++ b/Cycript.y.in @@ -51,7 +51,7 @@ @end @begin E4X -#include "E4X.hpp" +#include "E4X/Syntax.hpp" @end typedef struct { @@ -103,6 +103,8 @@ typedef struct { @begin E4X CYAttribute *attribute_; + CYPropertyIdentifier *propertyIdentifier_; + CYSelector *selector_; @end }; } YYSTYPE; @@ -437,6 +439,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type PrimaryExpressionBF %type Program %type PropertyName +%type PropertyName_ %type PropertyNameAndValueList %type PropertyNameAndValueList_ %type PropertyNameAndValueListOpt @@ -504,9 +507,9 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); @end @begin E4X -%type PropertyIdentifier_ -%type PropertySelector -%type PropertySelector_ +%type PropertyIdentifier_ +%type PropertySelector +%type PropertySelector_ %type QualifiedIdentifier %type QualifiedIdentifier_ %type WildcardIdentifier @@ -518,13 +521,22 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type XMLPI %type AttributeIdentifier -%type DefaultXMLNamespaceStatement +/* XXX: %type DefaultXMLNamespaceStatement */ %type PropertyIdentifier %type XMLListInitialiser %type XMLInitialiser @end -/* +%token WC + +%nonassoc Identifier_ "abstract" "boolean" "break" "byte" "case" "catch" "char" "class" "const" "continue" "debugger" "default" "delete" "do" "double" "each" "enum" "export" "extends" "false" "final" "finally" "float" /*"for"*/ "function" "goto" "implements" "import" /*"in"*/ /*"instanceof"*/ "int" "interface" "let" "long" "namespace" "native" "new" "null" "package" "private" "protected" "public" "return" "short" "super" "static" "switch" "synchronized" "this" "throw" "throws" "transient" "true" "try" "typeof" "var" "void" "volatile" "while" "with" "xml" "yield" + +%nonassoc "if" +%nonassoc "else" + +%nonassoc "++" "--" +%nonassoc "(" "[" + %left "*" "/" "%" %left "+" "-" %left "<<" ">>" ">>>" @@ -537,10 +549,6 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %left "||" %right "=" "*=" "/=" "%=" "+=" "-=" "<<=" ">>=" ">>>=" "&=" "^=" "|=" -*/ - -%nonassoc "if" -%nonassoc "else" %start Program @@ -672,6 +680,7 @@ LiteralNoRE | BooleanLiteral { $$ = $1; } | NumericLiteral { $$ = $1; } | StringLiteral { $$ = $1; } + | "@" StringLiteral { $$ = $2; } ; LiteralRE @@ -771,11 +780,15 @@ PropertyNameAndValueList : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = new(driver.pool_) CYProperty($1, $3, $4); } ; -PropertyName +PropertyName_ : Identifier { $$ = $1; } | StringLiteral { $$ = $1; } | NumericLiteral { $$ = $1; } ; + +PropertyName + : LexSetRegExp PropertyName_ { $$ = $2; } + ; /* }}} */ /* 11.2 Left-Hand-Side Expressions {{{ */ @@ -802,7 +815,7 @@ MemberExpressionNoBF ; MemberExpressionNoWC - : PrimaryExpressionNoWC { $$ = $1; } + : PrimaryExpression { $$ = $1; } | FunctionExpression { $$ = $1; } | MemberExpression MemberAccess { $2->SetLeft($1); $$ = $2; } | LexSetRegExp MemberExpression_ { $$ = $2; } @@ -957,7 +970,7 @@ AdditiveExpressionNoBF ; AdditiveExpressionNoWC - : MultiplicativeExpressionNoWC{ $$ = $1; } + : MultiplicativeExpressionNoWC { $$ = $1; } | AdditiveExpression "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); } | AdditiveExpression "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); } ; @@ -1726,7 +1739,7 @@ XMLMarkup /* }}} */ /* 11.1 Primary Expressions {{{ */ PrimaryExpressionWC - : PropertyIdentifier { $$ = $1; } + : PropertyIdentifier { $$ = new(driver.pool_) CYPropertyVariable($1); } | XMLInitialiser { $$ = $1; } | XMLListInitialiser { $$ = $1; } ; @@ -1743,23 +1756,23 @@ AttributeIdentifier ; PropertySelector_ - : PropertySelector - | "[" Expression "]" + : PropertySelector { $$ = $1; } + | "[" Expression "]" { $$ = new(driver.pool_) CYSelector($2); } ; PropertySelector - : Identifier { $$ = $1; } + : Identifier { $$ = new(driver.pool_) CYSelector($1); } | WildcardIdentifier { $$ = $1; } ; /* }}} */ /* 11.1.2 Qualified Identifiers {{{ */ QualifiedIdentifier_ - : PropertySelector_ { $$ = $1; } + : PropertySelector_ { $$ = new(driver.pool_) CYQualified(NULL, $1); } | QualifiedIdentifier { $$ = $1; } ; QualifiedIdentifier - : PropertySelector "::" PropertySelector_ { $$ = new(driver.pool_) CYQName($1, $3); } + : PropertySelector "::" PropertySelector_ { $$ = new(driver.pool_) CYQualified($1, $3); } ; /* }}} */ /* 11.1.3 Wildcard Identifiers {{{ */ @@ -1840,13 +1853,13 @@ MemberAccess ; /* }}} */ /* 12.1 The default xml namespace Statement {{{ */ -DefaultXMLNamespaceStatement +/* XXX: DefaultXMLNamespaceStatement : "default" "xml" "namespace" "=" Expression Terminator { $$ = new(driver.pool_) CYDefaultXMLNamespace($5); } ; Statement_ : DefaultXMLNamespaceStatement { $$ = $1; } - ; + ; */ /* }}} */ @end diff --git a/E4X/Syntax.hpp b/E4X/Syntax.hpp index 921db02..9bec64d 100644 --- a/E4X/Syntax.hpp +++ b/E4X/Syntax.hpp @@ -56,4 +56,59 @@ struct CYDefaultXMLNamespace : virtual void Output(CYOutput &out, CYFlags flags) const; }; +struct CYPropertyIdentifier { +}; + +struct CYSelector +{ +}; + +struct CYWildcard : + CYPropertyIdentifier, + CYSelector +{ + virtual CYExpression *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + +struct CYQualified : + CYPropertyIdentifier +{ + CYSelector *namespace_; + CYSelector *name_; + + CYQualified(CYSelector *_namespace, CYSelector *name) : + namespace_(_namespace), + name_(name) + { + } +}; + +struct CYPropertyVariable : + CYExpression +{ + CYPropertyIdentifier *identifier_; + + CYPropertyVariable(CYPropertyIdentifier *identifier) : + identifier_(identifier) + { + } + + CYPrecedence(0) + + virtual CYExpression *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + +struct CYAttribute : + CYPropertyIdentifier +{ + CYQualified *identifier_; + + CYAttribute(CYQualified *identifier) : + identifier_(identifier) + { + } +}; + #endif/*CYCRIPT_E4X_SYNTAX_HPP*/ diff --git a/makefile b/makefile index 18cea08..3e3006d 100644 --- a/makefile +++ b/makefile @@ -26,7 +26,7 @@ code += Cycript.tab.o lex.cy.o code += Network.o Parser.o code += JavaScriptCore.o Library.o -filters := C #E4X +filters := C E4X ldid := true dll := so apr := $(shell apr-1-config --link-ld) diff --git a/todo.txt b/todo.txt index 0528bbb..be2776a 100644 --- a/todo.txt +++ b/todo.txt @@ -6,4 +6,5 @@ look into what String is, and whether to bridge it the console frontend's error handling, well, doesn't setup a default hook mechanism for ffi_call passthrough some JS callbacks don't use exception pointers at all... -PropertyName may need a LexSetRegExp before it +a newline needs to not be allowed after a unary * +finish implementing default xml namespace statement -- 2.47.2