use lark
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
from lark import Lark, Transformer, Token, v_args
|
||||
from pathlib import Path
|
||||
|
||||
GRAMMAR_FILE = Path(__file__).parent.joinpath("tcl.lark")
|
||||
TCL_GRAMMAR = GRAMMAR_FILE.read_text(encoding="utf-8")
|
||||
|
||||
|
||||
@v_args(inline=True)
|
||||
class TCLTransformer(Transformer):
|
||||
def start(self, *stmts):
|
||||
return list(stmts)
|
||||
|
||||
def command(self, *elements):
|
||||
return list(elements)
|
||||
|
||||
def braced(self, *content):
|
||||
return "{" + "".join(c for c in content) + "}"
|
||||
|
||||
def quoted(self, *content):
|
||||
return '"' + "".join(c for c in content) + '"'
|
||||
|
||||
def variable(self, token):
|
||||
return token.value
|
||||
|
||||
def cmdsubst(self, *inner):
|
||||
return "[" + " ".join(inner) + "]"
|
||||
|
||||
def bare(self, token):
|
||||
return token.value
|
||||
|
||||
def COMMENT(self, token):
|
||||
return token.value
|
||||
Reference in New Issue
Block a user