File: json.pgx

package info (click to toggle)
libpegex-perl 0.75-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 908 kB
  • sloc: perl: 3,288; makefile: 43; sh: 2
file content (69 lines) | stat: -rw-r--r-- 1,188 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# A simple grammar for the simple JSON data language.
# For parser implementations that use this grammar, see:
# * https://github.com/ingydotnet/pegex-json-pm

%grammar json
%version 0.0.1
%include pegex-atoms

json: - value -

object:
  ./- '{' -/
  pair* % /- ',' -/
  ./- '}' -/

pair: string ./- ':' -/ value

array:
  ./- '[' -/
  value* % ./- ',' -/
  ./- ']' -/

value:
  | string
  | number
  | object
  | array
  | true
  | false
  | null

# string and number are interpretations of http://www.json.org/
string: /
  DOUBLE
    (
      (:
        BACK (:     # Backslash escapes
          [
            DOUBLE    # Double Quote
            BACK    # Back Slash
            SLASH     # Foreward Slash
            'b'     # Back Space
            'f'     # Form Feed
            'n'     # New Line
            'r'     # Carriage Return
            't'     # Horizontal Tab
          ]
        |
          'u' HEX{4}    # Unicode octet pair
        )
      |
        [^ DOUBLE CONTROLS BACK ]  # Anything else
      )*
    )
  DOUBLE
/

number: /(
  DASH?
  (: '0' | [1-9] DIGIT* )
  (: DOT DIGIT+ )?
  (: [eE] [ DASH PLUS ]? DIGIT+ )?
)/

true: 'true'

false: 'false'

null: 'null'