61 lines
1.2 KiB
Python
Executable file
61 lines
1.2 KiB
Python
Executable file
#!/bin/env -S python
|
|
|
|
from os.path import dirname
|
|
import sys
|
|
|
|
sys.path.append(f"{dirname(__file__)}/../src")
|
|
from party import regex, Parser, just, FwDeclaration, end
|
|
|
|
|
|
# input = "abc"
|
|
# parser = just("a").or_else(just("b")).or_else(just("c"))
|
|
# (parsed1, rest1) = parser.parse_part(input)
|
|
# (parsed2, rest2) = parser.parse_part(rest1)
|
|
# (parsed3, rest3) = parser.parse_part(rest2)
|
|
|
|
# print(
|
|
# "parsed1", parsed1,
|
|
# "rest1", rest1,
|
|
# "parsed2", parsed2,
|
|
# "rest2", rest2,
|
|
# "parsed3", parsed3,
|
|
# "rest3", rest3,
|
|
# )
|
|
|
|
|
|
# input = "a"
|
|
# parser = just("a").and_then(end())
|
|
# parsed = parser.parse(input)
|
|
|
|
# print("parsed", parsed)
|
|
|
|
|
|
# input = "...a"
|
|
# parser = just(".").repeat() >> just("a")
|
|
# parsed = parser.parse(input)
|
|
|
|
# print("parsed", parsed)
|
|
|
|
|
|
# input = r"{a}"
|
|
# parser = just("{") >> just("a") << just("}")
|
|
# parsed = parser.parse(input)
|
|
|
|
# print("parsed", parsed)
|
|
|
|
|
|
# input = r"a,a,a,a"
|
|
# parser = just("a").sep_by(just(","))
|
|
# parsed = parser.parse(input)
|
|
|
|
# print("parsed", parsed)
|
|
|
|
|
|
#td
|
|
input = r"{a,a,a,a"
|
|
# parser = just("{") >> just("a").sep_by(just(","))
|
|
# parser = just("{").and_then(just("a").sep_by(just(",")))
|
|
parser = just("{").and_then(just("a").sep_by(just(",")))
|
|
parsed = parser.parse(input)
|
|
|
|
print("parsed", parsed)
|