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

Side by Side Diff: packages/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
OLDNEW
1 part of json; 1 part of petitparser.json;
2 2
3 /** 3 /// JSON grammar.
4 * JSON grammar.
5 */
6 class JsonGrammar extends GrammarParser { 4 class JsonGrammar extends GrammarParser {
7 JsonGrammar() : super(const JsonGrammarDefinition()); 5 JsonGrammar() : super(const JsonGrammarDefinition());
8 } 6 }
9 7
10 /** 8 /// JSON grammar definition.
11 * JSON grammar definition.
12 */
13 class JsonGrammarDefinition extends GrammarDefinition { 9 class JsonGrammarDefinition extends GrammarDefinition {
14 const JsonGrammarDefinition(); 10 const JsonGrammarDefinition();
15 11
16 start() => ref(value).end(); 12 start() => ref(value).end();
17 token(p) => p.flatten().trim(); 13 token(p) => p.flatten().trim();
18 14
19 array() => ref(token, char('[')) 15 array() => ref(token, char('['))
20 & ref(elements).optional() 16 & ref(elements).optional()
21 & ref(token, char(']')); 17 & ref(token, char(']'));
22 elements() => ref(value).separatedBy(ref(token, char(',')), includeSeparators: false); 18 elements() => ref(value).separatedBy(ref(token, char(',')), includeSeparators: false);
(...skipping 13 matching lines...) Expand all
36 | ref(nullToken); 32 | ref(nullToken);
37 33
38 trueToken() => ref(token, string('true')); 34 trueToken() => ref(token, string('true'));
39 falseToken() => ref(token, string('false')); 35 falseToken() => ref(token, string('false'));
40 nullToken() => ref(token, string('null')); 36 nullToken() => ref(token, string('null'));
41 stringToken() => ref(token, ref(stringPrimitive)); 37 stringToken() => ref(token, ref(stringPrimitive));
42 numberToken() => ref(token, ref(numberPrimitive)); 38 numberToken() => ref(token, ref(numberPrimitive));
43 39
44 characterPrimitive() => ref(characterNormal) 40 characterPrimitive() => ref(characterNormal)
45 | ref(characterEscape) 41 | ref(characterEscape)
46 | ref(characterOctal); 42 | ref(characterUnicode);
47 characterNormal() => pattern('^"\\'); 43 characterNormal() => pattern('^"\\');
48 characterEscape() => char('\\') 44 characterEscape() => char('\\')
49 & pattern(new List.from(JSON_ESCAPE_CHARS.keys).join()); 45 & pattern(new List.from(jsonEscapeChars.keys).join());
50 characterOctal() => string('\\u').seq(pattern("0-9A-Fa-f").times(4).flatten()) ; 46 characterUnicode() => string('\\u')
47 & pattern("0-9A-Fa-f").times(4);
51 numberPrimitive() => char('-').optional() 48 numberPrimitive() => char('-').optional()
52 & char('0').or(digit().plus()) 49 & char('0').or(digit().plus())
53 & char('.').seq(digit().plus()).optional() 50 & char('.').seq(digit().plus()).optional()
54 & pattern('eE').seq(pattern('-+').optional()).seq(digit().plus()).optional (); 51 & pattern('eE').seq(pattern('-+').optional()).seq(digit().plus()).optional ();
55 stringPrimitive() => char('"') 52 stringPrimitive() => char('"')
56 & ref(characterPrimitive).star() 53 & ref(characterPrimitive).star()
57 & char('"'); 54 & char('"');
58 55
59 } 56 }
60 57
61 const JSON_ESCAPE_CHARS = const { 58 const jsonEscapeChars = const {
62 '\\': '\\', 59 '\\': '\\',
63 '/': '/', 60 '/': '/',
64 '"': '"', 61 '"': '"',
65 'b': '\b', 62 'b': '\b',
66 'f': '\f', 63 'f': '\f',
67 'n': '\n', 64 'n': '\n',
68 'r': '\r', 65 'r': '\r',
69 't': '\t' 66 't': '\t'
70 }; 67 };
OLDNEW
« no previous file with comments | « packages/petitparser/lib/src/debug/trace.dart ('k') | packages/petitparser/lib/src/json/parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698