Syntax Error when using JFLEX

Hi,

can any body please tell me why

(?<=(<%))[^']+(?=(%>))

gives an syntax error when transformed via jflex

I want to get the content in between  <% %>

tags. Regular expression seems to work when I checked with http://rubular.com/

Eg:
content not wanted <% needed content %>content not wanted

below is the error:




Error in file "/home/amila/jagtest2/jaggery.flex" (line 73):
Syntax error.
    (?<=('<%'))[^']+(?=('%>'))  { return JaggeryTokenTypes.JAVASCRIPT_TEXT;}
              ^

Error in file "/home/amila/jagtest2/jaggery.flex" (line 73):
Syntax error.
    (?<=('<%'))[^']+(?=('%>'))  { return JaggeryTokenTypes.JAVASCRIPT_TEXT;}
                     ^

Error in file "/home/amila/jagtest2/jaggery.flex" (line 73):
Syntax error.
    (?<=('<%'))[^']+(?=('%>'))  { return JaggeryTokenTypes.JAVASCRIPT_TEXT;}


Thanks .. !!

2 comments
Comment actions Permalink

I won't go into whether you should be creating chameleon tokens or not - that would depend on what you are doing, though I think you probably should look into it at least.

You have to create tokens such that they cover all of the text. You can't skip any.

Here is a way you could do it - it may not be the best, but hopefully, it will get you started.

%x DATA

"<%" { yybegin(DATA); return JaggeryTokenTypes.BEGIN_JS; }
<DATA> [^%]* {  return JaggeryTokenTypes.JAVASCRIPT_TEXT; } <DATA> "%>" { yybegin(YYINITIAL); return JaggeryTokenTypes.END_JS }
<DATA> .  { yybegin(YYINITIAL); return JaggeryTokenTypes.BAD_TOKEN; }



Also, I don't think you need all those single quotes and parens in your regex

(?<=<%)[^%]*(?=%>)

0
Comment actions Permalink

Hi,

Thanks you very much for your help. I could manage it working adding

  "<%"   { yybegin(TAG_STARTED);return JaggeryTokenTypes.OUTERBRACKETS;  }
     [^<%]*  {yybegin(YYINITIAL);return JaggeryTokenTypes.BAD_CHARACTER;}

in  <YYINITIAL> state. Other wise if I edit over  the very first bracket, highlighting of the first line after that  bracket get distorted.

Thanks..

0

Please sign in to leave a comment.