lwb_parser/parser/syntax_file/ast/ast.rs
1#![allow(unused)]
2#![allow(non_snake_case)]
3#![allow(non_camel_case_types)]
4#![allow(clippy::all)]
5// |==========================================================|
6// | WARNING: THIS FILE IS AUTOMATICALLY GENERATED. |
7// | CHANGES TO IT WILL BE DELETED WHEN REGENERATED. |
8// | IN GENERAL, THIS FILE SHOULD NOT BE MODIFIED IN ANY WAY. |
9// |==========================================================|
10use super::prelude::*;
11#[derive(Debug, PartialEq, Serialize, Deserialize)]
12#[serde(crate = "self::serde")]
13pub struct Program<M>(pub M, pub Vec<SortOrMeta<M>>);
14#[derive(Debug, PartialEq, Serialize, Deserialize)]
15#[serde(crate = "self::serde")]
16pub enum SortOrMeta<M> {
17 Meta(M, Meta<M>),
18 Sort(M, Sort<M>),
19}
20///Other top-level constructs that are not sorts
21#[derive(Debug, PartialEq, Serialize, Deserialize)]
22#[serde(crate = "self::serde")]
23pub struct Meta<M>(pub M, pub Identifier<M>);
24///A sort is a group of constructors. See [`constructor`] for more details.
25///
26///There is one special sort, called `layout`. It can be used to denote
27///that a grammar should for example ignore certain whitespace or comments.
28///Between every part of an expression, the parser will attempt to parse the
29///layout sort 0 or more times, and throw away whatever it parses.
30///
31///Sorts can have doc-comments using triple slashes.
32#[derive(Debug, PartialEq, Serialize, Deserialize)]
33#[serde(crate = "self::serde")]
34pub enum Sort<M> {
35 SortDocumented(M, Vec<DocComment<M>>, Box<Sort<M>>),
36 Sort(
37 M,
38 Identifier<M>,
39 Option<AnnotationList<M>>,
40 Vec<Constructor<M>>,
41 ),
42 ///When a sort has only one constructor, it has simpler syntax.
43 SortSingle(
44 M,
45 Identifier<M>,
46 Vec<Expression<M>>,
47 Option<AnnotationList<M>>,
48 ),
49}
50///An identifier is any name of a constructor or sort, and is used in various places.
51///Identifiers always start with a letter (capital or not) or an underscore, and can be
52///followed by letters or numbers. This is very similar to how variables in most major
53///programming languages work.
54#[derive(Debug, PartialEq, Serialize, Deserialize)]
55#[serde(crate = "self::serde")]
56pub struct Identifier<M>(pub M, pub std::string::String);
57///A documentation comment (doc comment) is always associated with a sort
58///or constructor. It documents what it does. Doc comments will be interpreted
59///and will be put on the generated types during codegen.
60#[derive(Debug, PartialEq, Serialize, Deserialize)]
61#[serde(crate = "self::serde")]
62pub struct DocComment<M>(pub M, pub std::string::String);
63///Annotations are tags that modify a specific sort or more often constructor.
64#[derive(Debug, PartialEq, Serialize, Deserialize)]
65#[serde(crate = "self::serde")]
66pub struct AnnotationList<M>(pub M, pub Vec<Annotation<M>>);
67///A [`sort`] consists of constructors. A sort will try each of the constructors
68///from top to bottom, and use the first one that successfully parses the input string.
69///
70///A constructor consists of a name, followed by an [`expression`]
71///
72///Constructors can have doc-comments using triple slashes.
73#[derive(Debug, PartialEq, Serialize, Deserialize)]
74#[serde(crate = "self::serde")]
75pub enum Constructor<M> {
76 ConstructorDocumented(M, Vec<DocComment<M>>, Box<Constructor<M>>),
77 Constructor(
78 M,
79 Identifier<M>,
80 Vec<Expression<M>>,
81 Option<AnnotationList<M>>,
82 ),
83 ///using `test;` as a constructor desugars to `test = test;`
84 ConstructorBare(M, Identifier<M>, Option<AnnotationList<M>>),
85}
86///With expressions, you can give the syntax rules of a single constructor.
87///Expressions can be nested and combined.
88#[derive(Debug, PartialEq, Serialize, Deserialize)]
89#[serde(crate = "self::serde")]
90pub enum Expression<M> {
91 ///Repeat some expression zero or more times
92 ///Equivalent to `<expression> {0,}`
93 Star(M, Box<Expression<M>>),
94 ///Repeat some expression one or more times
95 ///Equivalent to `<expression> {1,}`
96 Plus(M, Box<Expression<M>>),
97 ///Optionally have some expression.
98 ///Equivalent to `<expression> {0,1}`
99 Maybe(M, Box<Expression<M>>),
100 ///Exact repetition. The expression is repeated an exact number of times. Equivalent
101 ///to ranged repetition with an equal lower and upper bound.
102 RepeatExact(M, Box<Expression<M>>, Number<M>),
103 ///Ranged repetition. The expression may be repeated any number of times, within the range.
104 ///Both bounds are inclusive.
105 RepeatRange(M, Box<Expression<M>>, Number<M>, Number<M>),
106 ///Ranged repetition, without upper bound (or an infinite maximum)
107 RepeatLower(M, Box<Expression<M>>, Number<M>),
108 ///Delimited expressions. Says that some expression should be repeatedly parsed,
109 ///but between two parses, a delimiter should be parsed too. For example, comma seperated expressions.
110 ///The final trailing keyword enables a trailing separator after the sequence. If not present, no trailing
111 ///separator is allowed.
112 Delimited(
113 M,
114 Box<Expression<M>>,
115 Box<Expression<M>>,
116 DelimitedBound<M>,
117 bool,
118 ),
119 ///Matches a piece of text exactly. Layout is parsed within a literal.
120 Literal(M, String<M>),
121 ///You can use parentheses to group parts of expressions.
122 Paren(M, Vec<Box<Expression<M>>>),
123 Labelled(M, Identifier<M>, Box<Expression<M>>),
124 ///Reference another sort within this expression.
125 ///That sort should be parsed in this position in the expression.
126 Sort(M, Identifier<M>),
127 ///A [`character class`](character-class) (range of characters) should be parsed here.
128 Class(M, CharacterClass<M>),
129}
130#[derive(Debug, PartialEq, Serialize, Deserialize)]
131#[serde(crate = "self::serde")]
132pub enum Annotation<M> {
133 ///Mark a constructor as being a mapping from sort x to sort x.
134 ///An example is a parenthesis rule:
135 ///```lwb,no_run
136 ///expr:
137 ///paren = "(" expr ")"
138 ///```
139 ///
140 ///In that case you don't want a variant in the expr rule that's called "paren".
141 ///Instead, by adding the `injection` annotation you tell the parser that this rule is purely to create a new priority level,
142 ///but to use the inner expr as the result of the parse. Thus there will be no rule called "paren".
143 Injection(M),
144 ///disable pretty printing. Doesn't work well anyway so don't bother with this annotation
145 NoPrettyPrint(M),
146 ///mark a rule to appear as just a string in the AST. Whatever structure is found within, throw it away and just store
147 ///whatever was parsed.
148 ///
149 ///Note that any AST node has the .as_str() method to request this string representation of the node. For
150 ///single-string rules this is simply the default.
151 SingleString(M),
152 ///don't accept any layout characters while parsing this rule
153 NoLayout(M),
154 ///Annotation for sorts. This sort will not appear in any of the constructors it's used in.
155 ///useful for for example the [`newline`] rule in this file.
156 Hidden(M),
157 ///if this rule manages to parse, display an error with the associated message
158 ///This annotation can be placed on constructors (these constructors then won't actually exist in the AST,
159 ///if the constructor is chosen an error is emitted), or on sorts. On a sort the annotation
160 ///has a slightly different effect. If none of the variants in the sort managed to parse
161 ///then alongside an "expected ...", that message will be displayed as well.
162 ///If this sort was the only possibility at a certain point, only the message will be displayed.
163 Error(M, String<M>),
164 ///Makes constructors of this rule generate as part of another rule.
165 ///This has one major requirement. If a is part-of b then
166 ///b must have a rule like `a=a;` (also written as just `a;`) to allow
167 ///any a to appear in b
168 ///
169 ///Injections on rule a become injections into rule b too.
170 PartOf(M, Identifier<M>),
171}
172#[derive(Debug, PartialEq, Serialize, Deserialize)]
173#[serde(crate = "self::serde")]
174pub struct Number<M>(pub M, pub std::string::String);
175///A delimited expression can be repeated just like normal repetition expressions.
176///To denote this, you can use a delimitation bound.
177#[derive(Debug, PartialEq, Serialize, Deserialize)]
178#[serde(crate = "self::serde")]
179pub enum DelimitedBound<M> {
180 ///Within a range or possible repetitions.
181 NumNum(M, Number<M>, Number<M>),
182 ///At least some number of repetitions, but no upper bound.
183 NumInf(M, Number<M>),
184 ///Exactly this number of repetitions.
185 Num(M, Number<M>),
186 Star(M),
187 ///One or more repetitions.
188 Plus(M),
189}
190#[derive(Debug, PartialEq, Serialize, Deserialize)]
191#[serde(crate = "self::serde")]
192pub enum String<M> {
193 Single(M, Vec<StringChar<M>>),
194 Double(M, Vec<StringChar<M>>),
195}
196///A character class represent a selection of terminal characters. This is similar to
197///Regex character classes. Character classes can be inverted by starting them with a `^`.
198///For example, `[^\n]` means it matches any character that is not a newline.
199///
200///Character classes can contain a range of characters. Either by listing each individual character, or using
201///a dash (`-`). For example, `[a-z]` means any character in the range a through z (inclusive!),
202///and `[abc]` means an a, b or c
203///
204///Note that to use a closing square bracket within a character class, you need to escape it.
205///
206///`[^\]]` means any character that isn't a square bracket.
207#[derive(Debug, PartialEq, Serialize, Deserialize)]
208#[serde(crate = "self::serde")]
209pub struct CharacterClass<M>(pub M, pub bool, pub Vec<CharacterClassItem<M>>);
210#[derive(Debug, PartialEq, Serialize, Deserialize)]
211#[serde(crate = "self::serde")]
212pub enum StringChar<M> {
213 Escaped(M, std::string::String),
214 Normal(M, std::string::String),
215}
216#[derive(Debug, PartialEq, Serialize, Deserialize)]
217#[serde(crate = "self::serde")]
218pub enum CharacterClassItem<M> {
219 Range(M, EscapeClosingBracket<M>, EscapeClosingBracket<M>),
220 SingleChar(M, EscapeClosingBracket<M>),
221}
222#[derive(Debug, PartialEq, Serialize, Deserialize)]
223#[serde(crate = "self::serde")]
224pub enum EscapeClosingBracket<M> {
225 Escaped(M, std::string::String),
226 Unescaped(M, std::string::String),
227}
228#[derive(Debug, PartialEq, Serialize, Deserialize)]
229#[serde(crate = "self::serde")]
230pub enum Layout<M> {
231 Simple(M, std::string::String),
232 Comment(M, Vec<std::string::String>),
233}
234pub type AST_ROOT<M> = Program<M>;