Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: petitparser/lib/src/json/grammar.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « petitparser/lib/src/debug/trace.dart ('k') | petitparser/lib/src/json/parser.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 part of json;
2
3 /**
4 * JSON grammar.
5 */
6 class JsonGrammar extends GrammarParser {
7 JsonGrammar() : super(const JsonGrammarDefinition());
8 }
9
10 /**
11 * JSON grammar definition.
12 */
13 class JsonGrammarDefinition extends GrammarDefinition {
14 const JsonGrammarDefinition();
15
16 start() => ref(value).end();
17 token(p) => p.flatten().trim();
18
19 array() => ref(token, char('['))
20 & ref(elements).optional()
21 & ref(token, char(']'));
22 elements() => ref(value).separatedBy(ref(token, char(',')), includeSeparators: false);
23 members() => ref(pair).separatedBy(ref(token, char(',')), includeSeparators: f alse);
24 object() => ref(token, char('{'))
25 & ref(members).optional()
26 & ref(token, char('}'));
27 pair() => ref(stringToken)
28 & ref(token, char(':'))
29 & ref(value);
30 value() => ref(stringToken)
31 | ref(numberToken)
32 | ref(object)
33 | ref(array)
34 | ref(trueToken)
35 | ref(falseToken)
36 | ref(nullToken);
37
38 trueToken() => ref(token, string('true'));
39 falseToken() => ref(token, string('false'));
40 nullToken() => ref(token, string('null'));
41 stringToken() => ref(token, ref(stringPrimitive));
42 numberToken() => ref(token, ref(numberPrimitive));
43
44 characterPrimitive() => ref(characterNormal)
45 | ref(characterEscape)
46 | ref(characterOctal);
47 characterNormal() => pattern('^"\\');
48 characterEscape() => char('\\')
49 & pattern(new List.from(JSON_ESCAPE_CHARS.keys).join());
50 characterOctal() => string('\\u').seq(pattern("0-9A-Fa-f").times(4).flatten()) ;
51 numberPrimitive() => char('-').optional()
52 & char('0').or(digit().plus())
53 & char('.').seq(digit().plus()).optional()
54 & pattern('eE').seq(pattern('-+').optional()).seq(digit().plus()).optional ();
55 stringPrimitive() => char('"')
56 & ref(characterPrimitive).star()
57 & char('"');
58
59 }
60
61 const JSON_ESCAPE_CHARS = const {
62 '\\': '\\',
63 '/': '/',
64 '"': '"',
65 'b': '\b',
66 'f': '\f',
67 'n': '\n',
68 'r': '\r',
69 't': '\t'
70 };
OLDNEW
« no previous file with comments | « petitparser/lib/src/debug/trace.dart ('k') | petitparser/lib/src/json/parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698