Zen-C
Loading...
Searching...
No Matches
parser.h
Go to the documentation of this file.
1
2#ifndef PARSER_H
3#define PARSER_H
4
5#include "ast.h"
6#include "zprep.h"
7
8// Operator precedence for expression parsing
9
28
29// Main entry points
30// Forward declarations
31struct ParserContext;
33
38
40
41// Symbol table
61
67typedef struct Scope
68{
70 struct Scope *parent;
72
91
95typedef struct LambdaRef
96{
98 struct LambdaRef *next;
100
110
121
132
136typedef struct ImportedFile
137{
138 char *path;
141
154
158typedef struct StructRef
159{
163
167typedef struct StructDef
168{
169 char *name;
173
177typedef struct SliceType
178{
179 char *name;
182
186typedef struct TupleType
187{
188 char *sig;
191
202
206typedef struct DeprecatedFunc
207{
208 char *name;
209 char *reason;
212
216typedef struct Module
217{
218 char *alias;
219 char *path;
220 char *base_name;
222 struct Module *next;
224
235
239typedef struct ImplReg
240{
241 char *trait;
242 char *strct;
243 struct ImplReg *next;
245
249typedef struct ImportedPlugin
250{
251 char *name;
252 char *alias;
255
267
275{
278
279 // Lambdas
282
283// Generics
284#define MAX_KNOWN_GENERICS 1024
285 char
291
292 // Instantiations
296
297 // Structs/Enums
306
307 // Types
311
312 // Modules/Imports
318
319 // Config/State
322
323 // Internal tracking
325
326 // LSP / Fault Tolerance
329 void (*on_error)(void *data, Token t, const char *msg);
330
331 // LSP: Flat symbol list (persists after parsing for LSP queries)
333
334 // External C interop: suppress undefined warnings for external symbols
338
339 // Codegen state:
340 FILE *hoist_out;
345
346 // Type Validation
350};
351
352typedef struct TypeUsage
353{
354 char *name;
358
359// Type validation prototypes
360
364void register_type_usage(ParserContext *ctx, const char *name, Token t);
365
370
371// Token helpers
372
376char *token_strdup(Token t);
377
381int is_token(Token t, const char *s);
382
386Token expect(Lexer *l, TokenType type, const char *msg);
387
391void skip_comments(Lexer *l);
392
397
402
403// C reserved word warnings
404
408int is_c_reserved_word(const char *name);
409
413void warn_c_reserved_word(Token t, const char *name);
414
415// ZenSymbol table
416
420void enter_scope(ParserContext *ctx);
421
425void exit_scope(ParserContext *ctx);
426
430void add_symbol(ParserContext *ctx, const char *n, const char *t, Type *type_info);
431
435void add_symbol_with_token(ParserContext *ctx, const char *n, const char *t, Type *type_info,
436 Token tok);
437
441Type *find_symbol_type_info(ParserContext *ctx, const char *n);
442
446char *find_symbol_type(ParserContext *ctx, const char *n);
447
451ZenSymbol *find_symbol_entry(ParserContext *ctx, const char *n);
452
456ZenSymbol *find_symbol_in_all(ParserContext *ctx, const char *n);
457char *find_similar_symbol(ParserContext *ctx, const char *name);
458
459// Function registry
460
464void register_func(ParserContext *ctx, const char *name, int count, char **defaults,
465 Type **arg_types, Type *ret_type, int is_varargs, int is_async,
466 Token decl_token);
467
471void register_func_template(ParserContext *ctx, const char *name, const char *param, ASTNode *node);
472
477
478// Generic/template helpers
482void register_generic(ParserContext *ctx, char *name);
483
487int is_known_generic(ParserContext *ctx, char *name);
488
489void register_impl_template(ParserContext *ctx, const char *sname, const char *param,
490 ASTNode *node);
492void add_to_enum_list(ParserContext *ctx, ASTNode *node);
493void add_to_func_list(ParserContext *ctx, ASTNode *node);
494void add_to_impl_list(ParserContext *ctx, ASTNode *node);
498
502void instantiate_generic(ParserContext *ctx, const char *name, const char *concrete_type,
503 const char *unmangled_type, Token t);
504
508void instantiate_generic_multi(ParserContext *ctx, const char *name, char **args, int arg_count,
509 Token t);
510
514char *sanitize_mangled_name(const char *name);
515
520void register_type_alias(ParserContext *ctx, const char *alias, const char *original, int is_opaque,
521 const char *defined_in_file);
522
526void register_impl(ParserContext *ctx, const char *trait, const char *strct);
527
531int check_impl(ParserContext *ctx, const char *trait, const char *strct);
532
536void register_template(ParserContext *ctx, const char *name, ASTNode *node);
537
541void register_deprecated_func(ParserContext *ctx, const char *name, const char *reason);
542
547
551ASTNode *parse_arrow_lambda_single(ParserContext *ctx, Lexer *l, char *param_name);
552
556ASTNode *parse_arrow_lambda_multi(ParserContext *ctx, Lexer *l, char **param_names, int num_params);
557
558// Utils
559
563char *parse_and_convert_args(ParserContext *ctx, Lexer *l, char ***defaults_out, int *count_out,
564 Type ***types_out, char ***names_out, int *is_varargs_out,
565 char ***ctype_overrides_out);
566
570int is_file_imported(ParserContext *ctx, const char *path);
571
575void mark_file_imported(ParserContext *ctx, const char *path);
576
580void register_plugin(ParserContext *ctx, const char *name, const char *alias);
581
585const char *resolve_plugin(ParserContext *ctx, const char *name_or_alias);
586
590void print_type_defs(ParserContext *ctx, FILE *out, ASTNode *nodes);
591
592// String manipulation
593
597char *replace_in_string(const char *src, const char *old_w, const char *new_w);
598
602char *replace_type_str(const char *src, const char *param, const char *concrete,
603 const char *old_struct, const char *new_struct);
604
608Type *replace_type_formal(Type *t, const char *p, const char *c, const char *os, const char *ns);
609
613ASTNode *copy_ast_replacing(ASTNode *n, const char *p, const char *c, const char *os,
614 const char *ns);
615char *extract_module_name(const char *path);
616
617// Enum helpers
621void register_enum_variant(ParserContext *ctx, const char *ename, const char *vname, int tag);
622
626EnumVariantReg *find_enum_variant(ParserContext *ctx, const char *vname);
627
628// Lambda helpers
632void register_lambda(ParserContext *ctx, ASTNode *node);
633
638
639// Type registration
643void register_slice(ParserContext *ctx, const char *type);
644
648void register_tuple(ParserContext *ctx, const char *sig);
649
650// Struct lookup
654ASTNode *find_struct_def(ParserContext *ctx, const char *name);
655
659void register_struct_def(ParserContext *ctx, const char *name, ASTNode *node);
660
661// Module system
665Module *find_module(ParserContext *ctx, const char *alias);
666
670void register_module(ParserContext *ctx, const char *alias, const char *path);
671
675void register_selective_import(ParserContext *ctx, const char *symbol, const char *alias,
676 const char *source_module);
677
682
683// Type Aliases
684
688const char *find_type_alias(ParserContext *ctx, const char *alias);
689
690// External symbol tracking (C interop)
694void register_extern_symbol(ParserContext *ctx, const char *name);
695
699int is_extern_symbol(ParserContext *ctx, const char *name);
700
705
706// Initialization
710void init_builtins();
711
712// Expression rewriting
716char *rewrite_expr_methods(ParserContext *ctx, char *raw);
717
721char *process_fstring(ParserContext *ctx, const char *content, char ***used_syms, int *count);
722
726char *instantiate_function_template(ParserContext *ctx, const char *name, const char *concrete_type,
727 const char *unmangled_type);
728
732FuncSig *find_func(ParserContext *ctx, const char *name);
733
738
743
747char *parse_type(ParserContext *ctx, Lexer *l);
748
753
758
763
768
773
778
782char *parse_array_literal(ParserContext *ctx, Lexer *l, const char *st);
783
787char *parse_tuple_literal(ParserContext *ctx, Lexer *l, const char *tn);
788
793
798
803
808
813
818
823
828
833
838
843
848
853
857char *process_printf_sugar(ParserContext *ctx, const char *content, int newline, const char *target,
858 char ***used_syms, int *count, int check_symbols);
859
864
869
874
879
884
889
893ASTNode *parse_type_alias(ParserContext *ctx, Lexer *l, int is_opaque);
894
898ASTNode *parse_function(ParserContext *ctx, Lexer *l, int is_async);
899
903ASTNode *parse_struct(ParserContext *ctx, Lexer *l, int is_union, int is_opaque);
904
909
914
919
924
929
930// Move semantics helpers
931
935int is_type_copy(ParserContext *ctx, Type *t);
936
940void check_move_usage(ParserContext *ctx, ASTNode *node, Token t);
941
946
951
956
960char *patch_self_args(const char *args, const char *struct_name);
961
966
967#endif // PARSER_H
const char *const name
Definition cJSON.h:307
int count
Definition cJSON.h:248
void register_tuple(ParserContext *ctx, const char *sig)
Registers a tuple type.
Definition parser_utils.c:672
ASTNode * parse_return(ParserContext *ctx, Lexer *l)
Parses a return statement.
Definition parser_stmt.c:986
ASTNode * parse_struct(ParserContext *ctx, Lexer *l, int is_union, int is_opaque)
Parses a struct definition.
Definition parser_struct.c:780
void exit_scope(ParserContext *ctx)
Exits the current scope (pops from scope stack).
Definition parser_utils.c:120
EnumVariantReg * find_enum_variant(ParserContext *ctx, const char *vname)
Finds an enum variant.
Definition parser_utils.c:536
char * parse_condition_raw(ParserContext *ctx, Lexer *l)
Parses a condition.
Definition parser_utils.c:2860
void register_module(ParserContext *ctx, const char *alias, const char *path)
Registers a module.
Definition parser_utils.c:818
int should_suppress_undef_warning(ParserContext *ctx, const char *name)
Checks if a symbol should suppress an undefined warning.
Definition parser_utils.c:596
ASTNode * parse_block(ParserContext *ctx, Lexer *l)
Parses a block of statements { ... }.
Definition parser_stmt.c:2804
ASTNode * parse_include(ParserContext *ctx, Lexer *l)
Parses an include statement.
Definition parser_stmt.c:2937
int is_extern_symbol(ParserContext *ctx, const char *name)
Checks if a symbol is external.
Definition parser_utils.c:583
void add_to_struct_list(ParserContext *ctx, ASTNode *node)
Definition parser_utils.c:398
int is_file_imported(ParserContext *ctx, const char *path)
Checks if a file has been imported.
Definition parser_utils.c:2838
ASTNode * parse_if(ParserContext *ctx, Lexer *l)
Parses an if statement.
Definition parser_stmt.c:1094
ASTNode * parse_function(ParserContext *ctx, Lexer *l, int is_async)
Parses a function definition.
Definition parser_decl.c:15
char * rewrite_expr_methods(ParserContext *ctx, char *raw)
Rewrites expression methods.
Definition parser_utils.c:2916
void register_impl_template(ParserContext *ctx, const char *sname, const char *param, ASTNode *node)
Definition parser_utils.c:376
void print_type_defs(ParserContext *ctx, FILE *out, ASTNode *nodes)
Prints type definitions to a file.
Definition codegen_decl.c:1064
Type * replace_type_formal(Type *t, const char *p, const char *c, const char *os, const char *ns)
Replaces a type formal in a type.
Definition parser_utils.c:1321
void skip_comments(Lexer *l)
Skips comments in the lexer.
Definition parser_utils.c:39
void register_slice(ParserContext *ctx, const char *type)
Registers a slice type.
Definition parser_utils.c:630
void register_builtins(ParserContext *ctx)
Definition parser_utils.c:471
ASTNode * parse_expression(ParserContext *ctx, Lexer *l)
Parses an expression.
Definition parser_expr.c:408
ASTNode * parse_guard(ParserContext *ctx, Lexer *l)
Parses a guard statement.
Definition parser_stmt.c:528
char * replace_type_str(const char *src, const char *param, const char *concrete, const char *old_struct, const char *new_struct)
Replaces a type string in a string.
Definition parser_utils.c:1027
void check_move_usage(ParserContext *ctx, ASTNode *node, Token t)
Checks if a type is copyable.
Definition parser_expr.c:189
ASTNode * find_struct_def(ParserContext *ctx, const char *name)
Finds a struct definition.
Definition parser_utils.c:747
ASTNode * parse_type_alias(ParserContext *ctx, Lexer *l, int is_opaque)
Parses a type alias.
Definition parser_decl.c:901
void instantiate_generic_multi(ParserContext *ctx, const char *name, char **args, int arg_count, Token t)
Instantiates a multi-parameter generic.
Definition parser_utils.c:2738
FuncSig * find_func(ParserContext *ctx, const char *name)
Finds a function.
Definition parser_utils.c:1881
ASTNode * parse_asm(ParserContext *ctx, Lexer *l)
Parses an asm statement.
Definition parser_stmt.c:588
char * process_printf_sugar(ParserContext *ctx, const char *content, int newline, const char *target, char ***used_syms, int *count, int check_symbols)
Processes a formatted string.
Definition parser_stmt.c:1609
char * find_similar_symbol(ParserContext *ctx, const char *name)
Definition parser_utils.c:3664
SelectiveImport * find_selective_import(ParserContext *ctx, const char *name)
Finds a selective import.
Definition parser_utils.c:839
void instantiate_generic(ParserContext *ctx, const char *name, const char *concrete_type, const char *unmangled_type, Token t)
Instantiates a generic struct/function.
Definition parser_utils.c:2591
ASTNode * parse_defer(ParserContext *ctx, Lexer *l)
Parses a defer statement.
Definition parser_stmt.c:562
void register_type_alias(ParserContext *ctx, const char *alias, const char *original, int is_opaque, const char *defined_in_file)
Definition parser_utils.c:406
void register_enum_variant(ParserContext *ctx, const char *ename, const char *vname, int tag)
Registers an enum variant.
Definition parser_utils.c:526
void add_to_global_list(ParserContext *ctx, ASTNode *node)
Definition parser_utils.c:463
#define MAX_KNOWN_GENERICS
Definition parser.h:284
void register_selective_import(ParserContext *ctx, const char *symbol, const char *alias, const char *source_module)
Registers a selective import.
Definition parser_utils.c:828
ASTNode * parse_test(ParserContext *ctx, Lexer *l)
Parses a test definition.
Definition parser_stmt.c:925
int validate_types(ParserContext *ctx)
Validates types.
Definition parser_utils.c:3770
char * consume_and_rewrite(ParserContext *ctx, Lexer *l)
Consumes and rewrites tokens.
Definition parser_utils.c:3401
GenericFuncTemplate * find_func_template(ParserContext *ctx, const char *name)
Finds a function template.
Definition parser_utils.c:338
ASTNode * parse_import(ParserContext *ctx, Lexer *l)
Parses an import statement.
Definition parser_stmt.c:2979
ParserContext * g_parser_ctx
Definition utils.c:6
ASTNode * parse_primary(ParserContext *ctx, Lexer *l)
Parses a primary expression (literal, variable, grouping).
Definition parser_expr.c:1354
void register_func(ParserContext *ctx, const char *name, int count, char **defaults, Type **arg_types, Type *ret_type, int is_varargs, int is_async, Token decl_token)
Registers a function.
Definition parser_utils.c:288
char * parse_tuple_literal(ParserContext *ctx, Lexer *l, const char *tn)
Parses a tuple literal.
Definition parser_type.c:1119
char * replace_in_string(const char *src, const char *old_w, const char *new_w)
Replaces a substring in a string.
Definition parser_utils.c:887
void register_struct_def(ParserContext *ctx, const char *name, ASTNode *node)
Registers a struct definition.
Definition parser_utils.c:738
ASTNode * parse_def(ParserContext *ctx, Lexer *l)
Parses a def statement.
Definition parser_decl.c:799
void register_template(ParserContext *ctx, const char *name, ASTNode *node)
Registers a template.
Definition parser_utils.c:2362
Type * parse_type_formal(ParserContext *ctx, Lexer *l)
Parses a type formal.
Definition parser_type.c:882
void add_to_impl_list(ParserContext *ctx, ASTNode *node)
Definition parser_utils.c:455
const char * find_type_alias(ParserContext *ctx, const char *alias)
Finds a type alias.
Definition parser_utils.c:418
ASTNode * parse_comptime(ParserContext *ctx, Lexer *l)
Parses a comptime statement.
Definition parser_stmt.c:3537
ASTNode * parse_trait(ParserContext *ctx, Lexer *l)
Parses a trait definition.
Definition parser_struct.c:124
Module * find_module(ParserContext *ctx, const char *alias)
Finds a module.
Definition parser_utils.c:804
ASTNode * copy_ast_replacing(ASTNode *n, const char *p, const char *c, const char *os, const char *ns)
Copies an AST node and replaces its type parameters.
Definition parser_utils.c:1530
int check_impl(ParserContext *ctx, const char *trait, const char *strct)
Checks if a type implements a trait.
Definition parser_utils.c:2348
Type * parse_type_base(ParserContext *ctx, Lexer *l)
Parses a type base.
Definition parser_type.c:9
void analyze_lambda_captures(ParserContext *ctx, ASTNode *lambda)
Analyzes lambda captures.
Definition parser_expr.c:713
ASTNode * parse_loop(ParserContext *ctx, Lexer *l)
Parses a loop.
Definition parser_stmt.c:496
void init_builtins()
Initializes built-in types and symbols.
Definition parser_utils.c:278
ASTNode * parse_enum(ParserContext *ctx, Lexer *l)
Parses an enum definition.
Definition parser_struct.c:1067
ASTNode * parse_embed(ParserContext *ctx, Lexer *l)
Parses an embed.
Definition parser_type.c:1183
char * parse_and_convert_args(ParserContext *ctx, Lexer *l, char ***defaults_out, int *count_out, Type ***types_out, char ***names_out, int *is_varargs_out, char ***ctype_overrides_out)
Parses and converts arguments.
Definition parser_utils.c:3409
ASTNode * parse_arrow_lambda_single(ParserContext *ctx, Lexer *l, char *param_name)
Parses a single parameter arrow lambda.
Definition parser_expr.c:5978
int is_known_generic(ParserContext *ctx, char *name)
Checks if a name is a known generic parameter.
Definition parser_utils.c:364
int check_opaque_alias_compat(ParserContext *ctx, Type *a, Type *b)
Checks compatibility of opaque aliases (allows access within defining file).
Definition parser_expr.c:3
int is_type_copy(ParserContext *ctx, Type *t)
Checks if a type is copyable.
Definition parser_expr.c:125
void add_to_enum_list(ParserContext *ctx, ASTNode *node)
Definition parser_utils.c:439
void add_instantiated_func(ParserContext *ctx, ASTNode *fn)
Definition parser_utils.c:520
char * extract_module_name(const char *path)
Definition parser_utils.c:857
ASTNode * parse_repeat(ParserContext *ctx, Lexer *l)
Parses a repeat loop.
Definition parser_stmt.c:505
void add_symbol(ParserContext *ctx, const char *n, const char *t, Type *type_info)
Adds a symbol to the current scope.
Definition parser_utils.c:141
char * process_fstring(ParserContext *ctx, const char *content, char ***used_syms, int *count)
Processes a formatted string.
Definition parser_utils.c:2200
void register_lambda(ParserContext *ctx, ASTNode *node)
Registers a lambda.
Definition parser_utils.c:550
Type * find_symbol_type_info(ParserContext *ctx, const char *n)
Finds a symbol's type information.
Definition parser_utils.c:194
ZenSymbol * find_symbol_in_all(ParserContext *ctx, const char *n)
Finds a symbol in all scopes.
Definition parser_utils.c:264
void register_type_usage(ParserContext *ctx, const char *name, Token t)
Registers a type usage.
Definition parser_utils.c:3756
ASTNode * parse_impl(ParserContext *ctx, Lexer *l)
Parses an implementation.
Definition parser_struct.c:264
Precedence
Operator precedence for expression parsing.
Definition parser.h:14
@ PREC_UNARY
Unary operators.
Definition parser.h:24
@ PREC_TERNARY
Ternary operator.
Definition parser.h:17
@ PREC_NONE
No precedence.
Definition parser.h:15
@ PREC_EQUALITY
Equality operators.
Definition parser.h:20
@ PREC_OR
Logical OR.
Definition parser.h:18
@ PREC_FACTOR
Multiplication and division.
Definition parser.h:23
@ PREC_ASSIGNMENT
Assignment operators.
Definition parser.h:16
@ PREC_PRIMARY
Primary expressions.
Definition parser.h:26
@ PREC_CALL
Function calls.
Definition parser.h:25
@ PREC_COMPARISON
Comparison operators.
Definition parser.h:21
@ PREC_TERM
Addition and subtraction.
Definition parser.h:22
@ PREC_AND
Logical AND.
Definition parser.h:19
char * sanitize_mangled_name(const char *name)
Sanitizes a mangled name for use in codegen.
Definition parser_utils.c:1802
const char * resolve_plugin(ParserContext *ctx, const char *name_or_alias)
Resolves a plugin by name or alias.
Definition parser_utils.c:3737
ASTNode * parse_statement(ParserContext *ctx, Lexer *l)
Parses a statement.
Definition parser_stmt.c:2101
ASTNode * parse_var_decl(ParserContext *ctx, Lexer *l)
Parses a variable declaration.
Definition parser_decl.c:307
char * instantiate_function_template(ParserContext *ctx, const char *name, const char *concrete_type, const char *unmangled_type)
Instantiates a function template.
Definition parser_utils.c:2045
ASTNode * parse_match(ParserContext *ctx, Lexer *l)
Parses a match statement.
Definition parser_stmt.c:146
TypeAlias * find_type_alias_node(ParserContext *ctx, const char *name)
Registers a type alias.
Definition parser_utils.c:424
void mark_file_imported(ParserContext *ctx, const char *path)
Marks a file as imported.
Definition parser_utils.c:2852
Token expect(Lexer *l, TokenType type, const char *msg)
Expects a token of a specific type.
Definition parser_utils.c:14
ASTNode * parse_plugin(ParserContext *ctx, Lexer *l)
Parses a plugin statement.
Definition parser_stmt.c:3547
ASTNode * parse_macro_call(ParserContext *ctx, Lexer *l, char *name)
Parses a macro call.
Definition parser_stmt.c:1982
DeprecatedFunc * find_deprecated_func(ParserContext *ctx, const char *name)
Finds a deprecated function.
Definition parser_utils.c:324
void add_to_func_list(ParserContext *ctx, ASTNode *node)
Definition parser_utils.c:447
ASTNode * parse_for(ParserContext *ctx, Lexer *l)
Parses a for loop.
Definition parser_stmt.c:1173
void register_generic(ParserContext *ctx, char *name)
Registers a known generic type parameter.
Definition parser_utils.c:352
char * patch_self_args(const char *args, const char *struct_name)
Patches self arguments in a function.
Definition parser_decl.c:213
void register_plugin(ParserContext *ctx, const char *name, const char *alias)
Registers a plugin.
Definition parser_utils.c:3696
ASTNode * parse_expr_prec(ParserContext *ctx, Lexer *l, Precedence min_prec)
Parses an expression with minimum precedence.
Definition parser_expr.c:3613
void enter_scope(ParserContext *ctx)
Enters a new scope (pushes to scope stack).
Definition parser_utils.c:112
ASTNode * parse_arrow_lambda_multi(ParserContext *ctx, Lexer *l, char **param_names, int num_params)
Parses a multi-parameter arrow lambda.
Definition parser_expr.c:6073
void warn_c_reserved_word(Token t, const char *name)
Warns about a C reserved word.
Definition parser_utils.c:71
int is_token(Token t, const char *s)
Checks if a token matches a string.
Definition parser_utils.c:25
char * token_strdup(Token t)
Duplicates a token.
Definition parser_utils.c:31
char * consume_until_semicolon(Lexer *l)
Consumes tokens until a semicolon is found.
Definition parser_utils.c:78
void register_impl(ParserContext *ctx, const char *trait, const char *strct)
Registers an implementation.
Definition parser_utils.c:2339
void register_extern_symbol(ParserContext *ctx, const char *name)
Registers an external symbol.
Definition parser_utils.c:558
char * parse_type(ParserContext *ctx, Lexer *l)
Parses a type.
Definition parser_type.c:1036
void register_func_template(ParserContext *ctx, const char *name, const char *param, ASTNode *node)
Registers a function template.
Definition parser_utils.c:305
ASTNode * parse_lambda(ParserContext *ctx, Lexer *l)
Parses a lambda.
Definition parser_expr.c:841
void register_deprecated_func(ParserContext *ctx, const char *name, const char *reason)
Registers a deprecated function.
Definition parser_utils.c:315
ASTNode * parse_program(ParserContext *ctx, Lexer *l)
Parses a program.
Definition parser_core.c:621
ASTNode * parse_while(ParserContext *ctx, Lexer *l)
Parses a while loop.
Definition parser_stmt.c:1145
char * find_symbol_type(ParserContext *ctx, const char *n)
Finds a symbol's type.
Definition parser_utils.c:217
int is_c_reserved_word(const char *name)
Checks if a name is a C reserved word.
Definition parser_utils.c:59
ASTNode * parse_unless(ParserContext *ctx, Lexer *l)
Parses an unless statement.
Definition parser_stmt.c:517
ASTNode * parse_program_nodes(ParserContext *ctx, Lexer *l)
Main loop to parse top-level nodes in a file.
Definition parser_core.c:11
ASTNode * parse_impl_trait(ParserContext *ctx, Lexer *l)
Parses an implementation trait.
ZenSymbol * find_symbol_entry(ParserContext *ctx, const char *n)
Finds a symbol's entry.
Definition parser_utils.c:240
ASTNode * parse_assert(ParserContext *ctx, Lexer *l)
Parses an assert statement.
Definition parser_stmt.c:947
char * parse_array_literal(ParserContext *ctx, Lexer *l, const char *st)
Parses an array literal.
Definition parser_type.c:1043
void add_symbol_with_token(ParserContext *ctx, const char *n, const char *t, Type *type_info, Token tok)
Adds a symbol with definition token location.
Definition parser_utils.c:146
Definition ast.h:187
Functions marked as deprecated.
Definition parser.h:207
char * name
Definition parser.h:208
char * reason
Optional reason for deprecation.
Definition parser.h:209
struct DeprecatedFunc * next
Definition parser.h:210
Registry of enum variants.
Definition parser.h:196
char * variant_name
Name of the variant.
Definition parser.h:198
char * enum_name
Name of the enum.
Definition parser.h:197
struct EnumVariantReg * next
Definition parser.h:200
int tag_id
Integration tag value.
Definition parser.h:199
Registry entry for a function signature.
Definition parser.h:79
int must_use
1 if return value must be used.
Definition parser.h:88
int total_args
Total argument count.
Definition parser.h:82
int is_async
1 if async.
Definition parser.h:87
Token decl_token
declaration token.
Definition parser.h:81
Type ** arg_types
Argument types.
Definition parser.h:84
int is_varargs
1 if variadic.
Definition parser.h:86
struct FuncSig * next
Next function in registry.
Definition parser.h:89
char ** defaults
Default values for arguments (or NULL).
Definition parser.h:83
Type * ret_type
Return type.
Definition parser.h:85
char * name
Function name.
Definition parser.h:80
Template for a generic function.
Definition parser.h:115
char * name
Template name.
Definition parser.h:116
ASTNode * func_node
The function AST node.
Definition parser.h:118
struct GenericFuncTemplate * next
Definition parser.h:119
char * generic_param
Generic parameters string (legacy).
Definition parser.h:117
Template for a generic implementation block.
Definition parser.h:126
char * generic_param
Generic parameters.
Definition parser.h:128
char * struct_name
Target struct name.
Definition parser.h:127
ASTNode * impl_node
The impl block AST node.
Definition parser.h:129
struct GenericImplTemplate * next
Definition parser.h:130
Template for a generic struct.
Definition parser.h:105
char * name
Template name.
Definition parser.h:106
ASTNode * struct_node
The struct AST node (containing generic params).
Definition parser.h:107
struct GenericTemplate * next
Definition parser.h:108
Registry for trait implementations.
Definition parser.h:240
struct ImplReg * next
Definition parser.h:243
char * trait
Trait name.
Definition parser.h:241
char * strct
Implementing struct name.
Definition parser.h:242
Represents an imported source file (to prevent cycles/duplication).
Definition parser.h:137
struct ImportedFile * next
Definition parser.h:139
char * path
Absolute file path.
Definition parser.h:138
Loaded compiler plugin.
Definition parser.h:250
struct ImportedPlugin * next
Definition parser.h:253
char * name
Plugin name (e.g., "brainfuck").
Definition parser.h:251
char * alias
Optional usage alias.
Definition parser.h:252
Tracks a concrete instantiation of a generic template.
Definition parser.h:146
struct Instantiation * next
Definition parser.h:152
char * template_name
Original template name (e.g. "Vec").
Definition parser.h:148
char * concrete_arg
Concrete type argument string.
Definition parser.h:149
ASTNode * struct_node
The AST node of the instantiated struct.
Definition parser.h:151
char * unmangled_arg
Unmangled argument for substitution code.
Definition parser.h:150
char * name
Mangled name of the instantiation (e.g. "Vec_int").
Definition parser.h:147
Tracks a lambda (anonymous function) within the parser.
Definition parser.h:96
ASTNode * node
The AST node for the lambda.
Definition parser.h:97
struct LambdaRef * next
Definition parser.h:98
Lexer state.
Definition zprep.h:131
Represents a module (namespace/file).
Definition parser.h:217
struct Module * next
Definition parser.h:222
int is_c_header
1 if this is a C header import.
Definition parser.h:221
char * base_name
Base name of the module.
Definition parser.h:220
char * alias
Import alias (or default name).
Definition parser.h:218
char * path
File path.
Definition parser.h:219
Global compilation state and symbol table.
Definition parser.h:275
DeprecatedFunc * deprecated_funcs
Registry of deprecated functions.
Definition parser.h:324
SelectiveImport * selective_imports
Symbols imported via import { ... }.
Definition parser.h:314
ASTNode * current_impl_methods
Head of method list for current impl block.
Definition parser.h:321
Module * modules
List of registered modules.
Definition parser.h:313
StructDef * struct_defs
Registry of struct definitions (map name -> node).
Definition parser.h:303
StructRef * parsed_structs_list
List of all parsed struct nodes.
Definition parser.h:298
char ** extern_symbols
Explicitly declared extern symbols.
Definition parser.h:336
int is_fault_tolerant
1 if parser should recover from errors (LSP mode).
Definition parser.h:327
GenericTemplate * templates
Struct generic templates.
Definition parser.h:288
GenericFuncTemplate * func_templates
Function generic templates.
Definition parser.h:289
char * known_generics[MAX_KNOWN_GENERICS]
Stack of currently active generic type parameters.
Definition parser.h:286
ZenSymbol * all_symbols
comprehensive list of all symbols seen.
Definition parser.h:332
int in_defer_block
1 if currently parsing inside a defer block.
Definition parser.h:344
int has_async
1 if async/await features are used in the program.
Definition parser.h:343
void * error_callback_data
User data for error callback.
Definition parser.h:328
char * current_module_prefix
Prefix for current module (namespacing).
Definition parser.h:315
int has_external_includes
Set when #include <...> is used.
Definition parser.h:335
int skip_preamble
If 1, codegen won't emit standard preamble (includes etc).
Definition parser.h:341
ImportedFile * imported_files
List of files already included/imported.
Definition parser.h:316
ImportedPlugin * imported_plugins
List of active plugins.
Definition parser.h:317
int known_generics_count
Count of active generic parameters.
Definition parser.h:287
ASTNode * instantiated_funcs
List of AST nodes for instantiated functions.
Definition parser.h:295
FILE * hoist_out
File stream for hoisting code (e.g. from plugins).
Definition parser.h:340
Scope * current_scope
Current lexical scope for variable lookup.
Definition parser.h:276
StructRef * parsed_impls_list
List of all parsed impl blocks.
Definition parser.h:301
int extern_symbol_count
Count of external symbols.
Definition parser.h:337
GenericImplTemplate * impl_templates
Implementation block templates.
Definition parser.h:290
SliceType * used_slices
Cache of generated slice types.
Definition parser.h:308
int is_speculative
Flag to suppress side effects during speculative parsing.
Definition parser.h:348
TypeAlias * type_aliases
Defined type aliases.
Definition parser.h:310
Instantiation * instantiations
Cache of instantiated generic types.
Definition parser.h:293
int silent_warnings
Suppress warnings (e.g., during codegen interpolation).
Definition parser.h:349
ImplReg * registered_impls
Cache of type/trait implementations.
Definition parser.h:305
StructRef * parsed_globals_list
List of all parsed global variables.
Definition parser.h:302
EnumVariantReg * enum_variants
Registry of enum variants for global lookup.
Definition parser.h:304
struct TypeUsage * pending_type_validations
List of types to validate after parsing.
Definition parser.h:347
int is_repl
1 if running in REPL mode.
Definition parser.h:342
char * current_impl_struct
Name of struct currently being implemented (in impl block).
Definition parser.h:320
int lambda_counter
Counter for generating unique lambda IDs.
Definition parser.h:281
void(* on_error)(void *data, Token t, const char *msg)
Callback for reporting errors.
Definition parser.h:329
StructRef * parsed_funcs_list
List of all parsed function nodes.
Definition parser.h:300
StructRef * parsed_enums_list
List of all parsed enum nodes.
Definition parser.h:299
TupleType * used_tuples
Cache of generated tuple types.
Definition parser.h:309
FuncSig * func_registry
Registry of declared function signatures.
Definition parser.h:277
LambdaRef * global_lambdas
List of all lambdas generated during parsing.
Definition parser.h:280
ASTNode * instantiated_structs
List of AST nodes for instantiated structs.
Definition parser.h:294
Represents a lexical scope (block).
Definition parser.h:68
ZenSymbol * symbols
Linked list of symbols in this scope.
Definition parser.h:69
struct Scope * parent
Pointer to the parent scope (NULL for global).
Definition parser.h:70
Symbol imported via selective import (import { X }).
Definition parser.h:229
char * source_module
Origin module.
Definition parser.h:232
struct SelectiveImport * next
Definition parser.h:233
char * symbol
Symbol name.
Definition parser.h:230
char * alias
Local alias.
Definition parser.h:231
Track used slice types for generation.
Definition parser.h:178
struct SliceType * next
Definition parser.h:180
char * name
Definition parser.h:179
Definition of a struct (lookup cache).
Definition parser.h:168
char * name
Definition parser.h:169
struct StructDef * next
Definition parser.h:171
ASTNode * node
Definition parser.h:170
Reference to a parsed struct (list node).
Definition parser.h:159
struct StructRef * next
Definition parser.h:161
ASTNode * node
Definition parser.h:160
Represents a source token.
Definition zprep.h:119
Track used tuple signatures for generation.
Definition parser.h:187
struct TupleType * next
Definition parser.h:189
char * sig
Definition parser.h:188
Type alias definition.
Definition parser.h:260
char * original_type
Original type.
Definition parser.h:262
char * alias
New type name.
Definition parser.h:261
char * defined_in_file
Definition parser.h:265
int is_opaque
Definition parser.h:264
struct TypeAlias * next
Definition parser.h:263
Definition parser.h:353
Token location
Definition parser.h:355
struct TypeUsage * next
Definition parser.h:356
char * name
Definition parser.h:354
Represents a formal type in the type system.
Definition ast.h:81
Represents a symbol in the symbol table.
Definition parser.h:48
int is_moved
1 if the value has been moved (ownership transfer).
Definition parser.h:58
int is_const_value
1 if it is a compile-time constant.
Definition parser.h:55
Token decl_token
Token where the symbol was declared.
Definition parser.h:54
int is_used
1 if the symbol has been referenced.
Definition parser.h:52
char * type_name
String representation of the type.
Definition parser.h:50
Type * type_info
Formal type definition.
Definition parser.h:51
int is_autofree
1 if it requires automatic memory management (RAII).
Definition parser.h:53
int is_def
1 if it is a definition (vs declaration).
Definition parser.h:56
int const_int_val
Integer value if it is a constant.
Definition parser.h:57
struct ZenSymbol * next
Next symbol in the bucket/list (chaining).
Definition parser.h:59
char * name
Symbol name.
Definition parser.h:49
TokenType
Token types for the Lexer.
Definition zprep.h:58