Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed issue 109: In memory grammar #110

Merged
merged 1 commit into from
Jul 31, 2024
Merged
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
2 changes: 1 addition & 1 deletion sdk-rust/src/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ pub fn build_in_memory_grammar<'a>(
return Err(vec![error]);
}
let mut parser_automaton = Vec::new();
if let Err(error) = if data.method.is_rnglr() {
if let Err(error) = if !data.method.is_rnglr() {
parser_data::write_parser_lrk_data(
&mut parser_automaton,
grammar,
Expand Down
2 changes: 1 addition & 1 deletion sdk-rust/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl<'s> InMemoryParser<'s> {
repository: TokenRepository<'s, 't, 'a>,
errors: &'a mut ParseErrors<'s>,
) -> Lexer<'s, 't, 'a> {
if self.lexer_is_context_sensitive {
if !self.lexer_is_context_sensitive {
Lexer::ContextFree(ContextFreeLexer::new(
repository,
errors,
Expand Down
44 changes: 43 additions & 1 deletion sdk-rust/tests/regressions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use hime_sdk::output::helper::{get_namespace_java, get_namespace_net, get_namespace_rust};
use std::borrow::BorrowMut;

use hime_sdk::{output::helper::{get_namespace_java, get_namespace_net, get_namespace_rust}, ParsingMethod};

/// [Github issue #79](https://github.com/cenotelie/hime/issues/79)
#[test]
Expand All @@ -10,3 +12,43 @@ fn test_namespace_transformation() {
assert_eq!(get_namespace_rust("a.b.c"), String::from("a::b::c"));
assert_eq!(get_namespace_rust("a::b::c"), String::from("a::b::c"));
}

/// [Github issue #109](https://github.com/cenotelie/hime/issues/109)
#[test]
pub fn test_in_memory_parser(){
let text_grammar = r#"
grammar Test
{
options
{
Axiom = "expression";
}
terminals
{
A -> 'a'+;
}
rules
{
expression -> A ;
}
}
"#;

let input = hime_sdk::Input::Raw(&text_grammar);
let inputs = vec![input];
if let Ok(l) = hime_sdk::loaders::load_inputs(&inputs) {
// The load_inputs allows to load multiple inputs and turn them into grammars,
// but in our case, we only have one input grammar
let mut grammars = l.grammars;
let input_grammar = grammars[0].borrow_mut();
if let Ok(data) = input_grammar.build(Some(ParsingMethod::LR1), 0) {
if let Ok(parser) = hime_sdk::output::build_in_memory_grammar(input_grammar, &data) {
let res_1 = parser.parse("aaa");
assert!(res_1.is_success());
let res_2 = parser.parse("aaab");
assert!(!res_2.is_success());
}
}
}

}
Loading