diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-08-25 19:11:17 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-08-25 19:11:17 -0400 |
| commit | 247043eae0ad88b1833d6a64e7ded130605dd83a (patch) | |
| tree | c7e6334ffd9aa71c9b5de7f8f23fc492f823f0c4 /src/ast.c | |
| parent | e927a088be671a003b8e4816a4a963243c0b61aa (diff) | |
Better support for binops in formatter
Diffstat (limited to 'src/ast.c')
| -rw-r--r-- | src/ast.c | 31 |
1 files changed, 29 insertions, 2 deletions
@@ -8,6 +8,33 @@ #include "stdlib/tables.h" #include "stdlib/text.h" +const int op_tightness[NUM_AST_TAGS] = { + [Power] = 9, + [Multiply] = 8, + [Divide] = 8, + [Mod] = 8, + [Mod1] = 8, + [Plus] = 7, + [Minus] = 7, + [Concat] = 6, + [LeftShift] = 5, + [RightShift] = 5, + [UnsignedLeftShift] = 5, + [UnsignedRightShift] = 5, + [Min] = 4, + [Max] = 4, + [Equals] = 3, + [NotEquals] = 3, + [LessThan] = 2, + [LessThanOrEquals] = 2, + [GreaterThan] = 2, + [GreaterThanOrEquals] = 2, + [Compare] = 2, + [And] = 1, + [Or] = 1, + [Xor] = 1, +}; + static Text_t quoted_text(const char *text) { return Text$quoted(Text$from_str(text), false, Text("\"")); } CONSTFUNC const char *binop_method_name(ast_e tag) { @@ -44,7 +71,7 @@ CONSTFUNC const char *binop_method_name(ast_e tag) { case XorUpdate: return "bit_xor"; default: return NULL; } -}; +} CONSTFUNC const char *binop_operator(ast_e tag) { switch (tag) { @@ -76,7 +103,7 @@ CONSTFUNC const char *binop_operator(ast_e tag) { case GreaterThanOrEquals: return ">="; default: return NULL; } -}; +} static Text_t ast_list_to_sexp(ast_list_t *asts); static Text_t arg_list_to_sexp(arg_ast_t *args); |
