lib/chant/src/parse/root.zig
daab053ee43316e1809a84551d573ddd1e5bf3d2
1 const std = @import("std");
2 const chant = @import("../root.zig");
3 const ast = @import("../ast/root.zig");
4 const statement = @import("statement.zig");
5 const external = @import("external.zig");
6 const translation = @import("unit.zig");
7
8 pub const Error = @import("error.zig").Error;
9 pub const assertion = @import("assert.zig");
10 pub const auto = @import("auto.zig");
11 pub const expression = @import("expression.zig");
12 pub const initializer = @import("initializer.zig");
13 pub const thread = @import("thread.zig");
14 const Token = chant.token.Token;
15
16 pub const state = @import("state/root.zig");
17 pub const Diagnostic = state.Diagnostic;
18 pub const Parser = state.Parser;
19 pub const Storage = state.Storage;
20 pub const Limits = state.Limits;
21 pub const Capacity = state.Capacity;
22 pub const CapacityError = state.CapacityError;
23 pub const Survey = state.Survey;
24 pub const Exhaustion = state.Exhaustion;
25 pub const TypeOrigin = state.TypeOrigin;
26 pub const TypePlacement = state.TypePlacement;
27 pub const survey = state.survey;
28 pub const init = state.init;
29
30 /// Parses `tokens` into a translation unit whose expression, statement and type
31 /// nodes sit in `nodes` and refer to one another by pointer, so lowering
32 /// (translating each parsed C function into Choir operations) can consume the
33 /// result. The call first admits `node_survey` (the record a counting pass
34 /// produced over the tokens) into `nodes`, which clears the node counts. The
35 /// call returns `error.SurveyTokensMismatch` when the survey was taken over a
36 /// different token slice or `error.NodeCapacityExceeded` when it asks for more
37 /// than the storage holds. The tree borrows `nodes`, parser node storage (a
38 /// byte buffer the caller allocates). The caller keeps that storage alive, and
39 /// parses nothing else into it, until it is done with the tree, and the
40 /// compiler driver finishes lowering before it releases the storage. The name
41 /// tables, scopes and lists the parser builds along the way come from `arena`.
42 pub fn parse(
43 arena: std.mem.Allocator,
44 nodes: *Storage,
45 node_survey: Survey,
46 tokens: []const Token,
47 ) (Error || Exhaustion)!ast.TranslationUnit {
48 var parser = try init(arena, nodes, node_survey, tokens);
49 return translation.parseTranslationUnit(&parser);
50 }
51
52 pub const parseExternal = external.parseExternal;
53 pub const parseTranslationUnit = translation.parseTranslationUnit;
54 pub const parseStatement = statement.parseStatement;
55 pub const parseExpression = expression.parseExpression;