|
1 | 1 | use core::cmp::Ordering; |
2 | 2 | use core::{fmt, mem}; |
3 | 3 |
|
4 | | -use super::binary::Binary; |
5 | | -use super::blocks::Block; |
| 4 | +use super::super::types::binary::Binary; |
| 5 | +use super::super::types::blocks::Block; |
| 6 | +use super::super::types::literal::{Attribute, Literal, Variable, VariableName}; |
| 7 | +use super::super::types::operator::{Associativity, Operator as _}; |
| 8 | +use super::super::types::unary::Unary; |
| 9 | +use super::super::types::{FunctionCall, ListInitialiser}; |
6 | 10 | use super::conversions::OperatorConversions; |
7 | | -use super::literal::{Attribute, Literal, Variable, VariableName}; |
8 | | -use super::traits::{Associativity, Operator as _}; |
9 | | -use super::unary::Unary; |
10 | | -use super::{FunctionCall, ListInitialiser, Ternary}; |
11 | 11 | use crate::EMPTY; |
12 | | -use crate::parser::keyword::control_flow::node::ControlFlowNode; |
13 | | - |
14 | | -/// Struct to represent the AST |
15 | | -#[derive(Debug, Default, PartialEq)] |
16 | | -pub enum Ast { |
17 | | - Binary(Binary), |
18 | | - Block(Block), |
19 | | - ControlFlow(ControlFlowNode), |
20 | | - #[default] |
21 | | - Empty, |
22 | | - FunctionCall(FunctionCall), |
23 | | - Leaf(Literal), |
24 | | - ListInitialiser(ListInitialiser), |
25 | | - ParensBlock(ParensBlock), |
26 | | - Ternary(Ternary), |
27 | | - Unary(Unary), |
28 | | - // TODO: CompoundLiteral(CompoundLiteral), Cast, & SpecialUnary(SpecialUnary), |
29 | | -} |
| 12 | +use crate::parser::types::Ast; |
| 13 | +use crate::parser::types::ternary::Ternary; |
30 | 14 |
|
31 | 15 | impl Ast { |
32 | 16 | /// Finds the leaf the most left possible, checks it is a variable and |
@@ -133,9 +117,7 @@ impl Ast { |
133 | 117 | // |
134 | 118 | // |
135 | 119 | // atomic: failure |
136 | | - Self::ParensBlock(ParensBlock(old)) => { |
137 | | - Err(successive_literal_error("Parenthesis group", old, node)) |
138 | | - } |
| 120 | + Self::ParensBlock(old) => Err(successive_literal_error("Parenthesis group", old, node)), |
139 | 121 | Self::Leaf(old) => Err(successive_literal_error("Literal", old, node)), |
140 | 122 | // |
141 | 123 | // |
@@ -339,36 +321,12 @@ impl fmt::Display for Ast { |
339 | 321 | Self::Unary(val) => val.fmt(f), |
340 | 322 | Self::Block(block) => block.fmt(f), |
341 | 323 | Self::ListInitialiser(list_initialiser) => list_initialiser.fmt(f), |
342 | | - Self::ParensBlock(ParensBlock(node)) => write!(f, "({node})"), |
| 324 | + Self::ParensBlock(parens) => parens.fmt(f), |
343 | 325 | Self::ControlFlow(_) => todo!(), |
344 | 326 | } |
345 | 327 | } |
346 | 328 | } |
347 | 329 |
|
348 | | -/// Struct to represent parenthesis |
349 | | -/// |
350 | | -/// The [`Ast`] is what is inside of the parenthesis. |
351 | | -/// |
352 | | -/// # Examples |
353 | | -/// |
354 | | -/// If the C source is `(x = 2)`, the node is a [`ParensBlock`] with value the |
355 | | -/// [`Ast`] of `x=2`. |
356 | | -#[derive(Debug, Default, PartialEq)] |
357 | | -pub struct ParensBlock(Box<Ast>); |
358 | | - |
359 | | -impl ParensBlock { |
360 | | - /// Adds parenthesis around an [`Ast`]. |
361 | | - /// |
362 | | - /// # Examples |
363 | | - /// |
364 | | - /// ```ignore |
365 | | - /// assert!(ParensBlock::make_parens_ast(Ast::Empty) == Ast::ParensBlock(Box::new(Ast::Empty))); |
366 | | - /// ``` |
367 | | - pub fn make_parens_ast(node: Ast) -> Ast { |
368 | | - Ast::ParensBlock(Self(Box::new(node))) |
369 | | - } |
370 | | -} |
371 | | - |
372 | 330 | /// Makes an error [`String`] for consecutive literals. |
373 | 331 | /// |
374 | 332 | /// If two consecutive literals are found, the [`crate::parser`] fails, and this |
|
0 commit comments