cl-parser: Move parser into its own crate
This commit is contained in:
parent
1afde9ce35
commit
cc281fc6ab
@ -6,6 +6,7 @@ members = [
|
||||
"cl-structures",
|
||||
"cl-token",
|
||||
"cl-ast",
|
||||
"cl-parser",
|
||||
]
|
||||
resolver = "2"
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
//! # The Abstract Syntax Tree
|
||||
//! Contains definitions of AST Nodes, to be derived by a [parser](super::parser).
|
||||
//! Contains definitions of Conlang AST Nodes.
|
||||
//!
|
||||
//! # Notable nodes
|
||||
//! - [Item] and [ItemKind]: Top-level constructs
|
||||
|
@ -8,6 +8,10 @@ license.workspace = true
|
||||
publish.workspace = true
|
||||
|
||||
[dependencies]
|
||||
conlang = { path = "../libconlang" }
|
||||
cl-ast = { path = "../cl-ast" }
|
||||
cl-structures = { path = "../cl-structures" }
|
||||
|
||||
|
||||
[dev-dependencies]
|
||||
conlang = { path = "../libconlang" }
|
||||
cl-parser = { path = "../cl-parser" }
|
||||
|
@ -1,7 +1,8 @@
|
||||
#![allow(unused_imports)]
|
||||
use crate::{env::Environment, temp_type_impl::ConValue, Interpret};
|
||||
use cl_ast::*;
|
||||
use conlang::{lexer::Lexer, parser::Parser};
|
||||
use cl_parser::Parser;
|
||||
use conlang::lexer::Lexer;
|
||||
pub use macros::*;
|
||||
|
||||
mod macros {
|
||||
|
14
cl-parser/Cargo.toml
Normal file
14
cl-parser/Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "cl-parser"
|
||||
repository.workspace = true
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
publish.workspace = true
|
||||
|
||||
[dependencies]
|
||||
cl-ast = { path = "../cl-ast" }
|
||||
cl-token = { path = "../cl-token" }
|
||||
cl-structures = { path = "../cl-structures" }
|
||||
conlang = { path = "../libconlang" }
|
@ -1,23 +1,26 @@
|
||||
//! Parses [tokens](super::token) into an [AST](super::ast)
|
||||
//! Parses [tokens](cl_token::token) into an [AST](cl_ast)
|
||||
//!
|
||||
//! For the full grammar, see [grammar.ebnf][1]
|
||||
//!
|
||||
//! [1]: https://git.soft.fish/j/Conlang/src/branch/main/grammar.ebnf
|
||||
#![feature(decl_macro)]
|
||||
|
||||
use self::error::{
|
||||
use cl_structures::span::*;
|
||||
use cl_token::*;
|
||||
|
||||
use crate::error::{
|
||||
Error,
|
||||
ErrorKind::{self, *},
|
||||
PResult, Parsing,
|
||||
};
|
||||
use crate::lexer::{error::Error as LexError, Lexer};
|
||||
use cl_ast::*;
|
||||
use cl_structures::span::*;
|
||||
use cl_token::*;
|
||||
use conlang::lexer::Lexer;
|
||||
|
||||
pub mod error {
|
||||
use std::fmt::Display;
|
||||
|
||||
use super::*;
|
||||
|
||||
use conlang::lexer::error::{Error as LexError, Reason};
|
||||
use std::fmt::Display;
|
||||
pub type PResult<T> = Result<T, Error>;
|
||||
|
||||
/// Contains information about [Parser] errors
|
||||
@ -49,7 +52,6 @@ pub mod error {
|
||||
}
|
||||
impl From<LexError> for ErrorKind {
|
||||
fn from(value: LexError) -> Self {
|
||||
use crate::lexer::error::Reason;
|
||||
match value.reason() {
|
||||
Reason::EndOfFile => Self::EndOfInput,
|
||||
_ => Self::Lexical(value),
|
||||
@ -130,9 +132,9 @@ pub mod error {
|
||||
let Self { reason, while_parsing, loc } = self;
|
||||
match reason {
|
||||
// TODO entries are debug-printed
|
||||
Todo => write!(f, "{loc} {reason} {while_parsing:?}"),
|
||||
ErrorKind::Todo => write!(f, "{loc} {reason} {while_parsing:?}"),
|
||||
// lexical errors print their own higher-resolution loc info
|
||||
Lexical(e) => write!(f, "{e} (while parsing {while_parsing})"),
|
||||
ErrorKind::Lexical(e) => write!(f, "{e} (while parsing {while_parsing})"),
|
||||
_ => write!(f, "{loc} {reason} while parsing {while_parsing}"),
|
||||
}
|
||||
}
|
||||
@ -226,6 +228,8 @@ pub mod error {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Parses a sequence of [Tokens](Token) into an [AST](cl_ast)
|
||||
pub struct Parser<'t> {
|
||||
/// Lazy tokenizer
|
||||
lexer: Lexer<'t>,
|
@ -12,8 +12,9 @@ publish.workspace = true
|
||||
[dependencies]
|
||||
conlang = { path = "../libconlang" }
|
||||
cl-ast = { path = "../cl-ast" }
|
||||
cl-interpret = { path = "../cl-interpret" }
|
||||
cl-token = { path = "../cl-token" }
|
||||
cl-parser = { path = "../cl-parser" }
|
||||
cl-interpret = { path = "../cl-interpret" }
|
||||
crossterm = "0.27.0"
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -1,8 +1,9 @@
|
||||
//! Collects identifiers into a list
|
||||
|
||||
use cl_parser::Parser;
|
||||
use cl_repl::repline::Repline;
|
||||
use cl_structures::span::Loc;
|
||||
use conlang::{lexer::Lexer, parser::Parser};
|
||||
use conlang::lexer::Lexer;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
error::Error,
|
||||
|
@ -74,10 +74,10 @@ pub mod program {
|
||||
};
|
||||
|
||||
use cl_ast::{self as ast, ast_impl::format::Pretty};
|
||||
use cl_parser::{error::PResult, Parser};
|
||||
use conlang::{
|
||||
// pretty_printer::{PrettyPrintable, Printer},
|
||||
lexer::Lexer,
|
||||
parser::{error::PResult, Parser},
|
||||
resolver::{error::TyResult, Resolver},
|
||||
};
|
||||
use std::{fmt::Display, io::Write};
|
||||
@ -228,7 +228,7 @@ pub mod cli {
|
||||
match (repl, path) {
|
||||
(true, Some(path)) => {
|
||||
let prog = std::fs::read_to_string(path).unwrap();
|
||||
let code = conlang::parser::Parser::new(conlang::lexer::Lexer::new(&prog))
|
||||
let code = cl_parser::Parser::new(conlang::lexer::Lexer::new(&prog))
|
||||
.file()
|
||||
.unwrap();
|
||||
let mut env = cl_interpret::env::Environment::new();
|
||||
|
@ -14,5 +14,5 @@ repository.workspace = true
|
||||
[dependencies]
|
||||
unicode-xid = "0.2.4"
|
||||
cl-ast = { path = "../cl-ast" }
|
||||
cl-structures = { path = "../cl-structures" }
|
||||
cl-token = { path = "../cl-token" }
|
||||
cl-structures = { path = "../cl-structures" }
|
||||
|
@ -4,8 +4,6 @@
|
||||
|
||||
pub mod lexer;
|
||||
|
||||
pub mod parser;
|
||||
|
||||
pub mod resolver;
|
||||
|
||||
#[cfg(test)]
|
||||
|
Loading…
Reference in New Issue
Block a user