Browse Source

chore: extract AST to own module

master
Garrit Franke 1 year ago
parent
commit
4c4f9f743d
  1. 5
      src/ast/README.md
  2. 2
      src/ast/mod.rs
  3. 2
      src/builder/mod.rs
  4. 2
      src/generator/c.rs
  5. 2
      src/generator/js.rs
  6. 2
      src/generator/llvm.rs
  7. 2
      src/generator/mod.rs
  8. 2
      src/generator/tests/c_tests.rs
  9. 2
      src/generator/x86.rs
  10. 1
      src/main.rs
  11. 3
      src/parser/infer.rs
  12. 3
      src/parser/mod.rs
  13. 2
      src/parser/parser.rs
  14. 3
      src/parser/rules.rs
  15. 2
      src/parser/tests.rs

5
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.

2
src/parser/node_type.rs → 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.

2
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

2
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;

2
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;

2
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::*;

2
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;

2
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]

2
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<String>,

1
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;

3
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
///

3
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;

2
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;

3
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;

2
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]

Loading…
Cancel
Save