From 4c4f9f743d9b8cb490f3266bb662b44ba7d99e86 Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Mon, 22 Feb 2021 22:51:38 +0100 Subject: [PATCH] chore: extract AST to own module --- src/ast/README.md | 5 +++++ src/{parser/node_type.rs => ast/mod.rs} | 2 +- src/builder/mod.rs | 2 +- src/generator/c.rs | 2 +- src/generator/js.rs | 2 +- src/generator/llvm.rs | 2 +- src/generator/mod.rs | 2 +- src/generator/tests/c_tests.rs | 2 +- src/generator/x86.rs | 2 +- src/main.rs | 1 + src/parser/infer.rs | 3 ++- src/parser/mod.rs | 3 +-- src/parser/parser.rs | 2 +- src/parser/rules.rs | 3 +-- src/parser/tests.rs | 2 +- 15 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 src/ast/README.md rename src/{parser/node_type.rs => ast/mod.rs} (99%) diff --git a/src/ast/README.md b/src/ast/README.md new file mode 100644 index 0000000..b24ca73 --- /dev/null +++ b/src/ast/README.md @@ -0,0 +1,5 @@ +# AST + +This module contains the node types of the Sabre AST. + +The most important node is `Module`, which is the abstract representation of a Sabre file. diff --git a/src/parser/node_type.rs b/src/ast/mod.rs similarity index 99% rename from src/parser/node_type.rs rename to src/ast/mod.rs index 4347ce2..bef4963 100644 --- a/src/parser/node_type.rs +++ b/src/ast/mod.rs @@ -2,7 +2,7 @@ use crate::lexer::*; use core::convert::TryFrom; use std::collections::HashMap; /** - * Copyright 2020 Garrit Franke + * Copyright 2021 Garrit Franke * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/builder/mod.rs b/src/builder/mod.rs index 444edc3..5b72c32 100644 --- a/src/builder/mod.rs +++ b/src/builder/mod.rs @@ -1,9 +1,9 @@ +use crate::ast::Module; use crate::generator; use crate::lexer; use crate::parser; use crate::Lib; use crate::PathBuf; -use parser::node_type::Module; use std::env; /** * Copyright 2021 Garrit Franke diff --git a/src/generator/c.rs b/src/generator/c.rs index 2069623..944ce2c 100644 --- a/src/generator/c.rs +++ b/src/generator/c.rs @@ -14,7 +14,7 @@ * limitations under the License. */ use crate::generator::Generator; -use crate::parser::node_type::*; +use crate::ast::*; use crate::util::Either; pub struct CGenerator; diff --git a/src/generator/js.rs b/src/generator/js.rs index 1652502..f362624 100644 --- a/src/generator/js.rs +++ b/src/generator/js.rs @@ -14,7 +14,7 @@ * limitations under the License. */ use crate::generator::Generator; -use crate::parser::node_type::*; +use crate::ast::*; use std::collections::HashMap; pub struct JsGenerator; diff --git a/src/generator/llvm.rs b/src/generator/llvm.rs index cc8e743..970e481 100644 --- a/src/generator/llvm.rs +++ b/src/generator/llvm.rs @@ -14,7 +14,7 @@ * limitations under the License. */ use crate::generator::Generator; -use crate::parser::node_type::*; +use crate::ast::*; use inkwell::context::Context; use inkwell::module; use inkwell::types::*; diff --git a/src/generator/mod.rs b/src/generator/mod.rs index 43358ac..24d5304 100644 --- a/src/generator/mod.rs +++ b/src/generator/mod.rs @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -use crate::parser::node_type::*; +use crate::ast::*; #[cfg(feature = "backend_c")] pub mod c; diff --git a/src/generator/tests/c_tests.rs b/src/generator/tests/c_tests.rs index d4b7b5b..1285516 100644 --- a/src/generator/tests/c_tests.rs +++ b/src/generator/tests/c_tests.rs @@ -1,5 +1,5 @@ use crate::generator::c::generate_type; -use crate::parser::node_type::Type; +use crate::ast::Type; use crate::util::Either; #[test] diff --git a/src/generator/x86.rs b/src/generator/x86.rs index ff91a10..2b4c570 100644 --- a/src/generator/x86.rs +++ b/src/generator/x86.rs @@ -14,7 +14,7 @@ * limitations under the License. */ use crate::generator::Generator; -use crate::parser::node_type::{Function, Module, Statement}; +use crate::ast::{Function, Module, Statement}; struct Assembly { asm: Vec, diff --git a/src/main.rs b/src/main.rs index 70d5278..c8bfeb4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,7 @@ extern crate tempfile; use std::path::PathBuf; use structopt::StructOpt; +mod ast; mod builder; mod command; mod generator; diff --git a/src/parser/infer.rs b/src/parser/infer.rs index 677beb2..2836a7c 100644 --- a/src/parser/infer.rs +++ b/src/parser/infer.rs @@ -1,3 +1,5 @@ +use crate::ast::{Expression, Module, Statement, SymbolTable, Type}; + /** * Copyright 2021 Garrit Franke * @@ -13,7 +15,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -use super::node_type::*; /// Try to infer types of variables /// diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 99113c9..1dc380b 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -14,13 +14,12 @@ * limitations under the License. */ mod infer; -pub mod node_type; // TODO: Resolve this lint by renaming the module #[allow(clippy::module_inception)] mod parser; mod rules; +use crate::ast::Module; use crate::lexer::Token; -use node_type::Module; #[cfg(test)] mod tests; diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 5467181..4f66c6c 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -17,7 +17,7 @@ use crate::lexer::Keyword; use crate::lexer::Position; use crate::lexer::{Token, TokenKind}; use crate::parser::infer::infer; -use crate::parser::node_type::*; +use crate::ast::*; use crate::util::string_util::highlight_position_in_file; use std::convert::TryFrom; use std::iter::Peekable; diff --git a/src/parser/rules.rs b/src/parser/rules.rs index 0aab785..2e8d3f3 100644 --- a/src/parser/rules.rs +++ b/src/parser/rules.rs @@ -1,6 +1,5 @@ -use super::node_type::Statement; -use super::node_type::*; use super::parser::Parser; +use crate::ast::*; use crate::lexer::Keyword; use crate::lexer::{TokenKind, Value}; use std::collections::HashMap; diff --git a/src/parser/tests.rs b/src/parser/tests.rs index e0291a9..206fa2d 100644 --- a/src/parser/tests.rs +++ b/src/parser/tests.rs @@ -14,7 +14,7 @@ * limitations under the License. */ use crate::lexer::*; -use crate::parser::node_type::*; +use crate::ast::*; use crate::parser::parse; #[test]