问题
I have a .tcl file.
Is there any parser available which directly extracts data from .tcl file ? I don't want to use REGEX for this task. Is pyparsing will work for this problem ?
I am using Python 2.7
回答1:
.tcl files are not data files, they are programming scripts, written in the Tcl programming language.
The Tcl language is extremely flexible in form and style, which makes writing a general-purpose parser a substantial project, whether in pyparsing or any other package. I encourage people, when they are embarking on a new pyparsing project, to begin by roughing out the BNF for the language, to whatever level of detail they want. This page from the Tcl wiki implies that developing a BNF for Tcl is not at all straightforward, if even possible.
It is very unlikely that anyone will respond to your question with an answer containing your Tcl-parser-implemented-in-Python. Perhaps there is a Tcl subset that you are particularly focused on - if you were to post some sample Tcl code and what you want to get from it, you are more likely to get helpful responses.
来源:https://stackoverflow.com/questions/26288633/tcl-file-parser-for-python