forked from tkw1536/PreJsPy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
56 lines (39 loc) · 960 Bytes
/
example.py
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
#
# Preamble -- make sure that PreJsPy is in the path.
# You won't have to do this in production.
#
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src", "py"))
import PreJsPy
import json
def run_example(expr):
"""
Parses a single expression and prints the result to stdout.
:param expr: Expression to parse.
:type expr: str
"""
p = PreJsPy.PreJsPy()
print(p.parse(expr))
def make_testcase(inp, msg):
"""
Utility function to create a test case.
:param inp: Input to use.
:type inp: str
:param msg: Message for test case.
:type msg: str
"""
p = PreJsPy.PreJsPy()
out = p.parse(inp)
print("""{
"input": %s,
"output": %s,
"message": %s
}""" % (json.dumps(inp), json.dumps(out), json.dumps(msg)))
def main():
"""
Main entry point for the example.
"""
run_example('"Hello world"')
if __name__ == '__main__':
main()