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

Const it up #144

Merged
merged 1 commit into from
Jan 1, 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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ complexity = "deny"
perf = "deny"
must_use_candidate = "deny"
doc_markdown = "deny"
missing_const_for_fn = "deny"

[dependencies]
tracing = { version = "0.1.37", optional = true }
Expand Down
8 changes: 4 additions & 4 deletions src/earley/input_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub(crate) struct InputRangeOffset {
}

impl InputRangeOffset {
pub fn total_len(&self) -> usize {
pub const fn total_len(&self) -> usize {
self.start + self.len
}
}
Expand All @@ -18,7 +18,7 @@ pub(crate) struct InputRange<'gram> {
}

impl<'gram> InputRange<'gram> {
pub fn new(input: &'gram str) -> Self {
pub const fn new(input: &'gram str) -> Self {
Self {
input,
offset: InputRangeOffset { start: 0, len: 0 },
Expand All @@ -28,7 +28,7 @@ impl<'gram> InputRange<'gram> {
let next_idx = self.offset.start + self.offset.len;
&self.input[next_idx..]
}
pub fn after(&self) -> Self {
pub const fn after(&self) -> Self {
Self {
input: self.input,
offset: InputRangeOffset {
Expand All @@ -46,7 +46,7 @@ impl<'gram> InputRange<'gram> {
offset: InputRangeOffset { start, len },
}
}
pub fn is_complete(&self) -> bool {
pub const fn is_complete(&self) -> bool {
self.offset.start == 0 && self.offset.len == self.input.len()
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/earley/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ pub(crate) struct CompletionKey<'gram> {
}

impl<'gram> CompletionKey<'gram> {
pub fn new_start(term: &'gram Term, input: &InputRange<'gram>) -> Self {
pub const fn new_start(term: &'gram Term, input: &InputRange<'gram>) -> Self {
Self {
term,
input_start: input.offset.start,
}
}
pub fn new_total(term: &'gram Term, input: &InputRange<'gram>) -> Self {
pub const fn new_total(term: &'gram Term, input: &InputRange<'gram>) -> Self {
Self {
term,
input_start: input.offset.total_len(),
Expand Down
2 changes: 1 addition & 1 deletion src/earley/traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub(crate) struct Traversal<'gram> {
}

impl<'gram> Traversal<'gram> {
pub fn next_unmatched(&self) -> Option<&'gram Term> {
pub const fn next_unmatched(&self) -> Option<&'gram Term> {
self.unmatched.first()
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ pub struct Expression {
impl Expression {
/// Construct a new `Expression`
#[must_use]
pub fn new() -> Expression {
pub const fn new() -> Expression {
Expression { terms: vec![] }
}

/// Construct an `Expression` from `Term`s
#[must_use]
pub fn from_parts(v: Vec<Term>) -> Expression {
pub const fn from_parts(v: Vec<Term>) -> Expression {
Expression { terms: v }
}

Expand Down
6 changes: 3 additions & 3 deletions src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl<'gram> ParseTree<'gram> {
/// println!("parse tree mermaid: {}", mermaid);
/// ```
#[must_use]
pub fn mermaid(&self) -> MermaidParseTree<'_> {
pub const fn mermaid(&self) -> MermaidParseTree<'_> {
MermaidParseTree { parse_tree: self }
}

Expand Down Expand Up @@ -212,15 +212,15 @@ pub struct Grammar {
impl Grammar {
/// Construct a new `Grammar`
#[must_use]
pub fn new() -> Grammar {
pub const fn new() -> Grammar {
Grammar {
productions: vec![],
}
}

/// Construct an `Grammar` from `Production`s
#[must_use]
pub fn from_parts(v: Vec<Production>) -> Grammar {
pub const fn from_parts(v: Vec<Production>) -> Grammar {
Grammar { productions: v }
}

Expand Down
Loading