Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

字段名以true开头将出现语法错误 #215

Closed
hatlonely opened this issue Jul 12, 2016 · 3 comments
Closed

字段名以true开头将出现语法错误 #215

hatlonely opened this issue Jul 12, 2016 · 3 comments

Comments

@hatlonely
Copy link

比如require i64 trueNum,这样将出现语法错误

@hatlonely
Copy link
Author

hatlonely commented Jul 12, 2016

test.thrift

struct Test {
    1:required i64 trueNum;
}

test.py

import sys
import thriftpy
from thriftpy.rpc import make_client

def main():
    as_thrift = thriftpy.load('test.thrift', module_name='test_thrift')

if __name__ == '__main__':
    main()

执行python3 test.py,报错如下:

Traceback (most recent call last):
  File "test.py", line 9, in <module>
    main()
  File "test.py", line 6, in main
    as_thrift = thriftpy.load('test.thrift', module_name='test_thrift')
  File "/usr/local/lib/python3.5/site-packages/thriftpy/parser/__init__.py", line 30, in load
    include_dir=include_dir)
  File "/usr/local/lib/python3.5/site-packages/thriftpy/parser/parser.py", line 502, in parse
    parser.parse(data)
  File "/usr/local/lib/python3.5/site-packages/ply/yacc.py", line 331, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "/usr/local/lib/python3.5/site-packages/ply/yacc.py", line 1181, in parseopt_notrack
    tok = call_errorfunc(self.errorfunc, errtoken, self)
  File "/usr/local/lib/python3.5/site-packages/ply/yacc.py", line 193, in call_errorfunc
    r = errorfunc(token)
  File "/usr/local/lib/python3.5/site-packages/thriftpy/parser/parser.py", line 24, in p_error
    (p.value, p.lineno))
thriftpy.parser.exc.ThriftGrammerError: Grammer error True at line 2

修改test.thrift 不以 true开头,在之前字段名前面加一个a,可以正常运行

struct Test {
    1:required i64 atrueNum;
}

@hatlonely
Copy link
Author

尝试改了一下源文件parser/lexer.py, t_BOOLCONSTANT函数,可以解决

def t_BOOLCONSTANT(t):
    r'true\W|false\W'
    t.value = t.value == 'true'
    return t

@hit9 hit9 self-assigned this Jul 21, 2016
@hit9
Copy link
Contributor

hit9 commented Jul 21, 2016

Confirmed.

@lxyu lxyu closed this as completed in 115b8a8 Jul 21, 2016
lxyu added a commit that referenced this issue Jul 21, 2016
Add word boundary for true/false literal lexing, close #215
@ethe ethe unassigned hit9 Dec 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants