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 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 ? thrift-parser
python thrift parser --> thrift-fmt --> auto format my thrift files in one style
Deprecated [My Old Try]
python3 simple.pys>
1. include + struct + service
- 支持 Annotation (uri = 'https://github.com/')
list< map< set (python.immutable = ""), map<i32, set< list< map<Insanity,string> (python.immutable = "") > (python.immutable = "") >>>> list_field,
-
支持解析 Comment
-
more test https://github.com/evernote/evernote-thrift/tree/master/src
-
ast 封装
COPYING
将参考以下代码
https://thrift.apache.org/docs/idl
https://github.com/apache/thrift APACHE
sly: https://github.com/dabeaz/sly
ptsd: https://github.com/wickman/ptsd MIT
ply: https://github.com/dabeaz/ply BSD
js thrift-parser: https://github.com/eleme/thrift-parser MIT
annotationTest.thrift https://git-wip-us.apache.org/repos/asf?p=thrift.git;a=blob_plain;f=test/AnnotationTest.thrift;hb=HEAD
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
Built Distribution
Hashes for thrift_parser-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04f7c03631fba5e344cceb6c2c23d21dc87334a1605640e014455bf2707be27a |
|
MD5 | 1d679f7978c95ada7d92daf9ca0c1cf5 |
|
BLAKE2b-256 | fc24f2975acd2bc1f88f173cc3c927fb9a99d5c7d6cb683375ddb35fe314b756 |