« Return to Thread: Doublequotes and Backslashes...

Doublequotes and Backslashes...

by Bertram :: Rate this Message:

Reply to Author | View in Thread

Hello again,

I am new to Javacc, so there might be a very obvious solution to this.

I'm trying to parse a) "ABC\\" and b) "\\ABC" by somestuff() below. [<= both as they are, NOT escaped, 2 backslashes]
In case of:
a) the normalString() is used by javacc -> clearly not intended
b) there is an exception: Lexical error at line 1, column 1.  Encountered: "\\" (92), after : ""

------------------------------

options{
    IGNORE_CASE=false ;
    JAVA_UNICODE_ESCAPE= true ;
}
PARSER_BEGIN(Test)
package Mini;
public class Test {}
PARSER_END(Test)
TOKEN :
{
 < T_ASTERISK:          "*">
| < T_QUOTED:            ( (" ") ("\\\\") ("\\\"") ["a"-"z","A"-"Z","_","-","0"-"9",":"] )+ >
| < T_PROPERTY:          ( ["a"-"z","A"-"Z","_","-","0"-"9",":"] )+ >
}  
void somestuff():
{}
{ escapedQuoteString()
        | normalString()
        | <T_ASTERISK>
}
void escapedQuoteString():
{System.out.println("YEA");}
{
    <T_QUOTED>
}
void normalString():
{System.out.println("NO");}
{
        <T_PROPERTY>
}

------------------------------

Wasn't able to find anything usefull, on how to handle \\ and \" when expected as valid option in your input.

Any help much appreciated !!

Bertram

 « Return to Thread: Doublequotes and Backslashes...