switch lexer to logos

This commit is contained in:
Jim 2025-10-20 21:41:19 -04:00
parent bff45e9215
commit 02858a9ef7
Signed by: jim
GPG key ID: 3236D2F059A7C0AC
9 changed files with 1100 additions and 190 deletions

69
Cargo.lock generated
View file

@ -35,6 +35,12 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
[[package]]
name = "beef"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1"
[[package]]
name = "bumpalo"
version = "3.19.0"
@ -211,6 +217,12 @@ version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "foldhash"
version = "0.1.5"
@ -259,6 +271,7 @@ name = "jang"
version = "0.1.0"
dependencies = [
"chumsky",
"logos",
]
[[package]]
@ -268,6 +281,7 @@ dependencies = [
"chumsky",
"criterion",
"jang",
"logos",
]
[[package]]
@ -280,6 +294,12 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "libc"
version = "0.2.177"
@ -292,6 +312,40 @@ version = "0.4.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432"
[[package]]
name = "logos"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff472f899b4ec2d99161c51f60ff7075eeb3097069a36050d8037a6325eb8154"
dependencies = [
"logos-derive",
]
[[package]]
name = "logos-codegen"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "192a3a2b90b0c05b27a0b2c43eecdb7c415e29243acc3f89cc8247a5b693045c"
dependencies = [
"beef",
"fnv",
"lazy_static",
"proc-macro2",
"quote",
"regex-syntax 0.8.8",
"rustc_version",
"syn",
]
[[package]]
name = "logos-derive"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "605d9697bcd5ef3a42d38efc51541aa3d6a4a25f7ab6d1ed0da5ac632a26b470"
dependencies = [
"logos-codegen",
]
[[package]]
name = "memchr"
version = "2.7.6"
@ -440,6 +494,15 @@ version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58"
[[package]]
name = "rustc_version"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92"
dependencies = [
"semver",
]
[[package]]
name = "rustversion"
version = "1.0.22"
@ -461,6 +524,12 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "semver"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"
[[package]]
name = "serde"
version = "1.0.228"

View file

@ -3,13 +3,18 @@ name = "jang_cli"
version = "0.1.0"
edition = "2024"
[dependencies]
[workspace.dependencies]
logos = "0.15.1"
chumsky = "0.11.1"
[dependencies]
jang = { path = "crates/jang" }
logos = { workspace = true }
chumsky = { workspace = true }
[dev-dependencies]
criterion = "0.7.0"
[[bench]]
name = "parser"
name = "jang"
harness = false

View file

@ -1 +1,35 @@
this is a programming language maybe
perf log:
- switching to logos for lexing
```
Fibonacci/Parse/programs/medium.jang
time: [13.715 ms 13.748 ms 13.782 ms]
change: [76.299% 76.233% 76.166%] (p = 0.00 < 0.05)
Performance has improved.
Found 5 outliers among 100 measurements (5.00%)
5 (5.00%) high mild
Fibonacci/Interpret/programs/medium.jang
time: [15.646 ms 15.668 ms 15.693 ms]
change: [73.006% 72.935% 72.867%] (p = 0.00 < 0.05)
Performance has improved.
Found 4 outliers among 100 measurements (4.00%)
4 (4.00%) high mild
Fibonacci/Parse/programs/test.jang
time: [5.4356 µs 5.4369 µs 5.4383 µs]
change: [82.092% 82.052% 82.004%] (p = 0.00 < 0.05)
Performance has improved.
Found 8 outliers among 100 measurements (8.00%)
2 (2.00%) high mild
6 (6.00%) high severe
Fibonacci/Interpret/programs/test.jang
time: [6.5476 µs 6.5506 µs 6.5541 µs]
change: [79.543% 79.499% 79.471%] (p = 0.00 < 0.05)
Performance has improved.
Found 2 outliers among 100 measurements (2.00%)
1 (1.00%) high mild
1 (1.00%) high severe
```

View file

@ -1,4 +1,5 @@
use chumsky::Parser;
use std::collections::HashMap;
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
use jang::*;
@ -7,16 +8,16 @@ fn bench_parsers(c: &mut Criterion) {
for input_path in ["programs/medium.jang", "programs/test.jang"].iter() {
let src = std::fs::read_to_string(input_path).unwrap();
group.bench_with_input(BenchmarkId::new("Combo", input_path), &src, |b, src| {
b.iter(|| create_combo_parser().parse(src))
group.bench_with_input(BenchmarkId::new("Parse", input_path), &src, |b, src| {
b.iter(|| parse::<false>(src))
});
group.bench_with_input(BenchmarkId::new("Separate", input_path), &src, |b, src| {
group.bench_with_input(BenchmarkId::new("Interpret", input_path), &src, |b, src| {
b.iter(|| {
let lex_result = create_lexer().parse(src);
let Ok(lexed) = lex_result.into_result() else {
let Ok(ast) = parse::<false>(src) else {
return;
};
create_parser().parse(&lexed);
let mut vars = HashMap::new();
_ = eval(&ast, &mut vars);
})
});
}

View file

@ -4,4 +4,5 @@ version = "0.1.0"
edition = "2024"
[dependencies]
chumsky = "0.11.1"
logos = { workspace = true }
chumsky = { workspace = true }

View file

@ -1,4 +1,8 @@
use chumsky::prelude::*;
use chumsky::{
input::{Stream, ValueInput},
prelude::*,
};
use logos::{Lexer, Logos};
use std::{collections::HashMap, rc::Rc};
#[derive(Clone)]
@ -100,49 +104,70 @@ pub fn eval<'src>(
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Logos, Debug, Clone, Copy, PartialEq, Eq)]
#[logos(skip r"[ \t\n\f\r]+")] // Ignore this regex pattern between tokens
pub enum Token<'src> {
Error,
#[token("let")]
KWLet,
#[token("fn")]
KWFn,
#[token("+")]
Plus,
#[token("-")]
Minus,
#[token("/")]
FSlash,
#[token("*")]
Asterisk,
#[token("(")]
LParen,
#[token(")")]
RParen,
#[token(";")]
Semicolon,
#[token(",")]
Comma,
#[token("=")]
Equals,
#[regex("[0-9]", |lex| lex.slice().parse::<u64>().unwrap())]
Number(u64),
// todo: string internment
#[regex("[_a-zA-Z][_a-zA-Z0-9]*", |lex| lex.slice())]
Ident(&'src str),
}
// todo - either hand write this or move it to `logos`. The perf is HORRIBLE (4.6 MB/s!!!!!! WOW!!!!)
// probably would want a different parsing lib too with how slow that is
pub fn create_lexer<'src>()
-> impl Parser<'src, &'src str, Vec<Token<'src>>, extra::Err<Rich<'src, char>>> {
choice((
text::ascii::keyword("let").padded().to(Token::KWLet),
text::ascii::keyword("fn").padded().to(Token::KWFn),
just('+').to(Token::Plus),
just('-').to(Token::Minus),
just('/').to(Token::FSlash),
just('*').to(Token::Asterisk),
just('(').to(Token::LParen),
just(')').to(Token::RParen),
just(';').to(Token::Semicolon),
just(',').to(Token::Comma),
just('=').to(Token::Equals),
text::int(10).map(|s: &str| Token::Number(s.parse().unwrap())),
text::ident().map(Token::Ident),
))
.padded()
.repeated()
.collect::<Vec<_>>()
type ParseErrorContent<'src> = Rich<'src, Token<'src>>;
type ParseError<'src> = extra::Err<ParseErrorContent<'src>>;
pub fn parse<'src, const LOG: bool>(
input: &'src str,
) -> Result<Expr<'src>, Vec<ParseErrorContent<'src>>> {
let token_iter = Token::lexer(input)
.spanned()
// Convert logos errors into tokens. We want parsing to be recoverable and not fail at the lexing stage, so
// we have a dedicated `Token::Error` variant that represents a token error that was previously encountered
.map(|(tok, span)| match tok {
// Turn the `Range<usize>` spans logos gives us into chumsky's `SimpleSpan` via `Into`, because it's easier
// to work with
Ok(tok) => (tok, span.into()),
Err(()) => (Token::Error, span.into()),
});
// Turn the token iterator into a stream that chumsky can use for things like backtracking
// https://github.com/zesterer/chumsky/blob/main/examples/logos.rs
let token_stream = Stream::from_iter(token_iter)
// Tell chumsky to split the (Token, SimpleSpan) stream into its parts so that it can handle the spans for us
// This involves giving chumsky an 'end of input' span: we just use a zero-width span at the end of the string
.map((0..input.len()).into(), |(t, s): (_, _)| {
if LOG {
println!("tok: {:?}", (t, s));
}
(t, s)
});
create_parser().parse(token_stream).into_result()
}
#[derive(Debug, Clone)]
#[derive(Debug)]
pub enum Expr<'src> {
Num(f64),
Var(&'src str),
@ -167,100 +192,14 @@ pub enum Expr<'src> {
},
}
//does both lex + parsing
pub fn create_combo_parser<'src>() -> impl Parser<'src, &'src str, Expr<'src>> {
let ident = text::ascii::ident().padded();
let expr = recursive(|expr| {
let int = text::int(10)
.map(|s: &str| Expr::Num(s.parse().unwrap()))
.padded();
let call = ident
.then(
expr.clone()
.separated_by(just(','))
.allow_trailing()
.collect::<Vec<_>>()
.delimited_by(just('('), just(')')),
)
.map(|(f, args)| Expr::Call(f, args));
let atom = int
.or(expr.delimited_by(just('('), just(')')))
.or(call)
.or(ident.map(Expr::Var))
.padded();
let op = |c| just(c).padded();
let unary = op('-')
.repeated()
.foldr(atom, |_op, rhs| Expr::Neg(Box::new(rhs)));
let product = unary.clone().foldl(
choice((
op('*').to(Expr::Mul as fn(_, _) -> _),
op('/').to(Expr::Div as fn(_, _) -> _),
))
.then(unary)
.repeated(),
|lhs, (op, rhs)| op(Box::new(lhs), Box::new(rhs)),
);
let sum = product.clone().foldl(
choice((
op('+').to(Expr::Add as fn(_, _) -> _),
op('-').to(Expr::Sub as fn(_, _) -> _),
))
.then(product)
.repeated(),
|lhs, (op, rhs)| op(Box::new(lhs), Box::new(rhs)),
);
sum
});
let decl = recursive(|decl| {
// ex: let x = 5*2
let decl_let = text::ascii::keyword("let")
.ignore_then(ident)
.then_ignore(just('='))
.then(expr.clone())
.then_ignore(just(';'))
.then(decl.clone())
.map(|((name, rhs), then)| Expr::Let {
name,
rhs: Box::new(rhs),
then: Box::new(then),
});
// ex: fn f x y = x + y
let decl_fn = text::ascii::keyword("fn")
.ignore_then(ident)
// collect params
.then(ident.repeated().collect::<Vec<_>>())
.then_ignore(just('='))
.then(expr.clone())
.then_ignore(just(';'))
.then(decl)
.map(|(((name, params), body), then)| Expr::Fn {
name,
args: params,
body: Rc::new(body),
then: Box::new(then),
});
// must parse 'let' keyword first so it doesn't become an identifier
decl_fn.or(decl_let).or(expr).padded()
});
decl
}
pub fn create_parser<'src>()
-> impl Parser<'src, &'src [Token<'src>], Expr<'src>, extra::Err<Rich<'src, Token<'src>>>> {
let ident = any().filter(|tok| matches!(tok, Token::Ident(_)));
pub fn create_parser<'src, I: ValueInput<'src, Token = Token<'src>, Span = SimpleSpan>>()
-> impl Parser<'src, I, Expr<'src>, ParseError<'src>> {
let ident = any()
.filter(|tok| matches!(tok, Token::Ident(_)))
.map(|tok| match tok {
Token::Ident(s) => s,
_ => unreachable!("alredy filtered on string"),
});
let int = any()
.filter(|tok| matches!(tok, Token::Number(_)))
.map(|tok| match tok {
@ -277,21 +216,12 @@ pub fn create_parser<'src>()
.collect::<Vec<_>>()
.delimited_by(just(Token::LParen), just(Token::RParen)),
)
.try_map(|(f, args), span| match f {
Token::Ident(f_name) => Ok(Expr::Call(f_name, args)),
_ => Err(Rich::custom(
span,
format!("expected identifier, found {:?}", f),
)),
});
.map(|(f, args)| Expr::Call(f, args));
let atom = int
.or(expr.delimited_by(just(Token::LParen), just(Token::RParen)))
.or(call)
.or(ident.map(|tok| match tok {
Token::Ident(str) => Expr::Var(str),
_ => unreachable!("alredy filtered on string"),
}));
.or(ident.map(Expr::Var));
let unary = just(Token::Minus)
.repeated()
@ -328,49 +258,26 @@ pub fn create_parser<'src>()
.then(expr.clone())
.then_ignore(just(Token::Semicolon))
.then(decl.clone())
.try_map(|((name, rhs), then), span| match name {
Token::Ident(str) => Ok(Expr::Let {
name: str,
rhs: Box::new(rhs),
then: Box::new(then),
}),
_ => Err(Rich::custom(
span,
format!("expected identifier, found {:?}", name),
)),
.map(|((name, rhs), then)| Expr::Let {
name,
rhs: Box::new(rhs),
then: Box::new(then),
});
// ex: fn f x y = x + y
let decl_fn = just(Token::KWFn)
.ignore_then(ident)
// collect params
.then(
ident
.try_map(|name, span| match name {
Token::Ident(str) => Ok(str),
_ => Err(Rich::custom(
span,
format!("expected identifier, found {:?}", name),
)),
})
.repeated()
.collect::<Vec<_>>(),
)
.then(ident.repeated().collect::<Vec<_>>())
.then_ignore(just(Token::Equals))
.then(expr.clone())
.then_ignore(just(Token::Semicolon))
.then(decl)
.try_map(|(((name, params), body), then), span| match name {
Token::Ident(str) => Ok(Expr::Fn {
name: str,
args: params,
body: Rc::new(body),
then: Box::new(then),
}),
_ => Err(Rich::custom(
span,
format!("expected identifier, found {:?}", name),
)),
.map(|(((name, params), body), then)| Expr::Fn {
name,
args: params,
body: Rc::new(body),
then: Box::new(then),
});
// must parse 'let' keyword first so it doesn't become an identifier

View file

@ -9998,3 +9998,4 @@ let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
six

906
programs/short.jang Normal file
View file

@ -0,0 +1,906 @@
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
let five = 5;
let five = five + 3;
fn sum x y = x + y;
fn mul x y = x*y;
let six = sum(1,sum(mul(2,2),3));
six

View file

@ -1,4 +1,3 @@
use chumsky::prelude::*;
use jang::*;
use std::collections::HashMap;
@ -7,23 +6,10 @@ fn main() {
let src = std::fs::read_to_string(&path).unwrap();
println!("Parsing file at {path}");
println!("src:\n{}\n---", src);
let combo_parse_result = create_combo_parser().parse(&src);
println!("combo parsed:\n{:?}\n---", combo_parse_result);
if let Ok(ast) = combo_parse_result.into_result() {
let mut vars = HashMap::new();
let output = eval(&ast, &mut vars);
println!("{:?}", output);
}
println!("----\n");
let lex_result = create_lexer().parse(&src);
println!("lexed:\n{:?}\n---", lex_result);
let Ok(lexed) = lex_result.into_result() else {
return;
};
let parse_result = create_parser().parse(&lexed);
let parse_result = parse::<true>(&src);
println!("parsed:\n{:?}\n---", parse_result);
if let Ok(ast) = parse_result.into_result() {
if let Ok(ast) = parse_result {
let mut vars = HashMap::new();
let output = eval(&ast, &mut vars);
println!("{:?}", output);