rust: move syntax/AST stuff into separate crate

This commit is contained in:
Alain Zscheile 2023-11-02 01:10:09 +01:00
parent 32b9fd4039
commit a3e1609654
14 changed files with 61 additions and 20 deletions

12
rust/Cargo.lock generated
View file

@ -499,6 +499,16 @@ dependencies = [
"miette",
"nohash-hasher",
"thiserror",
"yn-functor",
"yz-string-utils",
]
[[package]]
name = "yanais-syntax"
version = "0.1.0"
dependencies = [
"miette",
"thiserror",
"unicode-ident",
"unicode-normalization",
"yn-functor",
@ -528,6 +538,7 @@ dependencies = [
"miette",
"thiserror",
"yanais-core",
"yanais-syntax",
]
[[package]]
@ -549,6 +560,7 @@ dependencies = [
"unicode-ident",
"unicode-normalization",
"yanais-core",
"yanais-syntax",
"yn-functor",
"yz-string-utils",
]

View file

@ -1,14 +1,16 @@
# SPDX-FileCopyrightText: 2023 Alain Zscheile <fogti+devel@ytrizja.de>
#
# SPDX-License-Identifier: CC0-1.0
[package]
name = "yanais-core"
version = "0.1.0"
edition = "2021"
license = "Apache-2,0"
license = "Apache-2.0"
[dependencies]
miette = "5.10"
nohash-hasher = "0.2"
thiserror = "1.0"
unicode-ident = "1.0"
unicode-normalization = "0.1"
yn-functor.path = "../yn-functor"
yz-string-utils = "0.3.1"

View file

@ -2,8 +2,6 @@
pub mod egraph;
pub mod literal;
pub mod parser;
pub mod record;
#[macro_export]
macro_rules! none_up {

View file

@ -0,0 +1,13 @@
[package]
name = "yanais-syntax"
version = "0.1.0"
edition = "2021"
license = "Apache-2.0"
[dependencies]
miette = "5.10"
thiserror = "1.0"
unicode-ident = "1.0"
unicode-normalization = "0.1"
yn-functor.path = "../yn-functor"
yz-string-utils = "0.3.1"

View file

@ -1,9 +1,25 @@
/*
* SPDX-FileCopyrightText: 2023 Alain Zscheile <fogti+devel@ytrizja.de>
*
* SPDX-License-Identifier: Apache-2.0
*/
use core::{cmp, fmt, result::Result as CoreResult};
use miette::{Diagnostic, SourceSpan};
use std::sync::Arc;
pub use yz_string_utils::StrLexerBase;
pub mod lex;
pub mod record;
#[macro_export]
macro_rules! none_up {
($x:expr) => {
match $x {
None => return Ok(None),
Some(x) => x,
}
};
}
/// A SourceSpan which is always equal to all other SourceSpans
/// (to be used to ignore span differences in expression comparisons)

View file

@ -7,11 +7,10 @@
use core::cmp;
use std::sync::Arc;
use crate::none_up;
use crate::parser::{
use crate::{
lex::{Token, TokenKind as Tok},
Env as ParseEnv, Error as Perr, ErrorCtx as PeCtx, ErrorKind as Pek, EvEqSourceSpan, Keywords,
MaybeParse, Parse, ParseDefaultCtx, Result as Pres,
none_up, Env as ParseEnv, Error as Perr, ErrorCtx as PeCtx, ErrorKind as Pek, EvEqSourceSpan,
Keywords, MaybeParse, Parse, ParseDefaultCtx, Result as Pres,
};
#[derive(Clone, Debug)]

View file

@ -7,3 +7,4 @@ edition = "2021"
miette = "5.10"
thiserror = "1.0"
yanais-core.path = "../yanais-core"
yanais-syntax.path = "../yanais-syntax"

View file

@ -14,8 +14,8 @@ use parser::{
use yanais_core::none_up;
pub mod parser {
use yanais_core::parser::lex as upslex;
pub use yanais_core::parser::{
use yanais_syntax::lex as upslex;
pub use yanais_syntax::{
Error, ErrorCtx, ErrorKind, EvEqSourceSpan, FullError, MaybeParse, Parse, ParseDefaultCtx,
Result,
};
@ -52,7 +52,7 @@ pub mod parser {
pub type TokenKind = upslex::TokenKind<Kw>;
}
pub type Env<'a> = yanais_core::parser::Env<'a, lex::Kw>;
pub type Env<'a> = yanais_syntax::Env<'a, lex::Kw>;
}
use parser::lex::Kw;
@ -63,8 +63,7 @@ mod record;
pub use expr::Expr;
pub use pat::Pattern;
pub use record::Record;
pub use yanais_core::parser::EvEqSourceSpan;
pub use yanais_syntax::{record::Record, EvEqSourceSpan};
#[derive(Clone, Debug)]
pub struct Lambda {

View file

@ -6,7 +6,7 @@
use crate::parser::{lex, Env as ParseEnv, Error, ErrorCtx, MaybeParse, ParseDefaultCtx};
use std::sync::Arc;
use yanais_core::parser::EvEqSourceSpan;
use yanais_syntax::EvEqSourceSpan;
// infallible patterns

View file

@ -7,9 +7,9 @@
use crate::{Expr, TaggedIdent};
use std::collections::BTreeMap;
use std::sync::Arc;
use yanais_core::parser::EvEqSourceSpan;
use yanais_syntax::EvEqSourceSpan;
pub use yanais_core::record::Record;
pub use yanais_syntax::record::Record;
pub type ModSelect = crate::Select<TaggedIdent>;

View file

@ -15,6 +15,7 @@ unicode-ident = "1.0"
unicode-normalization = "0.1"
yn-functor.path = "../yn-functor"
yanais-core.path = "../yanais-core"
yanais-syntax.path = "../yanais-syntax"
yz-string-utils = "0.3.1"
[dev-dependencies]

View file

@ -20,7 +20,7 @@ pub mod typeck;
use miette::SourceSpan;
pub use yanais_core::parser::EvEqSourceSpan;
pub use yanais_syntax::EvEqSourceSpan;
pub trait Subst {
fn incr_refs(&mut self, keep: usize, offset: usize);

View file

@ -134,7 +134,7 @@ impl<'a> Lexer<'a> {
}
}
use yanais_core::parser::lex::{consume_ident, try_consume_ident};
use yanais_syntax::lex::{consume_ident, try_consume_ident};
impl<'a> Iterator for Lexer<'a> {
type Item = Result<Token, Error>;