Skip to content
This repository was archived by the owner on Jan 21, 2019. It is now read-only.
This repository was archived by the owner on Jan 21, 2019. It is now read-only.

Python关键字汉化实例 #2

@swizl

Description

@swizl

以while为例
第1步. 编译pgen
cd到python的源代码目录下,
./configure
make Parser/pgen

第2步. 修改 ./Grammar/Grammar,添加同义词并生成语法代码。
原文:
while_stmt: 'while' test ':' suite ['else' ':' suite]
改为:
while_stmt: ('while'|'while_cn') test ':' suite ['else' ':' suite]
执行
./Parser/pgen ./Grammar/Grammar ./Include/graminit.h ./Python/graminit.c

第3步. 在./Python/graminit.c中替换英文同义词为中文。
原文:
{1, "while_cn"},
改为:
{1, "当"},
并保存./Python/graminit.c为UTF-8格式
之后 make 编译python即可。

中文的py文件也需要保存为UTF-8格式。
目前pgen不支持UTF-8,所以不能一步到位。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions