File: examples.py

package info (click to toggle)
python-lark 1.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,788 kB
  • sloc: python: 13,305; javascript: 88; makefile: 34; sh: 8
file content (150 lines) | stat: -rw-r--r-- 4,119 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

# Examples formattet this way:
#   "name": ("grammar", "demo-input")

examples = {

	# --- hello.lark ---
	"hello.lark": ("""
start: WORD "," WORD "!"

%import common.WORD   // imports from terminal library
%ignore " "           // Disregard spaces in text
""", "Hello, World!"),

	# --- calc.lark ---
"calc.lark": ("""
?start: sum
      | NAME "=" sum    -> assign_var

?sum: product
    | sum "+" product   -> add
    | sum "-" product   -> sub

?product: atom
    | product "*" atom  -> mul
    | product "/" atom  -> div

?atom: NUMBER           -> number
     | "-" atom         -> neg
     | NAME             -> var
     | "(" sum ")"

%import common.CNAME -> NAME
%import common.NUMBER
%import common.WS_INLINE
%ignore WS_INLINE""",
	"1 + 2 * 3 + 4"),

	# --- json.lark ---
	"json.lark": ("""
?start: value
?value: object
      | array
      | string
      | SIGNED_NUMBER      -> number
      | "true"             -> true
      | "false"            -> false
      | "null"             -> null
array  : "[" [value ("," value)*] "]"
object : "{" [pair ("," pair)*] "}"
pair   : string ":" value
string : ESCAPED_STRING
%import common.ESCAPED_STRING
%import common.SIGNED_NUMBER
%import common.WS
%ignore WS""",
"""
[
  {
    "_id": "5edb875cf3d764da55602437",
    "index": 0,
    "guid": "3dae2206-5d4d-41fe-b81d-dc8cdba7acaa",
    "isActive": false,
    "balance": "$2,872.54",
    "picture": "http://placehold.it/32x32",
    "age": 24,
    "eyeColor": "blue",
    "name": "Theresa Vargas",
    "gender": "female",
    "company": "GEEKOL",
    "email": "theresavargas@geekol.com",
    "phone": "+1 (930) 450-3445",
    "address": "418 Herbert Street, Sexton, Florida, 1375",
    "about": "Id minim deserunt laborum enim. Veniam commodo incididunt amet aute esse duis veniam occaecat nulla esse aute et deserunt eiusmod. Anim elit ullamco minim magna sint laboris. Est consequat quis deserunt excepteur in magna pariatur laborum quis eu. Ex quis tempor elit qui qui et culpa sunt sit esse mollit cupidatat. Fugiat cillum deserunt enim minim irure reprehenderit est. Voluptate nisi quis amet quis incididunt pariatur nostrud Lorem consectetur adipisicing voluptate.\\r\\n",
    "registered": "2016-11-19T01:02:42 -01:00",
    "latitude": -25.65267,
    "longitude": 104.19531,
    "tags": [
      "eiusmod",
      "reprehenderit",
      "anim",
      "sunt",
      "esse",
      "proident",
      "esse"
    ],
    "friends": [
      {
        "id": 0,
        "name": "Roth Herrera"
      },
      {
        "id": 1,
        "name": "Callie Christian"
      },
      {
        "id": 2,
        "name": "Gracie Whitfield"
      }
    ],
    "greeting": "Hello, Theresa Vargas! You have 6 unread messages.",
    "favoriteFruit": "banana"
  },
  {
    "_id": "5edb875c845eb08161a83e64",
    "index": 1,
    "guid": "a8ada2c1-e2c7-40d3-96b4-52c93baff7f0",
    "isActive": false,
    "balance": "$2,717.04",
    "picture": "http://placehold.it/32x32",
    "age": 23,
    "eyeColor": "green",
    "name": "Lily Ross",
    "gender": "female",
    "company": "RODEOMAD",
    "email": "lilyross@rodeomad.com",
    "phone": "+1 (941) 465-3561",
    "address": "525 Beekman Place, Blodgett, Marshall Islands, 3173",
    "about": "Aliquip duis proident excepteur eiusmod in quis officia consequat culpa eu et ut. Occaecat reprehenderit tempor mollit do eu magna qui et magna exercitation aliqua. Incididunt exercitation dolor proident eiusmod minim occaecat. Sunt et minim mollit et veniam sint ex. Duis ullamco elit aute eu excepteur reprehenderit officia.\\r\\n",
    "registered": "2019-11-02T04:06:42 -01:00",
    "latitude": 17.031701,
    "longitude": -42.657106,
    "tags": [
      "id",
      "non",
      "culpa",
      "reprehenderit",
      "esse",
      "elit",
      "sit"
    ],
    "friends": [
      {
        "id": 0,
        "name": "Ursula Maldonado"
      },
      {
        "id": 1,
        "name": "Traci Huff"
      },
      {
        "id": 2,
        "name": "Taylor Holt"
      }
    ],
    "greeting": "Hello, Lily Ross! You have 3 unread messages.",
    "favoriteFruit": "strawberry"
  }
]""")
}