Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 66 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions brane-dsl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ license.workspace = true
[dependencies]
enum-debug.workspace = true
log = "0.4.22"
nom = "7.1.0"
nom_locate = "4.1.0"
nom = "8.0.0"
nom_locate = "5.0.0"
nom-language = "0.1.0"
rand = "0.9.0"
regex = "1.5.0"
serde = "1.0.204"

brane-shr = { path = "../brane-shr" }
specifications = { path = "../specifications" }

[dev-dependencies]
insta = { version = "1.42.2", features=["yaml"] }

[lints]
workspace = true
89 changes: 7 additions & 82 deletions brane-dsl/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,83 +14,18 @@
//

use log::trace;
use nom::InputLength;
use nom::error::VerboseErrorKind;
use nom::Input as _;
use nom_language::error::VerboseErrorKind;
use specifications::package::PackageIndex;

use crate::errors;
pub use crate::errors::ParseError as Error;
use crate::parser::ast::Program;
use crate::parser::{bakery, bscript};
use crate::parser::bscript;
use crate::scanner::{self, Span, Token, Tokens};
use crate::spec::Language;


/***** TESTS *****/
#[cfg(test)]
pub mod tests {
use brane_shr::utilities::{create_package_index, test_on_dsl_files};

use super::*;


/// Tests BraneScript files.
#[test]
fn test_bscript() {
// Simply pass to the compiler
test_on_dsl_files("BraneScript", |path, code| {
// Print the header always
println!("{}", (0..80).map(|_| '-').collect::<String>());
println!("File '{}' gave us:", path.display());

// Read the package index
let pindex: PackageIndex = create_package_index();

// Create a compiler and compile it;
let res: Program = match parse(code, &pindex, &ParserOptions::bscript()) {
Ok(res) => res,
Err(err) => {
panic!("Failed to parse BraneScript file '{}': {}", path.display(), err);
},
};

// Print it for good measure
println!("{res:#?}");
println!("{}\n\n", (0..80).map(|_| '-').collect::<String>());
});
}

/// Tests Bakery files.
#[test]
fn test_bakery() {
// Simply pass to the compiler
test_on_dsl_files("Bakery", |path, code| {
// Print the header always
println!("{}", (0..80).map(|_| '-').collect::<String>());
println!("File '{}' gave us:", path.display());

// Read the package index
let pindex: PackageIndex = create_package_index();

// Create a compiler and compile it;
let res: Program = match parse(code, &pindex, &ParserOptions::bakery()) {
Ok(res) => res,
Err(err) => {
panic!("Failed to parse Bakery file '{}': {}", path.display(), err);
},
};

// Print it for good measure
println!("{res:#?}");
println!("{}\n\n", (0..80).map(|_| '-').collect::<String>());
});
}
}





/***** AUXILLARY STRUCTS *****/
/// Defines options that configure the compiler before we use it.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -145,7 +80,7 @@ impl ParserOptions {
///
/// # Errors
/// This function may error if we could not read the reader or if the source code was somehow malformed.
pub fn parse<S: AsRef<str>>(source: S, pindex: &PackageIndex, options: &ParserOptions) -> Result<Program, Error> {
pub fn parse<S: AsRef<str>>(source: S, _pindex: &PackageIndex, options: &ParserOptions) -> Result<Program, Error> {
let source: &str = source.as_ref();

// Run that through the scanner
Expand Down Expand Up @@ -182,21 +117,11 @@ pub fn parse<S: AsRef<str>>(source: S, pindex: &PackageIndex, options: &ParserOp
},
},

Language::Bakery => match bakery::parse_ast(tks, pindex.clone()) {
Ok(ast) => ast,

Err(nom::Err::Error(e)) | Err(nom::Err::Failure(e)) => {
// Match the EOF-error
if e.errors[0].1 == VerboseErrorKind::Nom(nom::error::ErrorKind::Eof) {
return Err(Error::Eof { lang: Language::BraneScript, err: errors::convert_parser_error(tks, e) });
}
return Err(Error::ParseError { lang: Language::Bakery, err: errors::convert_parser_error(tks, e) });
},
Err(err) => {
return Err(Error::ParserError { lang: Language::Bakery, err: format!("{err}") });
},
Language::Bakery => {
todo!("Support for the bakery language was removed as it was not functional anymore, this might be added back later");
},
};

if remain.input_len() > 0 {
return Err(Error::LeftoverTokensError { lang: options.lang });
}
Expand Down
2 changes: 1 addition & 1 deletion brane-dsl/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use std::error::Error;
use std::fmt::{Display, Formatter, Result as FResult};

use nom::error::{VerboseError, VerboseErrorKind};
use nom_language::error::{VerboseError, VerboseErrorKind};

use crate::scanner::{Span, Tokens};
use crate::spec::{Language, TextRange};
Expand Down
Loading
Loading