-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_julia.py
37 lines (30 loc) · 1018 Bytes
/
test_julia.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
from fable_sedlex.sedlex import *
from fable_sedlex.code_gen_julia import codegen_julia
from fable_sedlex.pretty_doc import show_doc
digit = pinterval(ord('0'), ord('9'))
dquote = pchar('"')
backslash = pchar('\\')
dot = pchar('.')
exp = pseq([por(pchar('E'), pchar('e')), pplus(digit)])
flt = pseq([pstar(digit), dot, pplus(digit), popt(exp)])
integral = pseq([pplus(digit), popt(exp)])
string_lit = pseq([dquote, pstar(por(pcompl(dquote), pseq([backslash, pany]))), dquote])
space = pchars(["\n", "\t", "\r", ' '])
EOF_ID = 0
cu = build(
[
(space, Lexer_discard),
(flt, Lexer_tokenize(1)),
(integral, Lexer_tokenize(2)),
(string_lit, Lexer_tokenize(3)),
(pstring("+"), Lexer_tokenize(4)),
(pstring("+="), Lexer_tokenize(4)),
(peof, Lexer_tokenize(EOF_ID))
], "my error")
header = """
using Sedlex
is_eof(x) = x.token_id == 0
"""
code = codegen_julia(header, cu)
with open("generated.jl", 'w', encoding='utf8') as f:
f.write(show_doc(code))