1 /*--------------------------------------------------------------------------
\r
2 * Copyright 2007 Taro L. Saito
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
15 *--------------------------------------------------------------------------*/
\r
16 //--------------------------------------
\r
20 // Since: 2009/01/30
\r
22 //--------------------------------------
\r
34 //--------------------------------------
\r
37 // InLineJSONLexer.java
\r
38 // Since: Apr 26, 2007
\r
40 //--------------------------------------
\r
41 package org.xerial.silk.impl;
\r
45 public int nesting = 1; // json fragment begins with nesting
\r
50 //--------------------------------------
\r
53 // InLineJSONParser.java
\r
54 // Since: Apr 26, 2007
\r
56 //--------------------------------------
\r
57 package org.xerial.silk.impl;
\r
61 WhiteSpace: (' ' | '\r' | '\t' | '\u000C' | '\n') { $channel=HIDDEN; };
\r
63 fragment Digit: '0' .. '9';
\r
64 fragment Letter: 'A' .. 'F' | 'a' .. 'f';
\r
65 fragment HexDigit: Digit | Letter;
\r
66 fragment UnicodeChar: ~('"'| '\\');
\r
67 fragment EscapeSequence
\r
68 : '\\' ('\"' | '\\' | '/' | 'b' | 'f' | 'n' | 'r' | 't' | 'u' HexDigit HexDigit HexDigit HexDigit)
\r
71 fragment StringChar : UnicodeChar | EscapeSequence;
\r
73 fragment StringChar_s: StringChar*;
\r
74 String: '"' s=StringChar_s '"' { setText($s.text); };
\r
79 Integer: '-'? ('0' | '1'..'9' Digit*);
\r
80 fragment Frac: '.' Digit+;
\r
81 fragment Exp: ('e' | 'E') ('+' | '-')? Digit+;
\r
82 Double: Integer (Frac Exp? | Exp);
\r
84 LBrace: '{' { nesting++; } ;
\r
85 RBrace: '}' { nesting--; if (nesting<=0) { emit(Token.EOF_TOKEN); } };
\r
86 LBracket: '[' { nesting++; } ;
\r
87 RBracket: ']' { nesting--; if (nesting<=0) { emit(Token.EOF_TOKEN); } };
\r
90 fragment NameChar: Letter | Digit | '_' | '-' | '@' | '.';
\r
91 QName: (Letter | '_') NameChar*;
\r
96 jsonObjectFragment: jsonElement (Comma jsonElement)*;
\r
97 jsonArrayFragment: jsonValue (Comma jsonValue)*;
\r
99 jsonObject: LBrace jsonElement (',' jsonElement)* RBrace;
\r
100 jsonElement: String Colon jsonValue;
\r
101 jsonArray: LBracket jsonValue (',' jsonValue)* RBracket;
\r