Skip to content

Commit

Permalink
Update dependencies and uplift Ids (dep & struct)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amejonah1200 committed Feb 6, 2024
1 parent 345d6c3 commit 948f5a3
Show file tree
Hide file tree
Showing 18 changed files with 389 additions and 1,576 deletions.
1,258 changes: 43 additions & 1,215 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
chumsky = { git = "https://github.com/zesterer/chumsky.git", rev = "56762fe5c965880066a068038a18b5ac07afd75c", features = [
"label",
] }
chumsky = { version = "1.0.0-alpha.6", features = [ "label" ] }
walkdir = { git = "https://github.com/APLanguage/walkdir.git" }
# chumsky = { version = "1.0.0-alpha.4", features = ["label"] }
num = "0.4.1"
num-traits = "0.2"
# num-derive = "0.3"
regex = "1.9"
regex = "1.10"
logos = "0.13"
paste = "1.0"
# clap = "4.1"
Expand All @@ -28,12 +26,12 @@ indextree = "4.6"
slotmap = "1.0.6"
ariadne = { git = "https://github.com/APLanguage/ariadne.git", rev = "bdc392368fb45e71aff0feca58d0bf66f56698ae" }
itertools = "0.11"
toml = "0.7.6"
toml = "0.8.8"
serde = { version = "1.0", features = ["derive"] }
same-file = "1.0.6"
strum = "0.25"
strum_macros = "0.25"
bigdecimal = { git = "https://github.com/APLanguage/bigdecimal-rs.git", rev = "864927641721a39299e460deebdc85d01ea0930b" }

[target.'cfg(windows)'.dependencies.winapi-util]
version = "0.1.5"
version = "0.1.6"
22 changes: 8 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![allow(incomplete_features)]
#![allow(unused_macros)]
#![feature(trait_alias)]
#![feature(return_position_impl_trait_in_trait)]
#![feature(iter_collect_into)]
// #![feature(iter_map_windows)]

Expand All @@ -15,9 +14,7 @@ use crate::{
Spanned,
},
project::{
display_integer_type,
readers::{read_workspace, ReadWorkspaceError, ReadWorkspaceResult},
Workspace, TypeRegistry,
display_integer_type, readers::{read_workspace, ReadWorkspaceError, ReadWorkspaceResult}, ProjectLink, TypeRegistry, Workspace
},
resolution::{
name_resolution::resolve_workspace_outlines,
Expand Down Expand Up @@ -85,8 +82,7 @@ fn main() {
{
let mut is_errors = false;
println!("Resolving...");
let dependency_id = workspace.project_dep_id();
for (file_id, errs) in resolve_workspace_outlines(&mut rodeo, &mut workspace, dependency_id)
for (file_id, errs) in resolve_workspace_outlines(&mut rodeo, &mut workspace, ProjectLink::Project)
{
is_errors = true;
let file = workspace.project().files.file_by_id(file_id).unwrap();
Expand All @@ -113,7 +109,7 @@ fn main() {
// }
return;
}
for (file_id, errs) in resolve_and_typecheck_functions(&rodeo, &mut workspace, dependency_id) {
for (file_id, errs) in resolve_and_typecheck_functions(&rodeo, &mut workspace, ProjectLink::Project) {
is_errors = true;
let file = workspace.project().files.file_by_id(file_id).unwrap();
// Generate & choose some colours for each of our elements
Expand Down Expand Up @@ -188,22 +184,20 @@ fn main() {
)
},
FieldNotFound(
Spanned((dep, struct_id), base_span),
Spanned(struct_link, base_span),
Spanned(name, name_span),
) => {
let dep = workspace.dependencies.get_dependency(dep).unwrap();
let project_name = rodeo.resolve(&dep.name);
let struct_path = &dep
.project
.struct_path(struct_id)
let project_name = rodeo.resolve(&workspace.get_dependency_name(struct_link.project_link));
let struct_path = workspace.get_project(struct_link.project_link)
.struct_path(struct_link.struct_id)
.map(|s| rodeo.resolve(&s))
.join("::");
let struct_color = colors.next();
rep.with_message(format!(
"No field `{}` found for struct ({}) {}",
rodeo.resolve(&name).fg(ariadne::Color::Red),
project_name.fg(struct_color),
struct_path.fg(struct_color),
(&struct_path).fg(struct_color),
))
.with_label({
ariadne::Label::new((&input_name as &str, base_span.into_range()))
Expand Down
26 changes: 9 additions & 17 deletions src/parsing/parsers/declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::parsing::{
},
parsers::{expressions::expression_parser, TokenInput, TokenParser},
tokenizer::{ident, keyword, Identifier, Token},
Spanned,
};
use chumsky::{
primitive::{choice, group, just},
Expand All @@ -21,8 +20,8 @@ fn field_parser<'a, I: TokenInput<'a>>() -> impl TokenParser<'a, I, Field> {
keyword(Identifier::Var).to(true),
keyword(Identifier::Val).to(false),
))
.map_with_span(Spanned),
ident().spur().map_with_span(Spanned),
.spanned(),
ident().spur().spanned(),
just(Token::Colon).paddedln(),
type_parser()
.spanned()
Expand All @@ -44,7 +43,7 @@ pub fn struct_parser<'a, I: TokenInput<'a>>() -> impl TokenParser<'a, I, Struct>
.ignore_then(
ident()
.spur()
.map_with_span(Spanned)
.spanned()
.paddedln()
.labelled("data-identifier")
.boxed(),
Expand All @@ -70,7 +69,7 @@ pub fn struct_parser<'a, I: TokenInput<'a>>() -> impl TokenParser<'a, I, Struct>
pub fn type_parser<'a, I: TokenInput<'a>>() -> impl TokenParser<'a, I, ParsedType> + Clone {
recursive(|p| {
choice((
ident().spur().map_with_span(Spanned).map(ParsedType::Data),
ident().spur().spanned().map(ParsedType::Data),
p.delimited_by(just(Token::BracketOpen), just(Token::BracketClosed))
.map(|t| ParsedType::Array(Box::new(t))),
))
Expand All @@ -84,12 +83,12 @@ pub fn variable_parser<'a, I: TokenInput<'a>>() -> impl TokenParser<'a, I, Varia
keyword(Identifier::Var).to(true),
keyword(Identifier::Val).to(false),
))
.map_with_span(Spanned)
.spanned()
.labelled("var-modifier")
.boxed(),
ident()
.spur()
.map_with_span(Spanned)
.spanned()
.paddedln()
.labelled("var-name")
.boxed(),
Expand Down Expand Up @@ -122,13 +121,10 @@ fn parameter_parser<'a, I: TokenInput<'a>>() -> impl TokenParser<'a, I, Paramete
keyword(Identifier::Var).to(true),
keyword(Identifier::Val).to(false),
))
.map_with_span(Spanned)
.spanned()
.or_not()
.labelled("fn-param-reassignable"),
ident()
.spur()
.map_with_span(Spanned)
.labelled("fn-param-name"),
ident().spur().spanned().labelled("fn-param-name"),
just(Token::Colon).paddedln().ignored(),
type_parser()
.spanned()
Expand All @@ -146,11 +142,7 @@ fn parameter_parser<'a, I: TokenInput<'a>>() -> impl TokenParser<'a, I, Paramete
pub fn function_parser<'a, I: TokenInput<'a>>() -> impl TokenParser<'a, I, Function> {
keyword(Identifier::Fn)
.ignore_then(group((
ident()
.spur()
.map_with_span(Spanned)
.paddedln()
.labelled("fn-name"),
ident().spur().spanned().paddedln().labelled("fn-name"),
parameter_parser()
.paddedln()
.separated_by(just(Token::Comma))
Expand Down
25 changes: 11 additions & 14 deletions src/parsing/parsers/expressions.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use chumsky::{
prelude::Rich,
primitive::{choice, group, just},
recursive::recursive,
select,
span::SimpleSpan,
IterParser, Parser, prelude::Rich,
Parser,
};
use itertools::Itertools;

use crate::parsing::{
ast::expressions::{CallKind, Expression},
Expand All @@ -32,7 +32,7 @@ pub fn call<'a, EP, I: TokenInput<'a>>(
where EP: TokenParser<'a, I, Expression> + Clone + 'a {
ident()
.spur()
.map_with_span(Spanned)
.spanned()
.then(
expr_parser
.spanned()
Expand Down Expand Up @@ -82,7 +82,7 @@ where EP: TokenParser<'a, I, Expression> + Clone + 'a {
LessLessEqual
)
.boxed()
.map_with_span(Spanned)
.spanned()
.labelled("assignement_operator")
.paddedln(),
expr_parser
Expand Down Expand Up @@ -131,7 +131,7 @@ pub fn unary_parser<'a, EP, I: TokenInput<'a>>(
) -> impl TokenParser<'a, I, Expression> + Clone
where EP: TokenParser<'a, I, Expression> + Clone + 'a {
ops_parser!(Minus, Bang, Tilde)
.map_with_span(Spanned)
.spanned()
.repeated()
.at_least(1)
.collect_boxed_slice()
Expand Down Expand Up @@ -218,7 +218,7 @@ pub fn expression_parser<'a, I: TokenInput<'a>>() -> impl TokenParser<'a, I, Exp

use paste::paste;

use super::{string::string_parser, TokenParserExt};
use super::{string::string_parser, TokenParserExt, just_span};
macro_rules! binary_parser {
($what:ident, $name: ident, $next_name: ident, $ops:expr) => {
paste! {
Expand All @@ -244,14 +244,11 @@ macro_rules! binary_parser {
#[rustfmt::skip] binary_parser!(binary, factor, bitops, ops_parser!(Asterisk, SlashSlash, Slash, Percent));
#[rustfmt::skip] binary_parser!(binary, bitops, unary, ops_parser!(Bar, Ampersand, LessLess)
.or(
just(Token::Greater).span().repeated().at_least(2).at_most(3).collect_boxed_slice()
.try_map(|slice, _span|
if slice.iter().tuple_windows().all(|(a, b)| a.end == b.start) {
Ok(if slice.len() == 2 { Operation::ShiftRight } else { Operation::ShiftRightUnsigned })
} else {
Err(Rich::custom(_span, "there is a whitespace between the two/three >"))
}
)
choice((
group((just_span(Token::Greater), just_span(Token::Greater), just_span(Token::Greater))).map(|(a, b, c)| (a.end == b.start && b.end == c.start).then_some(Operation::ShiftRightUnsigned)),
group((just_span(Token::Greater), just_span(Token::Greater))).map(|(a, b)| (a.end == b.start).then_some(Operation::ShiftRight)),
))
.try_map(|op, span| op.ok_or_else(|| Rich::custom(span, "there is a whitespace between the two/three >")))
)
);

Expand Down
7 changes: 4 additions & 3 deletions src/parsing/parsers/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use chumsky::{
prelude::Rich,
primitive::{choice, just},
recursive::recursive,
span::SimpleSpan,
IterParser, Parser,
};
use either::Either;
Expand Down Expand Up @@ -49,8 +48,10 @@ pub fn use_parser<'a, I: TokenInput<'a>>() -> impl TokenParser<'a, I, UseDeclara
.separated_by(just(Token::Minus))
.at_least(1)
.ignored()
.src().boxed()
.validate(|s, span: SimpleSpan, emitter| {
.src()
.boxed()
.validate(|s: &'a str, extra, emitter| {
let span = extra.span();
if s.chars().any(|c: char| c.is_whitespace()) {
emitter.emit(Rich::custom(span, "No whitespaces are allowed. Should match [a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z0-9]+)*"))
}
Expand Down
25 changes: 21 additions & 4 deletions src/parsing/parsers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::{fmt::Debug, ops::Range};

use chumsky::{
extra::Full, input::ValueInput, prelude::Rich, span::SimpleSpan, IterParser, Parser,
container::OrderedSeq, extra::Full, input::ValueInput, prelude::Rich, primitive::just,
span::SimpleSpan, IterParser, Parser,
};
use lasso::{Rodeo, Spur};

Expand Down Expand Up @@ -87,8 +88,17 @@ where
self.padded_by(newline().repeated())
}

#[inline]
fn map_with_state<R, F: (Fn(O, SimpleSpan, &mut ParserState<'a>) -> R) + Clone>(
self,
f: F,
) -> impl TokenParser<'a, I, R> {
self.map_with(move |t, e| f(t, e.span(), e.state()))
}

#[inline(always)]
fn span(self) -> impl TokenParser<'a, I, SimpleSpan> + Clone {
self.map_with_span(|_, s| s)
self.to_span()
}

fn spur(self) -> impl TokenParser<'a, I, Spur> + Clone {
Expand All @@ -102,10 +112,10 @@ where
}

fn spanned(self) -> impl TokenParser<'a, I, Spanned<O>> + Clone {
self.map_with_span(Spanned)
self.map_with(|t, e| Spanned(t, e.span()))
}

fn map_into<R: From<O>>(self) ->impl TokenParser<'a, I, R> + Clone {
fn map_into<R: From<O>>(self) -> impl TokenParser<'a, I, R> + Clone {
self.map(Into::into)
}
}
Expand All @@ -117,3 +127,10 @@ where
O: Debug,
{
}

pub fn just_span<'a, T, I>(seq: T) -> impl TokenParser<'a, I, SimpleSpan>
where
I: TokenInput<'a>,
T: OrderedSeq<'a, I::Token> + Clone, {
just(seq).to_span()
}
2 changes: 1 addition & 1 deletion src/parsing/parsers/statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn return_parser<'a, I: TokenInput<'a>>() -> impl TokenParser<'a, I, ControlFlow
keyword(Identifier::Return)
.ignore_then(
expression_parser()
.map_with_span(Spanned)
.spanned()
.paddedln()
.or_not()
.labelled("return-expr")
Expand Down
2 changes: 1 addition & 1 deletion src/parsing/parsers/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn string_parser<'a>(
any()
.and_is(end.not())
.repeated()
.slice()
.to_slice()
.map(|s: &'a str| {
UnlassoedStringLiteral::Raw(s.to_owned().replace("\r\n", "\n"))
})
Expand Down
2 changes: 1 addition & 1 deletion src/parsing/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn string_parser_callback(lex: &mut Lexer<Token>) -> Option<StringLiteralType> {
let start = lex.span().start;
let len = lex.span().end - lex.span().start;
let (literal, span) = string_literal_outline_parser()
.map_with_span(|t, s| (t, s))
.map_with(|t, e| (t, e.span()))
.lazy()
.parse(lex.source().slice(start..end).unwrap())
.into_output()?;
Expand Down
Loading

0 comments on commit 948f5a3

Please sign in to comment.