50 |
26 Feb 19 |
nicklas |
package org.json.simple.parser; |
50 |
26 Feb 19 |
nicklas |
2 |
|
50 |
26 Feb 19 |
nicklas |
3 |
%% |
50 |
26 Feb 19 |
nicklas |
4 |
|
50 |
26 Feb 19 |
nicklas |
5 |
%{ |
50 |
26 Feb 19 |
nicklas |
private StringBuffer sb=new StringBuffer(); |
50 |
26 Feb 19 |
nicklas |
7 |
|
50 |
26 Feb 19 |
nicklas |
int getPosition(){ |
50 |
26 Feb 19 |
nicklas |
return yychar; |
50 |
26 Feb 19 |
nicklas |
10 |
} |
50 |
26 Feb 19 |
nicklas |
11 |
|
50 |
26 Feb 19 |
nicklas |
12 |
%} |
50 |
26 Feb 19 |
nicklas |
13 |
|
50 |
26 Feb 19 |
nicklas |
%table |
50 |
26 Feb 19 |
nicklas |
%unicode |
50 |
26 Feb 19 |
nicklas |
%state STRING_BEGIN |
50 |
26 Feb 19 |
nicklas |
17 |
|
50 |
26 Feb 19 |
nicklas |
%yylexthrow ParseException |
50 |
26 Feb 19 |
nicklas |
%char |
50 |
26 Feb 19 |
nicklas |
20 |
|
50 |
26 Feb 19 |
nicklas |
HEX_D = [a-fA-F0-9] |
50 |
26 Feb 19 |
nicklas |
INT = [-]?[0-9]+ |
50 |
26 Feb 19 |
nicklas |
DOUBLE = {INT}((\.[0-9]+)?([eE][-+]?[0-9]+)?) |
50 |
26 Feb 19 |
nicklas |
WS = [ \t\r\n] |
50 |
26 Feb 19 |
nicklas |
UNESCAPED_CH = [^\"\\] |
50 |
26 Feb 19 |
nicklas |
FALLBACK_CH = . |
50 |
26 Feb 19 |
nicklas |
27 |
%% |
50 |
26 Feb 19 |
nicklas |
28 |
|
50 |
26 Feb 19 |
nicklas |
<STRING_BEGIN> \" { yybegin(YYINITIAL);return new Yytoken(Yytoken.TYPE_VALUE, sb.toString());} |
50 |
26 Feb 19 |
nicklas |
<STRING_BEGIN> {UNESCAPED_CH}+ { sb.append(yytext());} |
50 |
26 Feb 19 |
nicklas |
<STRING_BEGIN> \\\" {sb.append('"');} |
50 |
26 Feb 19 |
nicklas |
<STRING_BEGIN> \\\\ {sb.append('\\');} |
50 |
26 Feb 19 |
nicklas |
<STRING_BEGIN> \\\/ {sb.append('/');} |
50 |
26 Feb 19 |
nicklas |
<STRING_BEGIN> \\b {sb.append('\b');} |
50 |
26 Feb 19 |
nicklas |
<STRING_BEGIN> \\f {sb.append('\f');} |
50 |
26 Feb 19 |
nicklas |
<STRING_BEGIN> \\n {sb.append('\n');} |
50 |
26 Feb 19 |
nicklas |
<STRING_BEGIN> \\r {sb.append('\r');} |
50 |
26 Feb 19 |
nicklas |
<STRING_BEGIN> \\t {sb.append('\t');} |
50 |
26 Feb 19 |
nicklas |
<STRING_BEGIN> \\u{HEX_D}{HEX_D}{HEX_D}{HEX_D} { try{ |
50 |
26 Feb 19 |
nicklas |
int ch=Integer.parseInt(yytext().substring(2),16); |
50 |
26 Feb 19 |
nicklas |
sb.append((char)ch); |
50 |
26 Feb 19 |
nicklas |
42 |
} |
50 |
26 Feb 19 |
nicklas |
catch(Exception e){ |
50 |
26 Feb 19 |
nicklas |
throw new ParseException(yychar, ParseException.ERROR_UNEXPECTED_EXCEPTION, e); |
50 |
26 Feb 19 |
nicklas |
45 |
} |
50 |
26 Feb 19 |
nicklas |
46 |
} |
50 |
26 Feb 19 |
nicklas |
<STRING_BEGIN> \\ {sb.append('\\');} |
50 |
26 Feb 19 |
nicklas |
48 |
|
50 |
26 Feb 19 |
nicklas |
<YYINITIAL> \" { sb.delete(0, sb.length());yybegin(STRING_BEGIN);} |
50 |
26 Feb 19 |
nicklas |
<YYINITIAL> {INT} { Long val=Long.valueOf(yytext()); return new Yytoken(Yytoken.TYPE_VALUE, val);} |
50 |
26 Feb 19 |
nicklas |
<YYINITIAL> {DOUBLE} { Double val=Double.valueOf(yytext()); return new Yytoken(Yytoken.TYPE_VALUE, val);} |
50 |
26 Feb 19 |
nicklas |
<YYINITIAL> "true"|"false" { Boolean val=Boolean.valueOf(yytext()); return new Yytoken(Yytoken.TYPE_VALUE, val);} |
50 |
26 Feb 19 |
nicklas |
<YYINITIAL> "null" { return new Yytoken(Yytoken.TYPE_VALUE, null);} |
50 |
26 Feb 19 |
nicklas |
<YYINITIAL> "{" { return new Yytoken(Yytoken.TYPE_LEFT_BRACE,null);} |
50 |
26 Feb 19 |
nicklas |
<YYINITIAL> "}" { return new Yytoken(Yytoken.TYPE_RIGHT_BRACE,null);} |
50 |
26 Feb 19 |
nicklas |
<YYINITIAL> "[" { return new Yytoken(Yytoken.TYPE_LEFT_SQUARE,null);} |
50 |
26 Feb 19 |
nicklas |
<YYINITIAL> "]" { return new Yytoken(Yytoken.TYPE_RIGHT_SQUARE,null);} |
50 |
26 Feb 19 |
nicklas |
<YYINITIAL> "," { return new Yytoken(Yytoken.TYPE_COMMA,null);} |
50 |
26 Feb 19 |
nicklas |
<YYINITIAL> ":" { return new Yytoken(Yytoken.TYPE_COLON,null);} |
50 |
26 Feb 19 |
nicklas |
<YYINITIAL> {WS}+ {} |
50 |
26 Feb 19 |
nicklas |
<YYINITIAL> {FALLBACK_CH} { throw new ParseException(yychar, ParseException.ERROR_UNEXPECTED_CHAR, new Character(yycharat(0)));} |