Skip to content

Commit

Permalink
Fix issues and re-do project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Amejonah1200 committed Oct 8, 2024
1 parent 30c8ec7 commit fc8186f
Show file tree
Hide file tree
Showing 26 changed files with 231 additions and 669 deletions.
413 changes: 50 additions & 363 deletions Cargo.lock

Large diffs are not rendered by default.

23 changes: 18 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
[package]
name = "aplang"
[workspace.package]
version = "0.0.1"
authors = ["Amejonah1200 <amejonah@gmail.com>"]
edition = "2021"

[workspace]
resolver = "2"
default-members = ["crates/cli"]
members = [
"crates/cli",
"crates/parser",
"crates/source",
"crates/typing",
]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
[workspace.dependencies]
aplang-parser = { path = "crates/parser" }
aplang-source = { path = "crates/source" }
aplang-typing = { path = "crates/typing" }

chumsky = { version = "1.0.0-alpha.7", features = [ "label" ] }
walkdir = { git = "https://github.com/APLanguage/walkdir.git" }
# chumsky = { version = "1.0.0-alpha.4", features = ["label"] }
Expand Down Expand Up @@ -36,8 +49,8 @@ tracing = "0.1"
tracing-subscriber = {version = "0.3", features = ["default", "json"]}


[target.'cfg(windows)'.dependencies.winapi-util]
version = "0.1.9"
#[target.'cfg(windows)'.dependencies]
#winapi-util = { version = "0.1.9" }

[profile.release]
panic = "unwind"
Expand Down
16 changes: 16 additions & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "cli"
version.workspace = true
edition.workspace = true

[[bin]]
name = "cli"
path = "src/main.rs"

[dependencies]
aplang-parser.workspace = true
aplang-source.workspace = true
aplang-typing.workspace = true
ariadne.workspace = true
chumsky.workspace = true
itertools.workspace = true
48 changes: 5 additions & 43 deletions src/main.rs → crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,9 @@
#![feature(iter_collect_into)]
// #![feature(iter_map_windows)]

use crate::parsing::parsers::{expressions::expression_parser, file::File};

use chumsky::{error::RichReason, prelude::Rich, primitive::end, ParseResult, Parser};
use itertools::Itertools;
use lasso::Rodeo;
use parsing::{
ast::{declarations::FlatUseDeclaration, expressions::Expression},
tokenizer::tokenize,
};
use source::VirtualFile;

use crate::{
parsing::{
ast::declarations::UseDeclaration,
parsers::{file::file_parser, ParserState},
tokenizer::Token,
},
source::SourceFile,
};

pub mod parsing;
pub mod source;
pub mod typing;
use aplang_parser::{ast::declarations::{FlatUseDeclaration, UseDeclaration}, tokenizer::Token};
use aplang_source::{SourceFile, VirtualFile};
use chumsky::{error::{Rich, RichReason}, ParseResult};

#[derive(Debug)]
enum PathPartType {
Expand Down Expand Up @@ -93,27 +73,9 @@ fn main() {
// parse_and_print!(r###"r"Hello " + ", age " + str(person.age)"""###, test_parser)
}

fn parse_file<'a, S: SourceFile>(
rodeo: &'a mut Rodeo,
input: &'a S,
) -> ParseResult<File, Rich<'a, Token>> {
let mut state = ParserState::new(rodeo, input);
return file_parser()
.then_ignore(end())
.parse_with_state(tokenize(input.whole_file()), &mut state);
}

fn parse_expression<'a, S: SourceFile>(
rodeo: &'a mut Rodeo,
input: &'a S,
) -> ParseResult<Expression, Rich<'a, Token>> {
let mut state = ParserState::new(rodeo, input);
return expression_parser()
.then_ignore(end())
.parse_with_state(tokenize(input.whole_file()), &mut state);
}

fn print_uses(uses: &[UseDeclaration], file: &VirtualFile) {
use itertools::Itertools;

uses.iter().flat_map(UseDeclaration::flatten_tree).for_each(
|FlatUseDeclaration {
path,
Expand Down
22 changes: 22 additions & 0 deletions crates/parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "aplang-parser"
version.workspace = true
edition.workspace = true

[lib]
path = "src/lib.rs"

[dependencies]
chumsky.workspace = true
paste.workspace = true
logos.workspace = true
lasso.workspace = true
strum_macros.workspace = true
traversal.workspace = true
itertools.workspace = true
bigdecimal.workspace = true
either.workspace = true
num.workspace = true
num-traits.workspace = true
regex.workspace = true
aplang-source.workspace = true
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::iter::empty;

use crate::parsing::{
use crate::{
ast::{expressions::Expression, statements::Statement},
Spanned,
Infoed,
};

use super::ParsedType;
Expand All @@ -13,8 +12,6 @@ use lasso::Spur;
use strum_macros::IntoStaticStr;
use traversal::DftLongestPaths;

type NameTypeTuple = (Spanned<Spur>, Infoed<ParsedType>);

#[derive(Debug, Clone, PartialEq)]
pub enum UsePathEnd {
Split(Box<[UsePath]>),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use lasso::Spur;
use strum_macros::IntoStaticStr;

use crate::parsing::{
use crate::{
parsers::number::NumberLiteralResult,
tokenizer::{Operation, OperationGroup},
Spanned,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use strum_macros::IntoStaticStr;

use crate::parsing::{
use crate::{
ast::expressions::Expression,
Spanned,
};
Expand Down
2 changes: 2 additions & 0 deletions src/parsing/mod.rs → crates/parser/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(trait_alias)]

use chumsky::span::SimpleSpan;

pub mod ast;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::parsing::{
use crate::{
ast::{
declarations::{Field, Function, Parameter, Variable},
declarations::{Function, Parameter, Variable},
ParsedType,
},
parsers::{expressions::expression_parser, TokenInput, TokenParser},
Expand All @@ -14,30 +14,6 @@ use chumsky::{

use super::{statements::statement_parser, CollectBoxedSliceExt, TokenParserExt};

fn field_parser<'a, I: TokenInput<'a>>() -> impl TokenParser<'a, I, Field> {
group((
choice((
keyword(Identifier::Var).to(true),
keyword(Identifier::Val).to(false),
))
.spanned(),
ident().spur().spanned(),
just(Token::Colon).paddedln(),
type_parser()
.spanned()
.paddedln()
.labelled("data-field-type")
.boxed(),
))
.labelled("data-field")
.map(|(reassignable, name, _, ty)| Field {
reassignable,
name,
ty,
})
.boxed()
}

pub fn type_parser<'a, I: TokenInput<'a>>() -> impl TokenParser<'a, I, ParsedType> {
recursive(|p| {
choice((
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use chumsky::{
Parser,
};

use crate::parsing::{
use super::super::{
ast::expressions::{CallKind, Expression},
parsers::number::parse_complex_number,
parsers::{CollectBoxedSliceExt, ParserState, TokenInput, TokenParser},
Expand All @@ -26,9 +26,7 @@ macro_rules! ops_parser {
};
}

pub fn call<'a, EP, I: TokenInput<'a>>(
expr_parser: EP,
) -> impl TokenParser<'a, I, CallKind>
pub fn call<'a, EP, I: TokenInput<'a>>(expr_parser: EP) -> impl TokenParser<'a, I, CallKind>
where EP: TokenParser<'a, I, Expression> + Clone + 'a {
ident()
.spur()
Expand Down Expand Up @@ -218,7 +216,7 @@ pub fn expression_parser<'a, I: TokenInput<'a>>() -> impl TokenParser<'a, I, Exp

use paste::paste;

use super::{string::string_parser, TokenParserExt, just_span};
use super::{just_span, string::string_parser, TokenParserExt};
macro_rules! binary_parser {
($what:ident, $name: ident, $next_name: ident, $ops:expr) => {
paste! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use chumsky::{
use either::Either;
use itertools::Itertools;

use crate::parsing::{
use crate::{
ast::declarations::{Declaration, UseDeclaration, UsePath, UsePathEnd},
parsers::{
declarations::{function_parser, variable_parser},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use chumsky::{
};
use lasso::{Rodeo, Spur};

use crate::source::SourceFile;
use aplang_source::SourceFile;

use super::{
tokenizer::{newline, Token},
Expand Down
Loading

0 comments on commit fc8186f

Please sign in to comment.