]> git.saurik.com Git - cycript.git/blobdiff - Scanner.lpp.in
Avoid breaking normal down-arrow cursor semantics.
[cycript.git] / Scanner.lpp.in
index bcbd0d00d99e80e11c0f2a565099ce4a8466783d..139901104f1ed2dd029149b2312b5d20cee2402b 100644 (file)
@@ -52,6 +52,12 @@ typedef cy::parser::token tk;
     return value; \
 } while (false)
 
+#define S(stack) do { \
+    if (yyextra->stack.size() == 1) \
+        E("invalid brace") \
+    yyextra->stack.pop(); \
+} while (false)
+
 #define P yyextra->pool_
 #define A new(P)
 #define Y P.strmemdup(yytext, yyleng)
@@ -77,13 +83,13 @@ typedef cy::parser::token tk;
             nl = reinterpret_cast<const char *>(memchr(nl + 1, '\n', left)); \
         } while (nl != NULL); \
         yylloc->step(); \
-        yylloc->end.lines(lines); \
-        yylloc->end.columns(left); \
+        yylloc->end.Lines(lines); \
+        yylloc->end.Columns(left); \
         more \
     } else L \
 }
 
-#define R yylloc->end.columns(yyleng);
+#define R yylloc->end.Columns(yyleng);
 #define L yylloc->step(); R
 
 #define H(value, highlight) do { \
@@ -204,9 +210,6 @@ static void U(char *&local, const char *text, yy_size_t &i) {
 %option reentrant
 %option stack
 
-%option full
-%option ecs
-
 U1 [\x00-\x7f]
 U0 [\x80-\xbf]
 U2 [\xc2-\xdf]
@@ -263,8 +266,6 @@ XMLName {XMLNameStart}{XMLNamePart}*
 
 %s Div
 %s DivOrTemplateTail
-%s RegExp
-%s RegExpOrTemplateTail
 
 @begin E4X
 %x XMLContent
@@ -274,8 +275,6 @@ XMLName {XMLNameStart}{XMLNamePart}*
 %%
 
     /* RegEx {{{ */
-<RegExp,RegExpOrTemplateTail>\/ L CYLexBufferStart(RegularExpression); CYLexBufferUnit('/');
-
 <RegularExpression>{
     \/{UnicodePart}* R CYLexBufferUnits(yytext, yyleng); CYLexBufferEnd(literal, RegEx, tk::RegularExpressionLiteral, hi::Constant);
     \/{UnicodePart}*{UnicodeFail} R E("invalid flags")
@@ -303,7 +302,7 @@ XMLName {XMLNameStart}{XMLNamePart}*
 
 <MultiLine>{
     \**\*\/ R yy_pop_state(yyscanner); M N
-    \**{LineTerminatorSequence} yylloc->end.lines(); yyextra->last_ = true;
+    \**{LineTerminatorSequence} yylloc->end.Lines(); yyextra->last_ = true;
     \**{CommentCharacter}|\/ R
     \**({UnicodeFail}|\*) R E("invalid comment");
     <<EOF>> R E("invalid comment")
@@ -385,8 +384,8 @@ XMLName {XMLNameStart}{XMLNamePart}*
 "*="   L F(tk::StarEqual, hi::Operator);
 "~"    L F(tk::Tilde, hi::Operator);
 
-<Div,DivOrTemplateTail>"/"  L F(tk::Slash, hi::Operator);
-<Div,DivOrTemplateTail>"/=" L F(tk::SlashEqual, hi::Operator);
+"/"  L F(tk::Slash, hi::Operator);
+"/=" L F(tk::SlashEqual, hi::Operator);
 
 ":"    L F(tk::Colon, hi::Structure);
 ","    L F(tk::Comma, hi::Structure);
@@ -397,7 +396,7 @@ XMLName {XMLNameStart}{XMLNamePart}*
 ")"    L F(tk::CloseParen, hi::Structure);
 
 "{"    L yyextra->template_.push(false); F(yyextra->newline_ ? tk::OpenBrace_ : tk::OpenBrace, hi::Structure);
-<Div,RegExp>"}" L yyextra->template_.pop(); F(tk::CloseBrace, hi::Structure);
+<Div>"}" L S(template_); F(tk::CloseBrace, hi::Structure);
 
 "["    L F(tk::OpenBracket, hi::Structure);
 "]"    L F(tk::CloseBracket, hi::Structure);
@@ -450,6 +449,7 @@ XMLName {XMLNameStart}{XMLNamePart}*
 "char"            L /*FII*/ F(tk::_char_, hi::Type);
 "class"           L /*FFK*/ F(tk::_class_, hi::Meta);
 "const"           L /*FFK*/ F(tk::_const_, hi::Meta);
+"constructor"     L /*III*/ F(tk::_constructor_, hi::Special);
 "continue"        L /*KKK*/ F(tk::_continue_, hi::Control);
 "debugger"        L /*FKK*/ F(tk::_debugger_, hi::Meta);
 "default"         L /*KKK*/ F(tk::_default_, hi::Control);
@@ -484,12 +484,13 @@ XMLName {XMLNameStart}{XMLNamePart}*
 "package"         L /*FSS*/ F(tk::_package_, hi::Meta);
 "private"         L /*FSS*/ F(tk::_private_, hi::Meta);
 "protected"       L /*FSS*/ F(tk::_protected_, hi::Meta);
+"prototype"       L /*III*/ F(tk::_prototype_, hi::Special);
 "public"          L /*FSS*/ F(tk::_public_, hi::Meta);
 "return"          L /*KKK*/ F(yyextra->return_.top() ? tk::_return__ : tk::_return_, hi::Control);
 "set"             L /*III*/ F(tk::_set_, hi::Meta);
 "short"           L /*FII*/ F(tk::_short_, hi::Type);
 "static"          L /*FS?*/ F(tk::_static_, hi::Meta);
-"super"           L /*FFK*/ F(tk::_super_, hi::Constant);
+"super"           L /*FFK*/ F(yyextra->super_.top() ? tk::_super__ : tk::_super_, hi::Constant);
 "switch"          L /*KKK*/ F(tk::_switch_, hi::Control);
 "synchronized"    L /*FII*/ F(tk::_synchronized_, hi::Meta);
 "this"            L /*KKK*/ F(tk::_this_, hi::Constant);
@@ -579,7 +580,7 @@ XMLName {XMLNameStart}{XMLNamePart}*
     /* }}} */
     /* Template {{{ */
 "`" L yyextra->tail_ = false; CYLexBufferStart(StrictAccentString);
-<DivOrTemplateTail,RegExpOrTemplateTail>"}" L yyextra->tail_ = true; yyextra->template_.pop(); CYLexBufferStart(StrictAccentString);
+<DivOrTemplateTail>"}" L yyextra->tail_ = true; S(template_); CYLexBufferStart(StrictAccentString);
 
 <StrictAccentString>{
     "`" R CYLexBufferEnd(string, String, yyextra->tail_ ? tk::TemplateTail : tk::NoSubstitutionTemplate, hi::Constant);
@@ -623,7 +624,7 @@ XMLName {XMLNameStart}{XMLNamePart}*
         CYLexBufferPoint(point);
     }
 
-    \\{LineTerminatorSequence} yylloc->end.lines();
+    \\{LineTerminatorSequence} yylloc->end.Lines();
     \\(.|{NotLineTerminator}) R CYLexBufferUnits(yytext + 1, yyleng - 1);
 
     \\(x{HexDigit}{0,1}|u({HexDigit}{0,3}|\{{HexDigit}*)|{UnicodeFail})? R E("invalid escape");
@@ -631,7 +632,7 @@ XMLName {XMLNameStart}{XMLNamePart}*
 }
     /* }}} */
 
-{LineTerminatorSequence} yylloc->step(); yylloc->end.lines(); yyextra->last_ = true; N
+{LineTerminatorSequence} yylloc->step(); yylloc->end.Lines(); yyextra->last_ = true; N
 {WhiteSpace} L
 
 <<EOF>> if (yyextra->auto_) { yyextra->auto_ = false; F(tk::AutoComplete, hi::Nothing); } L yyterminate();
@@ -640,6 +641,10 @@ XMLName {XMLNameStart}{XMLNamePart}*
 
 %%
 
+#undef yyextra
+#define yyextra this
+#define yyscanner scanner_
+
 void CYDriver::ScannerInit() {
     cylex_init(&scanner_);
     cyset_extra(this, scanner_);
@@ -649,13 +654,17 @@ void CYDriver::ScannerDestroy() {
     cylex_destroy(scanner_);
 }
 
+void CYDriver::SetRegEx(bool equal) {
+    CYLexBufferStart(RegularExpression);
+    CYLexBufferUnit('/');
+    if (equal)
+        CYLexBufferUnit('=');
+}
+
 void CYDriver::SetCondition(Condition condition) {
     struct yyguts_t *yyg(reinterpret_cast<struct yyguts_t *>(scanner_));
 
     switch (condition) {
-        case RegExpCondition:
-            BEGIN(template_.top() ? RegExpOrTemplateTail : RegExp);
-            break;
 @begin E4X
         case XMLContentCondition:
             BEGIN(XMLContent);
@@ -671,9 +680,6 @@ void CYDriver::SetCondition(Condition condition) {
 
 void CYDriver::PushCondition(Condition condition) {
     switch (condition) {
-        case RegExpCondition:
-            yy_push_state(RegExp, scanner_);
-            break;
 @begin E4X
         case XMLContentCondition:
             yy_push_state(XMLContent, scanner_);