Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
28 lines (20 sloc) 584 Bytes
import sys
from lark import Lark
lark = Lark(r'''
tex: content+
?content: mathmode | text+
mathmode: OFFSETDOLLAR text+ OFFSETDOLLAR
| OFFSETOPEN text+ OFFSETCLOSE
| INLINEOPEN text+ INLINECLOSE
| INLINE text+ INLINE
INLINE: "$"
INLINEOPEN: "\\("
INLINECLOSE: "\\)"
OFFSETDOLLAR: "$$"
OFFSETOPEN: "\\["
OFFSETCLOSE: "\\]"
?text: /./s
''', start='tex', parser='lalr')
input_text = sys.stdin.read()
parsed_doc = lark.parse(input_text)
print(parsed_doc)
You can’t perform that action at this time.