如何用Unicode值替换Python关键字

时间:2018-07-12 19:42:26

标签: python unicode

我正在尝试使用替换为Unicode字符串(在我的情况下为外语的等效关键字)的关键字来编译Python。我决定首先替换import语句作为测试,所以我修改了Grammar/Grammar文件,使其看起来像这样:

# For normal and annotated assignments, additional restrictions enforced by the interpreter
del_stmt: 'del' exprlist
pass_stmt: 'pass'
flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt
break_stmt: 'break'
continue_stmt: 'continue'
return_stmt: 'return' [testlist]
yield_stmt: yield_expr
raise_stmt: 'raise' [test ['from' test]]
import_stmt: import_name | import_from
import_name: '輸入' dotted_as_names # This is the only line I modified
# note below: the ('.' | '...') is necessary because '...' is tokenized as ELLIPSIS
import_from: ('from' (('.' | '...')* dotted_name | ('.' | '...')+)
              'import' ('*' | '(' import_as_names ')' | import_as_names))
import_as_name: NAME ['as' NAME]
dotted_as_name: dotted_name ['as' NAME]
import_as_names: import_as_name (',' import_as_name)* [',']
dotted_as_names: dotted_as_name (',' dotted_as_name)*
dotted_name: NAME ('.' NAME)*
global_stmt: 'global' NAME (',' NAME)*
nonlocal_stmt: 'nonlocal' NAME (',' NAME)*
assert_stmt: 'assert' test [',' test]

当我尝试运行$ make -s -j2时,我得到了:

Translating labels ...
Can't translate STRING label '輸入'

如果我尝试使用非Unicode值,则可以正常工作,因此我猜测这是Unicode兼容性的问题。只是不被支持还是有解决办法?

0 个答案:

没有答案