将 ast 英化

This commit is contained in:
TermiNexus committed 2026-08-07 18:49:53 +08:00
1 parent 752f3ddb70
commit c5570dc8b1
9 files changed
+424 -413

No files matched your search

+29 -21
View File
@@ -3,34 +3,34 @@ from stdint import *
import memhub
import string
# 导入子模块
# Import submodule
from .tokens import (
Token, TokenType, Keyword, TokOp, _init_tables,
)
# 公共部分:基类、枚举、常量、辅助函数、dump
# Common Section: Base Classes, Enums, Constants, Helper Functions, Dump
from .base import (
AST, ASTKind, ASTCtx, OpKind, ASTFlag,
# 常量
# Constants
CONST_INT, CONST_FLOAT, CONST_STR, CONST_BOOL, CONST_NONE, CONST_CHAR,
FLAG_IS_ASYNC, FLAG_SIMPLE, FLAG_HAS_STAR,
# 辅助函数
# Helper Functions
_init_ast, _copy_str, _set_pos, _inherit_pos, _set_parent_list,
_binop_from_op, _augop_from_op, _cmpop_from_op,
_emit, _emit_str, _emit_int, _dump_list,
dump, _op_name,
)
# 语句节点
# Statement Nodes: Module, Expression, Interactive, FunctionType
from .stmts import (
# 模块层
# Module Layer
Module, Expression, Interactive, FunctionType,
# 语句
# Statement
FunctionDef, ClassDef, Return, Delete, Assign, AugAssign, AnnAssign,
For, While, If, With, Raise, Try, Assert, Global, Nonlocal,
Pass, Break, Continue, Expr, Import, ImportFrom, Match,
)
# 表达式节点
# Expression Nodes: BoolOp, BinOp, UnaryOp, Lambda, IfExp, Dict, Set
from .exprs import (
# 表达式
# Expression Layer
BoolOp, BinOp, UnaryOp, Lambda, IfExp, Dict, Set,
ListComp, SetComp, DictComp, GeneratorExp,
Await, Yield, YieldFrom, FormattedValue, JoinedStr,
@@ -38,12 +38,12 @@ from .exprs import (
List, Tuple, Slice,
Call, Compare, OpNode,
)
# 辅助节点
# Auxiliary Nodes
from .astaux import (
ExceptHandler, Arguments, Arg, Keyword, Alias, WithItem,
Comprehension,
)
# 模式匹配
# Pattern Matching
from .match import (
MatchCase, MatchValue, MatchSingleton, MatchSequence,
MatchMapping, MatchClass, MatchStar, MatchAs, MatchOr,
@@ -54,25 +54,25 @@ from .parser import Parser, _parser_init, parse_tokens, new_parser
from .parser import _parse_test
# ============================================================
# 全局内存池指针(遵循项目规则:声明 _mbuddy)
# 用户在 main 中初始化:ast._mbuddy = memhub.MemBuddy(arena, size)
# Global Memory Pool Pointer (follows project rules: declare _mbuddy)
# User initializes in main: ast._mbuddy = memhub.MemBuddy(arena, size)
# ============================================================
_mbuddy: memhub.MemBuddy | t.CPtr
# ============================================================
# 公共 API: parse
# Common API: parse
# ============================================================
def parse(src: str, pool: memhub.MemManager | t.CPtr) -> AST | t.CPtr:
"""解析 Python 源代码,返回 AST Module 节点。
"""Parse Python source code, return the AST Module node.
参数:
src: NUL 结尾的源代码字符串
pool: memhub.MemManager 实例,用于分配 AST 节点
Parameters:
src: NUL source code string, terminated with NUL
pool: memhub.MemManager instance, to allocate AST nodes
返回:
AST Module 节点,失败返回 None
Returns:
AST Module node, or None
"""
if src is None or pool is None:
return None
@@ -89,7 +89,15 @@ def parse(src: str, pool: memhub.MemManager | t.CPtr) -> AST | t.CPtr:
def parse_expression(src: str, pool: memhub.MemManager | t.CPtr) -> AST | t.CPtr:
"""解析单个表达式,返回 Expression 节点"""
"""Parse a single expression, return the Expression node.
Parameters:
src: NUL expression string, terminated with NUL
pool: memhub.MemManager instance, to allocate AST nodes
Returns:
Expression node, or None
"""
if src is None or pool is None:
return None
_init_tables(pool)