Skip to content

Commit

Permalink
feat(parser): Updated the parser to have optional features
Browse files Browse the repository at this point in the history
Updated the parser to have optional features to enable/disable different parsers. MOOS applications likely only need to have the MOOS parser so the behavior and plug parsers are disabled by default.

BREAKING CHANGE:
  • Loading branch information
cgagner committed Oct 12, 2024
1 parent ac6de36 commit 0bcba2f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
13 changes: 8 additions & 5 deletions moos-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@ edition = "2021"
build = "build.rs"

[features]
default = []
default = ["moos-parser"]
all-parsers = ["behavior-parser", "moos-parser", "plug-parser"]
behavior-parser = []
lsp-types = ["dep:lsp-types"]
moos-parser = []
plug-parser = []
threadsafe-tree = []

[dependencies]
regex = "1"
lalrpop-util = {version = "0.19.12", features = ["lexer"]}
lalrpop-util = { version = "0.19.12", features = ["lexer"] }
log = "0.4"
tracing = "0.1.40"
lsp-types = {version = "0.95.1", optional = true}
lsp-types = { version = "0.95.1", optional = true }


[dev-dependencies]
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
anyhow = "1.0.81"

[build-dependencies]
lalrpop = {version = "0.19.12", features = ["lexer"]}

lalrpop = { version = "0.19.12", features = ["lexer"] }
12 changes: 11 additions & 1 deletion moos-parser/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
pub mod ast;
// pub mod ast;
pub mod base;
#[cfg(feature = "behavior-parser")]
pub mod behavior;
pub mod helpers;
pub mod lexers;
#[cfg(feature = "moos-parser")]
pub mod moos;
#[cfg(feature = "plug-parser")]
pub mod nsplug;

/// Type of Str used in parse trees. This type needs to own the str
Expand All @@ -20,21 +23,27 @@ pub type TreeStr = Box<str>;
#[cfg(feature = "threadsafe-tree")]
pub type TreeStr = std::sync::Arc<str>;

#[cfg(feature = "moos-parser")]
#[allow(clippy::all, dead_code, unused_imports, unused_mut)]
pub type MoosParser = moos::moos::LinesParser;

#[cfg(feature = "moos-parser")]
#[allow(clippy::all, dead_code, unused_imports, unused_mut)]
pub type MoosLexer<'input> = moos::lexer::Lexer<'input>;

#[cfg(feature = "plug-parser")]
#[allow(clippy::all, dead_code, unused_imports, unused_mut)]
pub type PlugLexer<'input> = nsplug::lexer::Lexer<'input>;

#[cfg(feature = "plug-parser")]
#[allow(clippy::all, dead_code, unused_imports, unused_mut)]
pub type PlugParser = nsplug::nsplug::LinesParser;

#[cfg(feature = "behavior-parser")]
#[allow(clippy::all, dead_code, unused_imports, unused_mut)]
pub type BehaviorParser = behavior::behavior::LinesParser;

#[cfg(feature = "behavior-parser")]
#[allow(clippy::all, dead_code, unused_imports, unused_mut)]
pub type BehaviorLexer<'input> = behavior::lexer::Lexer<'input>;

Expand Down Expand Up @@ -96,6 +105,7 @@ pub trait TextFormatter {
}

#[cfg(test)]
#[cfg(feature = "plug-parser")]
mod tests {

use crate::{PlugLexer, PlugParser};
Expand Down
2 changes: 1 addition & 1 deletion moos-parser/src/nsplug/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::lexers::TokenRange;
use crate::vec_wrapper;
use crate::TreeStr;
#[cfg(feature = "lsp-types")]
use crate::{create_text_edit, TextFormatter};
use crate::{create_text_edit, FormatOptions, TextFormatter};

pub const DEFINE_STR: &str = "#define";
pub const INCLUDE_STR: &str = "#include";
Expand Down

0 comments on commit 0bcba2f

Please sign in to comment.