Compare commits

...
Author SHA1 Message Date
Schrottkatze
ccc6d4f532
update/fix cargo.lock 2024-07-08 20:51:51 +02:00
Schrottkatze
54401d2a21
app: apply review 2024-07-08 20:49:13 +02:00
Schrottkatze
18309ec919
app, prowocessing: move dev commands to tests 2024-07-08 20:49:13 +02:00
Schrottkatze
0705702d4a
experimentation: implement some basic traits for io and data types 2024-07-08 20:49:13 +02:00
Schrottkatze
31a044577a
experimentation: use dynamic type ids for signatures and add qol macro 2024-07-08 20:49:13 +02:00
Schrottkatze
911339fc2a
simplified by entirely removing DataRef 2024-07-08 20:49:12 +02:00
Schrottkatze
619b7acf94
prowocessing: let-else refatoring as according to review 2024-07-08 20:49:12 +02:00
Schrottkatze
b7bc0366c2
prowocessing: apply most basic reviews 2024-07-08 20:48:56 +02:00
Schrottkatze
734a734f09
prowocessing: add documentation of trait experiment 2024-07-08 20:48:10 +02:00
Schrottkatze
dddbcccf72
prowocessing: refactor trait based experiment to individual files 2024-07-08 20:48:10 +02:00
Schrottkatze
26996fbd00
prowocessing: add trait based experiment 2024-07-08 20:48:10 +02:00
Schrottkatze
d9a07c8898
prowocessing: extract experiment into its own file 2024-07-08 20:48:10 +02:00
Schrottkatze
db9228dec4
cli: add dev command for enums experiment 2024-07-08 20:48:10 +02:00
Schrottkatze
56ec11e143
cli: add subcommand support 2024-07-08 20:48:09 +02:00
Schrottkatze
1e9648966f
experimentation: write experiment for enum architecture 2024-07-08 20:48:09 +02:00
Schrottkatze
a2695a2a11
processing library: init 2024-07-08 20:46:39 +02:00
Schrottkatze
dc44244e7b
lang: work on some basics 2024-07-08 20:23:29 +02:00
Schrottkatze
1e0741e600
lang: add credit to macro 2024-07-08 20:20:45 +02:00
Schrottkatze
3eee768ce1
lang: work on various things
- work on new world
  - add file db
  - source_file parsing
  - locs
- fix some test stuff
2024-07-06 21:57:42 +02:00
Schrottkatze
eb7806572b
lang: remove this attempt 2024-06-23 20:53:05 +02:00
Schrottkatze
1c6180aabc
lang: current state for archival purposes 2024-06-23 20:32:10 +02:00
Schrottkatze
37651a83bc
lang: current state idk try to parallelize 2024-06-10 09:47:48 +02:00
Schrottkatze
3e2c5946c8
lang: add registry/namespace 2024-06-06 12:59:30 +02:00
Schrottkatze
1a533eb788
lang: smol module tree things and details 2024-06-06 09:53:28 +02:00
Schrottkatze
7bc603f7e7
lang: module resolvin 2024-06-05 21:10:52 +02:00
Schrottkatze
d6bc644fb6
lang: basic ast work 2024-06-05 18:00:14 +02:00
Schrottkatze
cfefab9fd0
lang: fix some details in the parser 2024-06-05 09:57:08 +02:00
Schrottkatze
0de076ace1
lang: finish module/top level syntax 2024-06-03 12:05:38 +02:00
Schrottkatze
946ac879a7
lang: basic module syntax grammar 2024-06-03 11:22:36 +02:00
Schrottkatze
f6da90a354
lang: improve and simplify error handling and storage
fixes wrong error ordering with errors using `forward_parents`.
2024-06-03 10:53:59 +02:00
Schrottkatze
ed151c2e3c
lang: handle and recover some errors in lists 2024-05-04 23:12:47 +02:00
Schrottkatze
4bcaf945d7
lang: add highlighting to errors 2024-05-04 22:35:18 +02:00
Schrottkatze
29cdcfbe0c
lang: make output errors debuggable 2024-05-04 21:56:12 +02:00
Schrottkatze
afd493be16
lang: parse pipelines 2024-05-04 21:44:02 +02:00
Schrottkatze
30f17773a8
lang: add pipelines and rename parser to lst_parser 2024-04-30 12:21:06 +02:00
Schrottkatze
db2643359c
lang: basic attrset parser 2024-04-30 10:18:59 +02:00
Schrottkatze
9af71ed3f4
lang: implement vec, list and matrix 2024-04-30 09:45:36 +02:00
Schrottkatze
8a541546d9
app: fix error_reporting not being used 2024-04-28 13:22:04 +02:00
Schrottkatze
4df0118aa4
lang: first test and stuff 2024-04-24 21:09:55 +02:00
Schrottkatze
ba0da33509
split up files a bit 2024-04-24 20:00:17 +02:00
Schrottkatze
9510d9254c
lang: fix matrix recovery 2024-04-24 19:55:25 +02:00
Schrottkatze
e62b50a51a
lang: make Markers debuggable 2024-04-24 19:55:16 +02:00
Schrottkatze
2bea3994c2
lang: matrix parser! 2024-04-24 19:37:52 +02:00
Schrottkatze
86b1481943
lang: remove empty recursive parser module 2024-04-24 11:15:07 +02:00
Schrottkatze
06c9094227
lang: fix main 2024-04-24 11:09:48 +02:00
Schrottkatze
381ab45edc
lang: rewrite parser 2024-04-24 11:07:38 +02:00
Schrottkatze
6d8b79e8f7
lang: apparently add event debug printer 2024-04-15 16:22:33 +02:00
Schrottkatze
be637846b1
lang: kinda fun parsing things that can now parse attribute sets with one attribute 2024-04-12 21:31:55 +02:00
Schrottkatze
1711d17fa6
lang: parsing to events now 2024-04-12 20:55:55 +02:00
Schrottkatze
f7b61f9e0e
lang: start working on parser that parses to events 2024-04-12 15:43:34 +02:00
Schrottkatze
2d59a7f560
lang: start implementing parser combinators (i have no idea what i'm doing)
also, the current test.owo crashes for some reason. this is a headache.
manual/imperative parsers are a nightmare.
2024-04-12 01:02:07 +02:00
Schrottkatze
9da157ff4a
lang: massive amounts of parser and ast pain 2024-04-11 03:23:03 +02:00
Schrottkatze
881a987b2f
flake.lock: Update
Flake lock file updates:

• Updated input 'devenv':
    'github:cachix/devenv/18ef9849d1ecac7a9a7920eb4f2e4adcf67a8c3a' (2024-01-09)
  → 'github:cachix/devenv/a71323c618664a6b7a39bc183b0ce22ac8511cf9' (2024-04-08)
• Added input 'devenv/cachix':
    'github:cachix/cachix/661bbb7f8b55722a0406456b15267b5426a3bda6' (2024-03-15)
• Added input 'devenv/cachix/devenv':
    'github:cachix/devenv/2ee4450b0f4b95a1b90f2eb5ffea98b90e48c196' (2024-02-23)
• Added input 'devenv/cachix/devenv/flake-compat':
    follows 'devenv/cachix/flake-compat'
• Added input 'devenv/cachix/devenv/nix':
    'github:domenkozar/nix/ecd0af0c1f56de32cbad14daa1d82a132bf298f8' (2024-02-22)
• Added input 'devenv/cachix/devenv/nix/flake-compat':
    'github:edolstra/flake-compat/35bb57c0c8d8b62bbfd284272c928ceb64ddbde9' (2023-01-17)
• Added input 'devenv/cachix/devenv/nix/nixpkgs':
    follows 'devenv/cachix/devenv/nixpkgs'
• Added input 'devenv/cachix/devenv/nix/nixpkgs-regression':
    'github:NixOS/nixpkgs/215d4d0fd80ca5163643b03a33fde804a29cc1e2' (2022-01-24)
• Added input 'devenv/cachix/devenv/nixpkgs':
    'github:NixOS/nixpkgs/9201b5ff357e781bf014d0330d18555695df7ba8' (2023-08-23)
• Added input 'devenv/cachix/devenv/poetry2nix':
    'github:nix-community/poetry2nix/d5006be9c2c2417dafb2e2e5034d83fabd207ee3' (2023-08-24)
• Added input 'devenv/cachix/devenv/poetry2nix/flake-utils':
    'github:numtide/flake-utils/919d646de7be200f3bf08cb76ae1f09402b6f9b4' (2023-07-11)
• Added input 'devenv/cachix/devenv/poetry2nix/flake-utils/systems':
    'github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e' (2023-04-09)
• Added input 'devenv/cachix/devenv/poetry2nix/nix-github-actions':
    'github:nix-community/nix-github-actions/165b1650b753316aa7f1787f3005a8d2da0f5301' (2023-07-09)
• Added input 'devenv/cachix/devenv/poetry2nix/nix-github-actions/nixpkgs':
    follows 'devenv/cachix/devenv/poetry2nix/nixpkgs'
• Added input 'devenv/cachix/devenv/poetry2nix/nixpkgs':
    follows 'devenv/cachix/devenv/nixpkgs'
• Added input 'devenv/cachix/devenv/pre-commit-hooks':
    follows 'devenv/cachix/pre-commit-hooks'
• Added input 'devenv/cachix/flake-compat':
    'github:edolstra/flake-compat/0f9255e01c2351cc7d116c072cb317785dd33b33' (2023-10-04)
• Added input 'devenv/cachix/nixpkgs':
    follows 'devenv/nixpkgs'
• Added input 'devenv/cachix/pre-commit-hooks':
    'github:cachix/pre-commit-hooks.nix/5df5a70ad7575f6601d91f0efec95dd9bc619431' (2024-02-15)
• Added input 'devenv/cachix/pre-commit-hooks/flake-compat':
    'github:edolstra/flake-compat/0f9255e01c2351cc7d116c072cb317785dd33b33' (2023-10-04)
• Added input 'devenv/cachix/pre-commit-hooks/flake-utils':
    'github:numtide/flake-utils/4022d587cbbfd70fe950c1e2083a02621806a725' (2023-12-04)
• Added input 'devenv/cachix/pre-commit-hooks/flake-utils/systems':
    'github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e' (2023-04-09)
• Added input 'devenv/cachix/pre-commit-hooks/gitignore':
    'github:hercules-ci/gitignore.nix/43e1aa1308018f37118e34d3a9cb4f5e75dc11d5' (2023-12-29)
• Added input 'devenv/cachix/pre-commit-hooks/gitignore/nixpkgs':
    follows 'devenv/cachix/pre-commit-hooks/nixpkgs'
• Added input 'devenv/cachix/pre-commit-hooks/nixpkgs':
    follows 'devenv/cachix/nixpkgs'
• Added input 'devenv/cachix/pre-commit-hooks/nixpkgs-stable':
    'github:NixOS/nixpkgs/3dc440faeee9e889fe2d1b4d25ad0f430d449356' (2024-01-10)
• Updated input 'devenv/flake-compat':
    'github:edolstra/flake-compat/35bb57c0c8d8b62bbfd284272c928ceb64ddbde9' (2023-01-17)
  → 'github:edolstra/flake-compat/0f9255e01c2351cc7d116c072cb317785dd33b33' (2023-10-04)
• Updated input 'devenv/nix':
    'github:domenkozar/nix/7c91803598ffbcfe4a55c44ac6d49b2cf07a527f' (2023-02-16)
  → 'github:domenkozar/nix/c5bbf14ecbd692eeabf4184cc8d50f79c2446549' (2024-03-15)
• Added input 'devenv/nix/flake-compat':
    'github:edolstra/flake-compat/35bb57c0c8d8b62bbfd284272c928ceb64ddbde9' (2023-01-17)
• Removed input 'devenv/nix/lowdown-src'
• Updated input 'devenv/nixpkgs':
    'github:NixOS/nixpkgs/126f49a01de5b7e35a43fd43f891ecf6d3a51459' (2023-03-15)
  → 'github:cachix/devenv-nixpkgs/829e73affeadfb4198a7105cbe3a03153d13edc9' (2024-03-12)
• Updated input 'devenv/pre-commit-hooks':
    'github:cachix/pre-commit-hooks.nix/ea96f0c05924341c551a797aaba8126334c505d2' (2024-01-08)
  → 'github:cachix/pre-commit-hooks.nix/e35aed5fda3cc79f88ed7f1795021e559582093a' (2024-04-02)
• Updated input 'devenv/pre-commit-hooks/flake-utils':
    'github:numtide/flake-utils/a1720a10a6cfe8234c0e93907ffe81be440f4cef' (2023-05-31)
  → 'github:numtide/flake-utils/b1d9ab70662946ef0850d488da1c9019f3a9752a' (2024-03-11)
• Updated input 'devenv/pre-commit-hooks/gitignore':
    'github:hercules-ci/gitignore.nix/a20de23b925fd8264fd7fad6454652e142fd7f73' (2022-08-14)
  → 'github:hercules-ci/gitignore.nix/637db329424fd7e46cf4185293b9cc8c88c95394' (2024-02-28)
• Updated input 'devenv/pre-commit-hooks/nixpkgs-stable':
    'github:NixOS/nixpkgs/c37ca420157f4abc31e26f436c1145f8951ff373' (2023-06-03)
  → 'github:NixOS/nixpkgs/614b4613980a522ba49f0d194531beddbb7220d3' (2024-03-17)
• Updated input 'fenix':
    'github:nix-community/fenix/93e89638c15512db65e931f26ce36edf8cfbb4a5' (2024-01-10)
  → 'github:nix-community/fenix/99c6241db5ca5363c05c8f4acbdf3a4e8fc42844' (2024-04-06)
• Updated input 'fenix/nixpkgs':
    'github:nixos/nixpkgs/46ae0210ce163b3cba6c7da08840c1d63de9c701' (2024-01-06)
  → 'github:nixos/nixpkgs/fd281bd6b7d3e32ddfa399853946f782553163b5' (2024-04-03)
• Updated input 'fenix/rust-analyzer-src':
    'github:rust-lang/rust-analyzer/ae6e73772432cfe35bb0ff6de6fdcfa908642b67' (2024-01-09)
  → 'github:rust-lang/rust-analyzer/8e581ac348e223488622f4d3003cb2bd412bf27e' (2024-04-03)
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/317484b1ead87b9c1b8ac5261a8d2dd748a0492d' (2024-01-08)
  → 'github:NixOS/nixpkgs/ff0dbd94265ac470dda06a657d5fe49de93b4599' (2024-04-06)
2024-04-08 23:27:56 +02:00
Schrottkatze
bfd4b3765f
lang: state with confusing error 2024-04-08 15:43:42 +02:00
Schrottkatze
198c74c7ae
lang: make attrset delims braces 2024-04-08 14:04:52 +02:00
Schrottkatze
8d7401531e
lang: some small, unfinished stuff 2024-04-07 01:04:02 +02:00
Schrottkatze
b6e304fa78
lang: rework ast structure 2024-04-07 00:55:12 +02:00
Schrottkatze
ace69b0094
svg-filters: format matrices in complex test 2024-04-03 20:08:33 +02:00
Schrottkatze
84448af714
lang: funky basic error reporting stuff 2024-04-03 17:00:20 +02:00
Schrottkatze
ae60db7721
lang: extract tests into file 2024-04-03 00:30:11 +02:00
Schrottkatze
de008263ca
lang: add test 2024-04-03 00:28:45 +02:00
Schrottkatze
ca84af4e1b
lang: basic parser 2024-04-03 00:08:00 +02:00
Schrottkatze
ae86ae29ab
svg-filters: more testssss 2024-03-24 17:07:35 +01:00
Schrottkatze
02c5e9e159
svg-filters: figured out flood not working in local test env 2024-03-24 16:11:07 +01:00
Schrottkatze
0197df5ee2
svg-filters: add turbulence and displacement map 2024-03-24 15:49:41 +01:00
Schrottkatze
919a3bb377
svg-filters: seperate out abstractions and add flood abstraction 2024-03-22 16:47:21 +01:00
Schrottkatze
9ae8c2fbd3
svg-filters: add nice abstractions for component transfer 2024-03-22 16:24:04 +01:00
Schrottkatze
9727ef82ca
svg-filters: implement feComponentTransfer rendering 2024-03-22 16:05:36 +01:00
Schrottkatze
c31a158d9b
svg-filters: rework macro slightly 2024-03-20 19:11:42 +01:00
Schrottkatze
aeeee54200
svg-filters: new conditional attrs macro 2024-03-19 18:43:30 +01:00
Schrottkatze
dc7d76dc26
svg-filters: create gen_attr and gen_attrs convenience macros 2024-03-19 15:47:09 +01:00
Schrottkatze
e17fffb66b
svg-filters: blend node 2024-03-19 15:15:36 +01:00
Schrottkatze
f59062cf88
svg-filters: cleanup 2024-03-17 00:51:20 +01:00
Schrottkatze
384fef5a81
svg-filters(primitives): start with feComponentTransfer 2024-03-17 00:50:51 +01:00
Schrottkatze
77bcb54b5e
svg-filters(tests): start 2024-03-17 00:50:16 +01:00
Schrottkatze
d87033d320
svg-filters(codegen): add pretty and ugly printing 2024-03-17 00:49:53 +01:00
Schrottkatze
bf60bdd814
svg-filters: simplify and refactor a bit 2024-03-16 23:57:09 +01:00
Schrottkatze
5368951254
svg-filters: rework codegen 2024-03-16 20:52:45 +01:00
Schrottkatze
a42ec014e5
svg-filters: get svg generation working!!!! 2024-03-16 00:35:23 +01:00
Schrottkatze
01b1880089
svg-filters: get bare basic xml generation going 2024-03-15 22:45:28 +01:00
Schrottkatze
56848a1b05
svg-filters: add basic graph and stuffs 2024-03-15 19:52:40 +01:00
Schrottkatze
69f0baf425
svg-filters: init 2024-03-15 16:44:47 +01:00
Schrottkatze
98850ee1e9
lang: lexer 2024-03-08 12:34:09 +01:00
93 changed files with 5266 additions and 292 deletions

875
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -2,13 +2,17 @@
members = [
"crates/app",
"crates/eval",
"crates/ir",
"crates/ir",
"crates/lang",
"crates/svg-filters",
"crates/prowocessing",
]
resolver = "2"
[workspace.dependencies]
clap = { version = "4", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
petgraph = "0.6.4"
# to enable all the lints below, this must be present in a workspace member's Cargo.toml:
# [lints]

View file

@ -2,6 +2,7 @@
name = "app"
version = "0.1.0"
edition = "2021"
default-run = "app"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -11,6 +12,7 @@ clap = { workspace = true, features = [ "derive", "env" ] }
dirs = "5"
eval = { path = "../eval" }
ir = { path = "../ir" }
prowocessing = { path = "../prowocessing"}
owo-colors = "4"
ron = "0.8"
serde = { workspace = true, features = [ "derive" ] }

View file

@ -1,18 +1,11 @@
use std::path::PathBuf;
use clap::Parser;
use self::{
cli::Args,
config_file::{find_config_file, Configs},
};
use self::config_file::{find_config_file, Configs};
pub(crate) use cli::CliConfigs;
mod cli;
mod config_file;
/// this struct may hold all configuration
pub struct Config {
pub source: PathBuf,
pub evaluator: eval::Available,
pub startup_msg: bool,
@ -20,13 +13,17 @@ pub struct Config {
impl Config {
/// Get the configs from all possible places (args, file, env...)
pub fn read() -> Self {
let args = Args::parse();
let config = if let Some(config) = args.config_path {
Ok(config)
} else {
find_config_file()
};
pub fn read(args: &CliConfigs) -> Self {
// let config = if let Some(config) = &args.config_path {
// Ok(config.clone())
// } else {
// find_config_file()
// };
let config = args
.config_path
.clone()
.ok_or(())
.or_else(|()| find_config_file());
// try to read a maybe existing config file
let config = config.ok().and_then(|path| {
@ -42,7 +39,6 @@ impl Config {
if let Some(file) = config {
Self {
source: args.source,
evaluator: args.evaluator.and(file.evaluator).unwrap_or_default(),
// this is negated because to an outward api, the negative is more intuitive,
// while in the source the other way around is more intuitive
@ -50,7 +46,6 @@ impl Config {
}
} else {
Self {
source: args.source,
startup_msg: !args.no_startup_message,
evaluator: args.evaluator.unwrap_or_default(),
}

View file

@ -1,12 +1,9 @@
use std::path::PathBuf;
use clap::{builder::BoolishValueParser, ArgAction, Parser};
#[derive(Parser)]
pub(crate) struct Args {
/// What file contains the pipeline to evaluate.
pub source: PathBuf,
use clap::{builder::BoolishValueParser, ArgAction, Args};
#[derive(Args)]
pub(crate) struct CliConfigs {
/// How to actually run the pipeline.
/// Overrides the config file. Defaults to the debug evaluator.
#[arg(short, long)]

View file

@ -5,7 +5,9 @@ use std::{
use serde::{Deserialize, Serialize};
use super::error::Config;
use crate::error_reporting::{report_serde_json_err, report_serde_ron_err};
use super::error::{self, Config};
#[derive(Debug, Serialize, Deserialize)]
pub struct Configs {
@ -40,14 +42,20 @@ pub(super) fn find_config_file() -> Result<PathBuf, Config> {
}
impl Configs {
pub fn read(p: PathBuf) -> Result<Self, Config> {
pub fn read(p: PathBuf) -> Result<Self, error::Config> {
match p
.extension()
.map(|v| v.to_str().expect("config path to be UTF-8"))
{
Some("ron") => Ok(serde_json::from_str(&fs::read_to_string(p)?)?),
Some("json") => Ok(ron::from_str(&fs::read_to_string(p)?)?),
e => Err(Config::UnknownExtension(e.map(str::to_owned))),
Some("ron") => {
let f = fs::read_to_string(p)?;
ron::from_str(&f).or_else(|e| report_serde_ron_err(&f, &e))
}
Some("json") => {
let f = fs::read_to_string(p)?;
serde_json::from_str(&f).or_else(|e| report_serde_json_err(&f, &e))
}
e => Err(error::Config::UnknownExtension(e.map(str::to_owned))),
}
}
}

View file

@ -25,7 +25,7 @@ fn report_serde_err(src: &str, line: usize, col: usize, msg: String) -> ! {
.finish()
.eprint(("test", Source::from(src)))
.expect("writing error to stderr failed");
process::exit(1);
process::exit(1)
}
/// Reconstruct a byte offset from the line + column numbers typical from serde crates

View file

@ -1,6 +1,8 @@
use std::fs;
use std::{fs, path::PathBuf};
use config::Config;
use clap::{Parser, Subcommand};
use config::{CliConfigs, Config};
use dev::DevCommands;
use welcome_msg::print_startup_msg;
mod config;
@ -9,19 +11,60 @@ mod config;
mod error_reporting;
mod welcome_msg;
#[derive(Parser)]
struct Args {
#[command(flatten)]
configs: CliConfigs,
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Run {
/// What file contains the pipeline to evaluate.
source: PathBuf,
},
Dev {
#[command(subcommand)]
command: DevCommands,
},
}
fn main() {
// TODO: proper error handling across the whole function
// don't forget to also look inside `Config`
let cfg = Config::read();
let args = Args::parse();
let cfg = Config::read(&args.configs);
if cfg.startup_msg {
print_startup_msg();
}
let source = fs::read_to_string(cfg.source).expect("can't find source file");
let ir = ir::from_ron(&source).expect("failed to parse source to graph ir");
match args.command {
Commands::Run { source } => {
let source = fs::read_to_string(source).expect("can't find source file");
let ir = ir::from_ron(&source).expect("failed to parse source to graph ir");
let mut machine = cfg.evaluator.pick();
machine.feed(ir);
machine.eval_full();
let mut machine = cfg.evaluator.pick();
machine.feed(ir);
machine.eval_full();
}
Commands::Dev {
command: dev_command,
} => dev_command.run(),
}
}
mod dev {
use clap::Subcommand;
#[derive(Subcommand)]
pub(crate) enum DevCommands {}
impl DevCommands {
pub fn run(self) {
println!("There are currently no dev commands.");
}
}
}

View file

@ -37,7 +37,7 @@ impl Available {
#[must_use]
pub fn pick(&self) -> Box<dyn Evaluator> {
match self {
Self::Debug => Box::new(kind::debug::Evaluator::default()),
Self::Debug => Box::<kind::debug::Evaluator>::default(),
}
}
}

25
crates/lang/Cargo.toml Normal file
View file

@ -0,0 +1,25 @@
[package]
name = "lang"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
logos = "0.14"
petgraph = { workspace = true}
indexmap = "2.2.6"
clap = { version = "4", features = ["derive"] }
ariadne = "0.4.0"
ego-tree = "0.6.2"
rowan = "0.15.15"
drop_bomb = "0.1.5"
enumset = "1.1.3"
indoc = "2"
dashmap = "5.5.3"
crossbeam = "0.8.4"
owo-colors = {version = "4", features = ["supports-colors"]}
strip-ansi-escapes = "0.2.0"
[lints]
workspace = true

80
crates/lang/src/ast.rs Normal file
View file

@ -0,0 +1,80 @@
use crate::lst_parser::syntax_kind::SyntaxKind::*;
use crate::SyntaxNode;
use rowan::Language;
// Heavily modified version of https://github.com/rust-analyzer/rowan/blob/e2d2e93e16c5104b136d0bc738a0d48346922200/examples/s_expressions.rs#L250-L266
macro_rules! ast_nodes {
($($ast:ident, $kind:ident);+) => {
$(
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[repr(transparent)]
pub struct $ast(SyntaxNode);
impl rowan::ast::AstNode for $ast {
type Language = crate::Lang;
fn can_cast(kind: <Self::Language as Language>::Kind) -> bool {
kind == $kind
}
fn cast(node: SyntaxNode) -> Option<Self> {
if node.kind() == $kind {
Some(Self(node))
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.0
}
}
)+
};
}
ast_nodes!(
Def, DEF;
DefName, DEF_NAME;
DefBody, DEF_BODY;
Mod, MODULE;
ModName, MODULE_NAME;
ModBody, MODULE_BODY;
Use, USE;
UsePat, USE_PAT;
PatItem, PAT_ITEM;
PatGlob, PAT_GLOB;
PatGroup, PAT_GROUP;
Literal, LITERAL;
IntLit, INT_NUM;
FloatLit, FLOAT_NUM;
StringLit, STRING;
Matrix, MATRIX;
MatrixRow, MAT_ROW;
Vector, VEC;
List, LIST;
CollectionItem, COLLECTION_ITEM;
ParenthesizedExpr, PARENTHESIZED_EXPR;
Expression, EXPR;
Pipeline, PIPELINE;
Instruction, INSTR;
InstructionName, INSTR_NAME;
InstructionParams, INSTR_PARAMS;
AttributeSet, ATTR_SET;
Attribute, ATTR;
AttributeName, ATTR_NAME;
AttributeValue, ATTR_VALUE;
ParseError, PARSE_ERR;
LexError, LEX_ERR;
Root, ROOT;
Eof, EOF
);

25
crates/lang/src/lib.rs Normal file
View file

@ -0,0 +1,25 @@
#![feature(type_alias_impl_trait, lint_reasons, box_into_inner)]
use crate::lst_parser::syntax_kind::SyntaxKind;
pub mod ast;
pub mod lst_parser;
pub mod world;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Lang {}
impl rowan::Language for Lang {
type Kind = SyntaxKind;
#[allow(unsafe_code)]
fn kind_from_raw(raw: rowan::SyntaxKind) -> Self::Kind {
assert!(raw.0 <= SyntaxKind::ROOT as u16);
unsafe { std::mem::transmute::<u16, SyntaxKind>(raw.0) }
}
fn kind_to_raw(kind: Self::Kind) -> rowan::SyntaxKind {
kind.into()
}
}
pub type SyntaxNode = rowan::SyntaxNode<Lang>;
pub type SyntaxToken = rowan::SyntaxNode<Lang>;
pub type SyntaxElement = rowan::NodeOrToken<SyntaxNode, SyntaxToken>;

View file

@ -0,0 +1,169 @@
use drop_bomb::DropBomb;
use self::{
error::SyntaxError,
events::{Event, NodeKind},
input::Input,
syntax_kind::SyntaxKind,
};
use std::cell::Cell;
pub mod syntax_kind;
#[cfg(test)]
mod tests;
pub mod error;
pub mod events;
pub mod grammar;
pub mod input;
pub mod output;
const PARSER_STEP_LIMIT: u32 = 4096;
pub struct Parser<'src, 'toks> {
input: Input<'src, 'toks>,
pos: usize,
events: Vec<Event>,
steps: Cell<u32>,
}
impl<'src, 'toks> Parser<'src, 'toks> {
pub fn new(input: Input<'src, 'toks>) -> Self {
Self {
input,
pos: 0,
events: Vec::new(),
steps: Cell::new(0),
}
}
pub fn finish(self) -> Vec<Event> {
self.events
}
pub(crate) fn nth(&self, n: usize) -> SyntaxKind {
self.step();
self.input.kind(self.pos + n)
}
pub fn eat_succeeding_ws(&mut self) {
self.push_ev(Event::Eat {
count: self.input.meaningless_tail_len(),
});
}
pub(crate) fn current(&self) -> SyntaxKind {
self.step();
self.input.kind(self.pos)
}
pub(crate) fn start(&mut self, name: &str) -> Marker {
let pos = self.events.len();
self.push_ev(Event::tombstone());
Marker::new(pos, name)
}
pub(crate) fn at(&self, kind: SyntaxKind) -> bool {
self.nth_at(0, kind)
}
pub(crate) fn eat(&mut self, kind: SyntaxKind) -> bool {
if !self.at(kind) {
return false;
}
self.do_bump();
true
}
pub(crate) fn nth_at(&self, n: usize, kind: SyntaxKind) -> bool {
self.nth(n) == kind
}
fn do_bump(&mut self) {
self.push_ev(Event::Eat {
count: self.input.preceding_meaningless(self.pos),
});
self.pos += 1;
}
fn push_ev(&mut self, event: Event) {
self.events.push(event)
}
fn step(&self) {
let steps = self.steps.get();
assert!(steps <= PARSER_STEP_LIMIT, "the parser seems stuck...");
self.steps.set(steps + 1);
}
}
pub(crate) struct Marker {
pos: usize,
bomb: DropBomb,
}
impl Marker {
pub(crate) fn new(pos: usize, name: &str) -> Self {
Self {
pos,
bomb: DropBomb::new(format!("Marker {name} must be completed or abandoned")),
}
}
fn close_node(mut self, p: &mut Parser, kind: NodeKind) -> CompletedMarker {
self.bomb.defuse();
match &mut p.events[self.pos] {
Event::Start { kind: slot, .. } => *slot = kind.clone(),
_ => unreachable!(),
}
p.push_ev(Event::Finish);
CompletedMarker {
pos: self.pos,
kind,
}
}
pub(crate) fn complete(self, p: &mut Parser<'_, '_>, kind: SyntaxKind) -> CompletedMarker {
self.close_node(p, NodeKind::Syntax(kind))
}
pub(crate) fn error(self, p: &mut Parser, kind: SyntaxError) -> CompletedMarker {
self.close_node(p, NodeKind::Error(kind))
}
pub(crate) fn abandon(mut self, p: &mut Parser<'_, '_>) {
self.bomb.defuse();
if self.pos == p.events.len() - 1 {
match p.events.pop() {
Some(Event::Start {
kind: NodeKind::Syntax(SyntaxKind::TOMBSTONE),
forward_parent: None,
}) => (),
_ => unreachable!(),
}
}
}
}
pub(crate) struct CompletedMarker {
pos: usize,
kind: NodeKind,
}
impl CompletedMarker {
pub(crate) fn precede(self, p: &mut Parser<'_, '_>, name: &str) -> Marker {
let new_pos = p.start(name);
match &mut p.events[self.pos] {
Event::Start { forward_parent, .. } => {
*forward_parent = Some(new_pos.pos - self.pos);
}
_ => unreachable!(),
}
new_pos
}
}

View file

@ -0,0 +1,15 @@
use crate::lst_parser::syntax_kind::SyntaxKind;
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum SyntaxError {
Expected(Vec<SyntaxKind>),
PipelineNeedsSink,
// if there was two space seperated items in a list
SpaceSepInList,
SemicolonInList,
CommaInMatOrVec,
UnterminatedTopLevelItem,
UnclosedModuleBody,
UnfinishedPath,
PathSepContainsSemicolon,
}

View file

@ -0,0 +1,70 @@
use crate::lst_parser::syntax_kind::SyntaxKind;
use super::error::SyntaxError;
#[derive(Debug)]
pub enum Event {
Start {
kind: NodeKind,
forward_parent: Option<usize>,
},
Finish,
Eat {
count: usize,
},
}
#[derive(Debug, Clone, PartialEq)]
pub enum NodeKind {
Syntax(SyntaxKind),
Error(SyntaxError),
}
impl NodeKind {
pub fn is_syntax(&self) -> bool {
matches!(self, Self::Syntax(_))
}
pub fn is_error(&self) -> bool {
matches!(self, Self::Error(_))
}
}
impl From<SyntaxKind> for NodeKind {
fn from(value: SyntaxKind) -> Self {
NodeKind::Syntax(value)
}
}
impl From<SyntaxError> for NodeKind {
fn from(value: SyntaxError) -> Self {
NodeKind::Error(value)
}
}
impl PartialEq<SyntaxKind> for NodeKind {
fn eq(&self, other: &SyntaxKind) -> bool {
match self {
NodeKind::Syntax(s) => s == other,
NodeKind::Error(_) => false,
}
}
}
impl PartialEq<SyntaxError> for NodeKind {
fn eq(&self, other: &SyntaxError) -> bool {
match self {
NodeKind::Syntax(_) => false,
NodeKind::Error(e) => e == other,
}
}
}
impl Event {
pub(crate) fn tombstone() -> Self {
Self::Start {
kind: SyntaxKind::TOMBSTONE.into(),
forward_parent: None,
}
}
}

View file

@ -0,0 +1,38 @@
use std::fmt::Debug;
use crate::lst_parser::syntax_kind::SyntaxKind::*;
use self::module::{mod_body, top_level_item};
use super::{
input::Input,
output::Output,
syntax_kind::{self, lex},
Parser,
};
mod expression;
mod module;
pub fn source_file(p: &mut Parser) {
let root = p.start("root");
mod_body(p);
// expression::expression(p, false);
p.eat_succeeding_ws();
root.complete(p, ROOT);
}
fn check_parser(input: &str, parser_fn: fn(&mut Parser), output: &str) {
let toks = lex(input);
let mut parser = Parser::new(Input::new(&toks));
parser_fn(&mut parser);
let p_out = dbg!(parser.finish());
let o = Output::from_parser_output(toks, p_out);
let s = strip_ansi_escapes::strip_str(format!("{o:?}"));
assert_eq!(&s, output);
}

View file

@ -0,0 +1,44 @@
use crate::lst_parser::{error::SyntaxError, syntax_kind::SyntaxKind::*, CompletedMarker, Parser};
use self::{collection::collection, instruction::instr, lit::literal, pipeline::PIPES};
mod collection;
mod instruction;
mod lit;
mod pipeline;
pub fn expression(p: &mut Parser, in_pipe: bool) -> Option<CompletedMarker> {
let expr = p.start("expr");
if atom(p).or_else(|| instr(p)).is_none() {
expr.abandon(p);
return None;
}
let r = expr.complete(p, EXPR);
if PIPES.contains(p.current()) && !in_pipe {
pipeline::pipeline(p, r)
} else {
Some(r)
}
}
pub fn atom(p: &mut Parser) -> Option<CompletedMarker> {
literal(p)
.or_else(|| collection(p))
.or_else(|| parenthesized_expr(p))
}
pub fn parenthesized_expr(p: &mut Parser) -> Option<CompletedMarker> {
if p.eat(L_PAREN) {
let par_expr = p.start("parenthesized");
expression(p, false);
if !p.eat(R_PAREN) {
return Some(par_expr.error(p, SyntaxError::Expected(vec![R_PAREN])));
}
return Some(par_expr.complete(p, PARENTHESIZED_EXPR));
}
None
}

View file

@ -0,0 +1,25 @@
use enumset::enum_set;
use crate::lst_parser::{
syntax_kind::{SyntaxKind::*, TokenSet},
CompletedMarker, Parser,
};
use self::{attr_set::attr_set, vec::vec_matrix_list};
mod attr_set;
mod vec;
const COLLECTION_START: TokenSet = enum_set!(L_BRACK | L_BRACE);
pub fn collection(p: &mut Parser) -> Option<CompletedMarker> {
if !COLLECTION_START.contains(p.current()) {
return None;
}
Some(match p.current() {
L_BRACK => vec_matrix_list(p),
L_BRACE => attr_set(p),
_ => unreachable!(),
})
}

View file

@ -0,0 +1,45 @@
use crate::lst_parser::{
error::SyntaxError,
grammar::expression::{atom, expression},
CompletedMarker, Marker, Parser,
SyntaxKind::*,
};
pub fn attr_set(p: &mut Parser) -> CompletedMarker {
let start = p.start("attr_set_start");
assert!(p.eat(L_BRACE));
loop {
if attr(p).is_some() {
// TODO: handle others
if p.eat(COMMA) {
continue;
} else if p.eat(R_BRACE) {
return start.complete(p, ATTR_SET);
}
// TODO: check for newline and stuff following that for recov of others
} else if p.eat(R_BRACE) {
return start.complete(p, ATTR_SET);
}
}
}
fn attr(p: &mut Parser) -> Option<CompletedMarker> {
if p.at(IDENT) {
let attr_start = p.start("attr");
let attr_name_start = p.start("attr_name");
p.do_bump();
attr_name_start.complete(p, ATTR_NAME);
// TODO: handle comma, expr/atom, other
p.eat(COLON);
// TODO: handle failed expr parser too
let attr_value = p.start("attr_value");
let _ = expression(p, false);
attr_value.complete(p, ATTR_VALUE);
Some(attr_start.complete(p, ATTR))
} else {
None
}
}

View file

@ -0,0 +1,97 @@
use crate::lst_parser::{
error::SyntaxError, grammar::expression::atom, CompletedMarker, Marker, Parser, SyntaxKind::*,
};
pub fn vec_matrix_list(p: &mut Parser) -> CompletedMarker {
let start = p.start("vec_matrix_list_start");
assert!(p.eat(L_BRACK));
let row_start = p.start("matrix_row_start");
if let Some(item) = atom(p) {
item.precede(p, "coll_item_start")
.complete(p, COLLECTION_ITEM);
if p.at(COMMA) {
row_start.abandon(p);
return finish_list(p, start);
}
finish_mat_or_vec(p, start, row_start)
} else if p.eat(R_BRACK) {
row_start.abandon(p);
start.complete(p, LIST)
} else {
row_start.abandon(p);
start.error(p, SyntaxError::Expected(vec![EXPR, R_BRACK]))
}
}
fn finish_list(p: &mut Parser, list_start: Marker) -> CompletedMarker {
loop {
if p.eat(COMMA) {
if let Some(item) = atom(p) {
item.precede(p, "coll_item_start")
.complete(p, COLLECTION_ITEM);
} else if p.eat(R_BRACK) {
return list_start.complete(p, LIST);
}
} else if p.eat(R_BRACK) {
return list_start.complete(p, LIST);
} else if let Some(item) = atom(p) {
item.precede(p, "next_item")
.complete(p, COLLECTION_ITEM)
.precede(p, "err_space_sep")
.error(p, SyntaxError::SpaceSepInList);
} else if p.at(SEMICOLON) {
let semi_err = p.start("semicolon_err");
p.eat(SEMICOLON);
semi_err.error(p, SyntaxError::SemicolonInList);
if let Some(item) = atom(p) {
item.precede(p, "coll_item_start")
.complete(p, COLLECTION_ITEM);
} else if p.eat(R_BRACK) {
return list_start.complete(p, LIST);
}
}
}
}
// TODO: handle commas, general other wrong toks
fn finish_mat_or_vec(p: &mut Parser, coll_start: Marker, mut row_start: Marker) -> CompletedMarker {
let mut is_matrix = false;
let mut row_item_count = 1;
loop {
if let Some(item) = atom(p) {
item.precede(p, "coll_item_start")
.complete(p, COLLECTION_ITEM);
row_item_count += 1;
} else if p.at(SEMICOLON) {
is_matrix = true;
row_start.complete(p, MAT_ROW);
p.eat(SEMICOLON);
row_start = p.start("matrix_row_start");
row_item_count = 0;
} else if p.at(R_BRACK) {
if is_matrix && row_item_count == 0 {
row_start.abandon(p);
p.eat(R_BRACK);
return coll_start.complete(p, MATRIX);
} else if is_matrix {
row_start.complete(p, MAT_ROW);
p.eat(R_BRACK);
return coll_start.complete(p, MATRIX);
} else {
row_start.abandon(p);
p.eat(R_BRACK);
return coll_start.complete(p, VEC);
}
} else if p.at(COMMA) {
let err_unexpected_comma = p.start("err_unexpected_comma");
p.do_bump();
err_unexpected_comma.error(p, SyntaxError::CommaInMatOrVec);
} else {
let err_unexpected = p.start("err_unexpected_tok");
p.do_bump();
err_unexpected.error(p, SyntaxError::Expected(vec![EXPR, SEMICOLON, R_BRACK]));
}
}
}

Some files were not shown because too many files have changed in this diff Show more