From 1afde9ce354e18dbb5523fbff562c8ffb5833792 Mon Sep 17 00:00:00 2001 From: John Date: Thu, 29 Feb 2024 19:49:50 -0600 Subject: [PATCH] cl-ast: Move AST definition into its own crate --- Cargo.toml | 1 + cl-ast/Cargo.toml | 11 +++++++++++ {libconlang/src/ast => cl-ast/src}/ast_impl.rs | 0 libconlang/src/ast.rs => cl-ast/src/lib.rs | 2 ++ cl-interpret/Cargo.toml | 3 ++- cl-interpret/src/interpret.rs | 2 +- cl-interpret/src/lib.rs | 4 ++-- cl-interpret/src/tests.rs | 5 +++-- cl-repl/Cargo.toml | 1 + cl-repl/examples/collect-identifiers.rs | 2 +- cl-repl/src/lib.rs | 3 ++- libconlang/Cargo.toml | 1 + libconlang/src/lib.rs | 2 -- libconlang/src/parser.rs | 6 ++---- libconlang/src/resolver.rs | 5 ----- 15 files changed, 29 insertions(+), 19 deletions(-) create mode 100644 cl-ast/Cargo.toml rename {libconlang/src/ast => cl-ast/src}/ast_impl.rs (100%) rename libconlang/src/ast.rs => cl-ast/src/lib.rs (99%) diff --git a/Cargo.toml b/Cargo.toml index 9168de3..74264b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ members = [ "cl-interpret", "cl-structures", "cl-token", + "cl-ast", ] resolver = "2" diff --git a/cl-ast/Cargo.toml b/cl-ast/Cargo.toml new file mode 100644 index 0000000..3aed4e9 --- /dev/null +++ b/cl-ast/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "cl-ast" +repository.workspace = true +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true +publish.workspace = true + +[dependencies] +cl-structures = { path = "../cl-structures" } diff --git a/libconlang/src/ast/ast_impl.rs b/cl-ast/src/ast_impl.rs similarity index 100% rename from libconlang/src/ast/ast_impl.rs rename to cl-ast/src/ast_impl.rs diff --git a/libconlang/src/ast.rs b/cl-ast/src/lib.rs similarity index 99% rename from libconlang/src/ast.rs rename to cl-ast/src/lib.rs index e221d7f..f4c3cc3 100644 --- a/libconlang/src/ast.rs +++ b/cl-ast/src/lib.rs @@ -9,6 +9,8 @@ //! - [AssignKind], [BinaryKind], and [UnaryKind] operators //! - [Ty] and [TyKind]: Type qualifiers //! - [Path]: Path expressions +#![feature(decl_macro)] + use cl_structures::span::*; pub mod ast_impl; diff --git a/cl-interpret/Cargo.toml b/cl-interpret/Cargo.toml index fd09019..df93b35 100644 --- a/cl-interpret/Cargo.toml +++ b/cl-interpret/Cargo.toml @@ -9,4 +9,5 @@ publish.workspace = true [dependencies] conlang = { path = "../libconlang" } -cl-structures = { path = "../cl-structures"} +cl-ast = { path = "../cl-ast" } +cl-structures = { path = "../cl-structures" } diff --git a/cl-interpret/src/interpret.rs b/cl-interpret/src/interpret.rs index 5be310c..c059596 100644 --- a/cl-interpret/src/interpret.rs +++ b/cl-interpret/src/interpret.rs @@ -6,7 +6,7 @@ //! one in any situation. use super::*; -use conlang::ast::*; +use cl_ast::*; /// A work-in-progress tree walk interpreter for Conlang pub trait Interpret { /// Interprets this thing in the given [`Environment`]. diff --git a/cl-interpret/src/lib.rs b/cl-interpret/src/lib.rs index 9ddae23..b859816 100644 --- a/cl-interpret/src/lib.rs +++ b/cl-interpret/src/lib.rs @@ -297,7 +297,7 @@ pub mod interpret; pub mod function { //! Represents a block of code which lives inside the Interpreter use super::{Callable, ConValue, Environment, Error, IResult, Interpret}; - use conlang::ast::{Function as FnDecl, Identifier, Param}; + use cl_ast::{Function as FnDecl, Identifier, Param}; /// Represents a block of code which persists inside the Interpreter #[derive(Clone, Debug)] pub struct Function { @@ -354,7 +354,7 @@ pub mod env { temp_type_impl::ConValue, BuiltIn, Callable, Interpret, }; - use conlang::ast::{Function as FnDecl, Identifier}; + use cl_ast::{Function as FnDecl, Identifier}; use std::{ collections::HashMap, fmt::Display, diff --git a/cl-interpret/src/tests.rs b/cl-interpret/src/tests.rs index 280095c..f603103 100644 --- a/cl-interpret/src/tests.rs +++ b/cl-interpret/src/tests.rs @@ -1,6 +1,7 @@ #![allow(unused_imports)] use crate::{env::Environment, temp_type_impl::ConValue, Interpret}; -use conlang::{ast::*, lexer::Lexer, parser::Parser}; +use cl_ast::*; +use conlang::{lexer::Lexer, parser::Parser}; pub use macros::*; mod macros { @@ -208,7 +209,7 @@ mod fn_declarations { } mod operators { - use conlang::ast::Tuple; + use cl_ast::Tuple; use super::*; #[test] diff --git a/cl-repl/Cargo.toml b/cl-repl/Cargo.toml index ca36a13..bd20a02 100644 --- a/cl-repl/Cargo.toml +++ b/cl-repl/Cargo.toml @@ -11,6 +11,7 @@ publish.workspace = true [dependencies] conlang = { path = "../libconlang" } +cl-ast = { path = "../cl-ast" } cl-interpret = { path = "../cl-interpret" } cl-token = { path = "../cl-token" } crossterm = "0.27.0" diff --git a/cl-repl/examples/collect-identifiers.rs b/cl-repl/examples/collect-identifiers.rs index ebc6d13..6ced9bf 100644 --- a/cl-repl/examples/collect-identifiers.rs +++ b/cl-repl/examples/collect-identifiers.rs @@ -125,7 +125,7 @@ use collectible::Collectible; pub mod collectible { use super::Collector; - use conlang::ast::*; + use cl_ast::*; pub trait Collectible<'code> { fn collect(&'code self, c: &mut Collector<'code>); } diff --git a/cl-repl/src/lib.rs b/cl-repl/src/lib.rs index bb46eb7..15bd23b 100644 --- a/cl-repl/src/lib.rs +++ b/cl-repl/src/lib.rs @@ -72,8 +72,9 @@ pub mod program { use cl_interpret::{ env::Environment, error::IResult, interpret::Interpret, temp_type_impl::ConValue, }; + + use cl_ast::{self as ast, ast_impl::format::Pretty}; use conlang::{ - ast::{self, ast_impl::format::Pretty}, // pretty_printer::{PrettyPrintable, Printer}, lexer::Lexer, parser::{error::PResult, Parser}, diff --git a/libconlang/Cargo.toml b/libconlang/Cargo.toml index de72233..d88cead 100644 --- a/libconlang/Cargo.toml +++ b/libconlang/Cargo.toml @@ -13,5 +13,6 @@ repository.workspace = true [dependencies] unicode-xid = "0.2.4" +cl-ast = { path = "../cl-ast" } cl-structures = { path = "../cl-structures" } cl-token = { path = "../cl-token" } diff --git a/libconlang/src/lib.rs b/libconlang/src/lib.rs index 5ce6951..7cc7af3 100644 --- a/libconlang/src/lib.rs +++ b/libconlang/src/lib.rs @@ -2,8 +2,6 @@ #![warn(clippy::all)] #![feature(decl_macro)] -pub mod ast; - pub mod lexer; pub mod parser; diff --git a/libconlang/src/parser.rs b/libconlang/src/parser.rs index bb67afa..33f8107 100644 --- a/libconlang/src/parser.rs +++ b/libconlang/src/parser.rs @@ -9,10 +9,8 @@ use self::error::{ ErrorKind::{self, *}, PResult, Parsing, }; -use crate::{ - ast::*, - lexer::{error::Error as LexError, Lexer}, -}; +use crate::lexer::{error::Error as LexError, Lexer}; +use cl_ast::*; use cl_structures::span::*; use cl_token::*; diff --git a/libconlang/src/resolver.rs b/libconlang/src/resolver.rs index 4d5e5f9..03401f5 100644 --- a/libconlang/src/resolver.rs +++ b/libconlang/src/resolver.rs @@ -853,11 +853,6 @@ mod ast1 { // } } -mod ast { - #![allow(unused_imports)] - use crate::ast::*; -} - // heakc yea man, generics impl Resolve for Option { fn resolve(&mut self, resolver: &mut Resolver) -> TyResult {