a thrift parser (antlr4)
Project description
thrift-parser
pip install thrift-parser
Thrift.g4
is from https://github.com/antlr/grammars-v4
parse
from thrift_parser import parse_file
lexer, tokens, parser, document = parse_file('tutorial.thrift')
or smiple
from thrift_parser import ThriftData
thrift_data = ThriftData.from_file('tutorial.thrift')
print(thrift_data.tokens[0].text)
print(thrift_data.document.children)
or you can try antlr's way
from antlr4 import FileStream
from antlr4 import CommonTokenStream
from antlr4 import ParserRuleContext
from thrift_parser.ThriftLexer import ThriftLexer
from thrift_parser.ThriftParser import ThriftParser
def main(file):
input_stream = FileStream(file, encoding='utf8')
lexer = ThriftLexer(input_stream)
stream = CommonTokenStream(lexer)
parser = ThriftParser(stream)
ctx = ParserRuleContext()
parser.enterRule(ctx, 0, 0)
document = parser.document()
return document
Why ?
python thrift parser --> thrift-fmt --> auto format my thrift files in one style
TODO
- more ast operate, fake_token, fake_context
- other language?
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
thrift-parser-1.0.4.tar.gz
(27.5 kB
view hashes)
Built Distribution
Close
Hashes for thrift_parser-1.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdb079dca1c732a1a26cb204dd18dde0a90cda78e8b4461e0eefbc6da7726fef |
|
MD5 | 669c1d1afad4f933d1452b99b7c24643 |
|
BLAKE2b-256 | 56ef1ec231fba6b2c6280491e8e263c7c552b8be0ac5b7f37952297e9322e7bf |