Refresh the repo
This commit is contained in:
159
tools/meta.py
Normal file
159
tools/meta.py
Normal file
@@ -0,0 +1,159 @@
|
||||
import re
|
||||
snake_case_pattern = re.compile(r'(?<!^)(?=[A-Z])')
|
||||
|
||||
def pascal_to_snake(v):
|
||||
name = snake_case_pattern.sub('_', v).lower()
|
||||
return name
|
||||
|
||||
BINARY_EXPR = 1
|
||||
UNARY_EXPR = 2
|
||||
|
||||
token_simple_expr = [
|
||||
["Mul", "*", BINARY_EXPR],
|
||||
["Div", "/", BINARY_EXPR],
|
||||
["Mod", "%", BINARY_EXPR],
|
||||
["LeftShift", "<<", BINARY_EXPR],
|
||||
["RightShift", ">>", BINARY_EXPR],
|
||||
["FirstMul = TK_Mul", "SPECIAL"],
|
||||
["LastMul = TK_RightShift", "SPECIAL"],
|
||||
["Add", "+", BINARY_EXPR | UNARY_EXPR],
|
||||
["Sub", "-", BINARY_EXPR | UNARY_EXPR],
|
||||
["FirstAdd = TK_Add", "SPECIAL"],
|
||||
["LastAdd = TK_Sub", "SPECIAL"],
|
||||
["Equals", "==", BINARY_EXPR],
|
||||
["LesserThenOrEqual", "<=", BINARY_EXPR],
|
||||
["GreaterThenOrEqual", ">=", BINARY_EXPR],
|
||||
["LesserThen", "<", BINARY_EXPR],
|
||||
["GreaterThen", ">", BINARY_EXPR],
|
||||
["NotEquals", "!=", BINARY_EXPR],
|
||||
["FirstCompare = TK_Equals", "SPECIAL"],
|
||||
["LastCompare = TK_NotEquals", "SPECIAL"],
|
||||
["BitAnd", "&", BINARY_EXPR],
|
||||
["BitOr", "|", BINARY_EXPR],
|
||||
["BitXor", "^", BINARY_EXPR],
|
||||
["And", "&&", BINARY_EXPR],
|
||||
["Or", "||", BINARY_EXPR],
|
||||
["FirstLogical = TK_BitAnd", "SPECIAL"],
|
||||
["LastLogical = TK_Or", "SPECIAL"],
|
||||
|
||||
["Neg", "~", UNARY_EXPR],
|
||||
["Not", "!", UNARY_EXPR],
|
||||
]
|
||||
|
||||
token_inc_expr = [
|
||||
["Decrement", "--", UNARY_EXPR],
|
||||
["Increment", "++", UNARY_EXPR],
|
||||
["PostDecrement", "--", UNARY_EXPR],
|
||||
["PostIncrement", "++", UNARY_EXPR],
|
||||
]
|
||||
|
||||
token_assign_expr = [
|
||||
["Assign", "="],
|
||||
["ColonAssign", ":="],
|
||||
["DivAssign", "/="],
|
||||
["MulAssign", "*="],
|
||||
["ModAssign", "%="],
|
||||
["SubAssign", "-="],
|
||||
["AddAssign", "+="],
|
||||
["AndAssign", "&="],
|
||||
["OrAssign", "|="],
|
||||
["XorAssign", "^="],
|
||||
["LeftShiftAssign", "<<="],
|
||||
["RightShiftAssign", ">>="],
|
||||
["FirstAssign = TK_Assign", "SPECIAL"],
|
||||
["LastAssign = TK_RightShiftAssign", "SPECIAL"],
|
||||
]
|
||||
|
||||
token_rest = [
|
||||
["OpenParen", "("],
|
||||
["CloseParen", ")"],
|
||||
["OpenBrace", "{"],
|
||||
["CloseBrace", "}"],
|
||||
["OpenBracket", "["],
|
||||
["CloseBracket", "]"],
|
||||
["Comma", ","],
|
||||
["Pound", "#"],
|
||||
["Question", "?"],
|
||||
["ThreeDots", "..."],
|
||||
["Semicolon", ";"],
|
||||
["Dot", "."],
|
||||
["TwoDots", ".."],
|
||||
["NewLine", "[NewLine]"],
|
||||
["Colon", ":"],
|
||||
["DoubleColon", "::"],
|
||||
["At", "@"],
|
||||
["Arrow", "->"],
|
||||
["Polymorph", "$"],
|
||||
["ExprSizeof", "[sizeof]"],
|
||||
["DocComment", "[///]"],
|
||||
["Comment", "//"],
|
||||
["Identifier", "[Ident]"],
|
||||
["UnicodeLit", "[Unicode]"],
|
||||
["StringLit", "[String]"],
|
||||
["Error", "[Error]"],
|
||||
["Float", "[Float]"],
|
||||
["Integer", "[Int]"],
|
||||
["Keyword", "[Keyword]"],
|
||||
]
|
||||
|
||||
token_kinds = token_simple_expr + token_inc_expr + token_assign_expr + token_rest
|
||||
|
||||
keywords = [
|
||||
"struct",
|
||||
"union",
|
||||
"true",
|
||||
"default",
|
||||
"continue",
|
||||
"break",
|
||||
"false",
|
||||
"return",
|
||||
"switch",
|
||||
"Assert",
|
||||
"if",
|
||||
"elif",
|
||||
"pass",
|
||||
"else",
|
||||
"for",
|
||||
"enum",
|
||||
"goto",
|
||||
"defer",
|
||||
]
|
||||
|
||||
interns = [
|
||||
"typeof",
|
||||
"sizeof",
|
||||
"Len",
|
||||
"alignof",
|
||||
"foreign",
|
||||
"strict",
|
||||
"void",
|
||||
"flag",
|
||||
"it",
|
||||
"load",
|
||||
"import",
|
||||
"link",
|
||||
"compiler_breakpoint",
|
||||
]
|
||||
|
||||
|
||||
value_struct_content = """
|
||||
Ast_Type *type;
|
||||
Ast_Decl *resolved_decl;
|
||||
union {
|
||||
bool bool_val;
|
||||
double f64_val;
|
||||
Intern_String intern_val;
|
||||
BigInt big_int_val;
|
||||
Ast_Type *type_val;
|
||||
};
|
||||
""".strip()
|
||||
|
||||
def inline_value_fields():
|
||||
print(f"""
|
||||
union {{
|
||||
Value value;
|
||||
struct {{
|
||||
{value_struct_content}
|
||||
}};
|
||||
}};
|
||||
""".strip())
|
||||
Reference in New Issue
Block a user