#define YY_EXTRA_TYPE CYDriver *
-#define T yylval->newline_ = yyextra->state_ == CYNewLine;
+#define T yylval->newline_ = yyextra->state_ == CYNewLine; BEGIN(Div);
#define C T yyextra->state_ = CYClear;
#define R T yyextra->state_ = CYRestricted;
-#define E(prefix) L C BEGIN(INITIAL); { \
+#define E(prefix) L C { \
char *value(reinterpret_cast<char *>(apr_palloc(yyextra->pool_, yyleng + sizeof(prefix)))); \
memcpy(value, prefix, sizeof(prefix) - 1); \
memcpy(value + sizeof(prefix) - 1, yytext, yyleng); \
RegularExpressionChar [^\n\\/]|{BackslashSequence}
RegularExpressionFlags {IdentifierPart}*
RegularExpressionChars {RegularExpressionChar}*
-RegularExpressionBody_ {RegularExpressionChars}
-RegularExpressionBody {RegularExpressionFirstChar}{RegularExpressionBody_}
+RegularExpressionBody {RegularExpressionFirstChar}{RegularExpressionChars}
-RegularExpressionEnd_ \/{RegularExpressionFlags}
-RegularExpressionRest_ {RegularExpressionBody_}{RegularExpressionEnd_}
-RegularExpressionStart_ {RegularExpressionBody}{RegularExpressionEnd_}
-
-%x RegExp
-%x RegExpSlash
-%x RegExpSlashEqual
-%x RegExpSlashRight
+%s Div
+%s RegExp
%%
-<RegExpSlash>{RegularExpressionStart_} E("/")
-<RegExpSlashEqual>{RegularExpressionRest_} E("/=")
-<RegExpSlashRight>{RegularExpressionRest_} E("/>")
+<RegExp>\/{RegularExpressionBody}\/{RegularExpressionFlags} E("")
\/\/[^\n]* L
\/\*(\n|[^\*]|\*[^/])*\*\/ M
">>=" L C return tk::RightRightEqual;
">>>" L C return tk::RightRightRight;
">>>=" L C return tk::RightRightRightEqual;
-"/" L C return tk::Slash;
-"/=" L C return tk::SlashEqual;
"*" L C return tk::Star;
"*=" L C return tk::StarEqual;
"~" L C return tk::Tilde;
+<Div>"/" L C return tk::Slash;
+<Div>"/=" L C return tk::SlashEqual;
+
":" L C return tk::Colon;
"," L C return tk::Comma;
"?" L C return tk::Question;
"each" L C yylval->identifier_ = new(yyextra->pool_) CYIdentifier("each"); return tk::Each;
-{IdentifierStart}{IdentifierPart}* yylval->identifier_ = new(yyextra->pool_) CYIdentifier(apr_pstrmemdup(yyextra->pool_, yytext, yyleng)); L C return tk::Identifier_;
+{IdentifierStart}{IdentifierPart}* L C yylval->identifier_ = new(yyextra->pool_) CYIdentifier(apr_pstrmemdup(yyextra->pool_, yytext, yyleng)); return tk::Identifier_;
-(\.[0-9]+|(0|[1-9][0-9]*)(\.[0-9]*)?){Exponent}? yylval->number_ = new(yyextra->pool_) CYNumber(strtod(yytext, NULL)); L C return tk::NumericLiteral;
+(\.[0-9]+|(0|[1-9][0-9]*)(\.[0-9]*)?){Exponent}? L C yylval->number_ = new(yyextra->pool_) CYNumber(strtod(yytext, NULL)); return tk::NumericLiteral;
0[xX][0-9a-fA-F]+ L C yylval->number_ = new(yyextra->pool_) CYNumber(strtoull(yytext + 2, NULL, 16)); return tk::NumericLiteral;
cylex_destroy(scanner_);
}
-void CYDriver::SetCondition(Condition condition) {
+void CYDriver::BeginCondition(Condition condition) {
struct yyguts_t *yyg(reinterpret_cast<struct yyguts_t *>(scanner_));
switch (condition) {
- case RegExpSlash:
- BEGIN(RegExpSlash);
- break;
- case RegExpSlashEqual:
- BEGIN(RegExpSlashEqual);
- break;
- case RegExpSlashRight:
- BEGIN(RegExpSlashRight);
+ case RegExpCondition:
+ BEGIN(RegExp);
break;
default:
_assert(false);
%type <argument_> Arguments
%type <literal_> ArrayLiteral
%type <expression_> AssigneeExpression
-%type <expression_> AssigneeExpression_
%type <expression_> AssigneeExpressionNoBF
%type <expression_> AssignmentExpression
%type <assignment_> AssignmentExpression_
%type <expression_> PrimaryExpression
%type <expression_> PrimaryExpression_
%type <expression_> PrimaryExpressionNoBF
+%type <expression_> PrimaryExpressionNoBF_
%type <statement_> Program
%type <propertyName_> PropertyName
%type <property_> PropertyNameAndValueList
%type <property_> PropertyNameAndValueList_
%type <property_> PropertyNameAndValueListOpt
-%type <literal_> RegularExpressionLiteral_
-%type <condition_> RegularExpressionToken
%type <expression_> RelationalExpression
%type <infix_> RelationalExpression_
%type <expression_> RelationalExpressionNoBF
%type <expression_> ShiftExpression
%type <expression_> ShiftExpressionNoBF
%type <statement_> SourceElement
+%type <statement_> SourceElement_
%type <statement_> SourceElements
%type <statement_> Statement
%type <statement_> Statement_
%type <statement_> SwitchStatement
%type <statement_> ThrowStatement
%type <statement_> TryStatement
+%type <expression_> UnaryAssigneeExpression
%type <expression_> UnaryExpression
%type <expression_> UnaryExpression_
%type <expression_> UnaryExpressionNoBF
| { $$ = NULL; }
;
-RegularExpressionToken
- : "/" { $$ = CYDriver::RegExpSlash; }
- | "/=" { $$ = CYDriver::RegExpSlashEqual; }
-@begin E4X
- | "/>" { $$ = CYDriver::RegExpSlashRight; }
-@end
- ;
-
-RegularExpressionLiteral_
- : RegularExpressionToken { driver.SetCondition($1); } RegularExpressionLiteral { $$ = $3; }
- ;
-
Literal
: NullLiteral { $$ = $1; }
| BooleanLiteral { $$ = $1; }
| NumericLiteral { $$ = $1; }
| StringLiteral { $$ = $1; }
- | RegularExpressionLiteral_ { $$ = $1; }
+ | RegularExpressionLiteral { $$ = $1; }
;
NullLiteral
/* 11.1 Primary Expressions {{{ */
PrimaryExpression_
+ : ObjectLiteral { $$ = $1; }
+ | PrimaryExpressionNoBF_ { $$ = $1; }
+ ;
+
+PrimaryExpressionNoBF_
: "this" { $$ = $1; }
| Identifier { $$ = new(driver.pool_) CYVariable($1); }
| Literal { $$ = $1; }
| "(" Expression ")" { $$ = $2; }
;
+LexBeginRegExp
+ : { driver.BeginCondition(CYDriver::RegExpCondition); }
+ ;
+
PrimaryExpression
- : ObjectLiteral { $$ = $1; }
- | PrimaryExpression_ { $$ = $1; }
+ : LexBeginRegExp PrimaryExpression_ { $$ = $2; }
;
PrimaryExpressionNoBF
- : PrimaryExpression_ { $$ = $1; }
+ : PrimaryExpressionNoBF_ { $$ = $1; }
;
/* }}} */
/* 11.1.4 Array Initialiser {{{ */
ElementOpt
: Element { $$ = $1; }
- | { $$ = NULL; }
+ | LexBeginRegExp { $$ = NULL; }
;
ElementListOpt
: ElementList { $$ = $1; }
- | { $$ = NULL; }
+ | LexBeginRegExp { $$ = NULL; }
;
ElementList
: PrimaryExpression { $$ = $1; }
| FunctionExpression { $$ = $1; }
| MemberExpression MemberAccess { $2->SetLeft($1); $$ = $2; }
- | MemberExpression_ { $$ = $1; }
+ | LexBeginRegExp MemberExpression_ { $$ = $2; }
;
MemberExpressionNoBF
NewExpression
: MemberExpression { $$ = $1; }
- | NewExpression_ { $$ = $1; }
+ | LexBeginRegExp NewExpression_ { $$ = $2; }
;
NewExpressionNoBF
ArgumentListOpt
: ArgumentList { $$ = $1; }
- | { $$ = NULL; }
+ | LexBeginRegExp { $$ = NULL; }
;
ArgumentList
UnaryExpression
: PostfixExpression { $$ = $1; }
- | UnaryExpression_ { $$ = $1; }
+ | LexBeginRegExp UnaryExpression_ { $$ = $2; }
;
UnaryExpressionNoBF
AssigneeExpression
: LeftHandSideExpression { $$ = $1; }
- | AssigneeExpression_ { $$ = $1; }
+ | LexBeginRegExp UnaryAssigneeExpression { $$ = $2; }
;
AssigneeExpressionNoBF
: LeftHandSideExpressionNoBF { $$ = $1; }
- | AssigneeExpression_ { $$ = $1; }
+ | UnaryAssigneeExpression { $$ = $1; }
;
AssignmentExpression
ExpressionOpt
: Expression { $$ = $1; }
- | { $$ = NULL; }
+ | LexBeginRegExp { $$ = NULL; }
;
ExpressionNoInOpt
: ExpressionNoIn { $$ = $1; }
- | { $$ = NULL; }
+ | LexBeginRegExp { $$ = NULL; }
;
Expression
;
Statement
- : Statement_ { $$ = $1; }
+ : LexBeginRegExp Statement_ { $$ = $2; }
;
/* }}} */
/* 12.1 Block {{{ */
StatementListOpt
: StatementList { $$ = $1; }
- | { $$ = NULL; }
+ | LexBeginRegExp { $$ = NULL; }
;
/* }}} */
/* 12.2 Variable Statement {{{ */
ForStatementInitialiser
: ExpressionNoInOpt { $$ = $1; }
- | "var" VariableDeclarationListNoIn { $$ = $2; }
+ | LexBeginRegExp "var" VariableDeclarationListNoIn { $$ = $3; }
;
/* }}} */
/* 12.6.4 The for-in Statement {{{ */
ForInStatementInitialiser
: LeftHandSideExpression { $$ = $1; }
- | "var" VariableDeclarationNoIn { $$ = $2; }
+ | LexBeginRegExp "var" VariableDeclarationNoIn { $$ = $3; }
;
/* }}} */
;
FunctionExpression
- : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionExpression($2, $4, $7); }
+ : LexBeginRegExp "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionExpression($3, $5, $8); }
;
FormalParameterList_
SourceElements
: SourceElement SourceElements { $1->SetNext($2); $$ = $1; }
- | { $$ = NULL; }
+ | LexBeginRegExp { $$ = NULL; }
;
-SourceElement
+SourceElement_
: Statement_ { $$ = $1; }
| FunctionDeclaration { $$ = $1; }
;
+
+SourceElement
+ : LexBeginRegExp SourceElement_ { $$ = $2; }
+ ;
/* }}} */
@begin ObjectiveC
/* Cycript (Objective-C): @class Declaration {{{ */
ClassSuperOpt
- : ":" MemberExpressionNoBF { $$ = $2; }
+ /* XXX: why the hell did I choose MemberExpressionNoBF? */
+ : ":" LexBeginRegExp MemberExpressionNoBF { $$ = $3; }
| { $$ = NULL; }
;
: "@class" ClassName ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYCategory($2, $3); }
;
-PrimaryExpression
+PrimaryExpression_
: ClassExpression { $$ = $1; }
;
MessageExpression
: "[" AssignmentExpression SelectorList "]" { $$ = new(driver.pool_) CYSendDirect($2, $3); }
- | "[" "super" SelectorList "]" { $$ = new(driver.pool_) CYSendSuper($3); }
+ | "[" LexBeginRegExp "super" SelectorList "]" { $$ = new(driver.pool_) CYSendSuper($4); }
;
SelectorExpressionOpt
| Word { $$ = new(driver.pool_) CYSelectorPart($1, false, NULL); }
;
-PrimaryExpression_
+PrimaryExpressionNoBF_
: MessageExpression { $$ = $1; }
| "@selector" "(" SelectorExpression ")" { $$ = new(driver.pool_) CYSelector($3); }
;
@begin C
/* Cycript (C): Pointer Indirection/Addressing {{{ */
-AssigneeExpression_
+UnaryAssigneeExpression
: "*" UnaryExpression { $$ = new(driver.pool_) CYIndirect($2); }
;
;
/* }}} */
/* 11.1 Primary Expressions {{{ */
-PrimaryExpression_
+PrimaryExpressionNoBF_
: PropertyIdentifier
| XMLInitialiser
| XMLListInitialiser
: ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; }
;
-PrimaryExpression_
+PrimaryExpressionNoBF_
: "[" AssignmentExpression ComprehensionList "]" { $$ = new(driver.pool_) CYArrayComprehension($2, $3); }
;
/* }}} */
: "let" "(" VariableDeclarationList ")" Block_ { $$ = new(driver.pool_) CYLet($3, $5); }
;
-Statement
+Statement_
: LetStatement
;
*//* }}} */
/* JavaScript FTW: Function Statements {{{ */
Statement
- : FunctionDeclaration { driver.Warning(yylloc, "warning, FunctionDeclaration is a SourceElement, not a Statement"); } { $$ = $1; }
+ : LexBeginRegExp FunctionDeclaration { driver.Warning(yylloc, "warning, FunctionDeclaration is a SourceElement, not a Statement"); } { $$ = $2; }
;
/* }}} */