Skip to content

Commit

Permalink
fix [r], add normal debug impls for IR
Browse files Browse the repository at this point in the history
  • Loading branch information
Aloso committed May 17, 2024
1 parent 2be185d commit 3d2c356
Show file tree
Hide file tree
Showing 19 changed files with 36 additions and 35 deletions.
2 changes: 1 addition & 1 deletion pomsky-lib/src/exprs/char_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl<'i> RuleExt<'i> for CharClass {
options: CompileOptions,
state: &mut CompileState<'_, 'i>,
) -> CompileResult<'i> {
if self.inner.len() == 1 {
if self.inner.len() == 1 && !matches!(&&*self.inner, [GroupItem::Char('\r')]) {
let first = self.inner.first().unwrap();
if let &GroupItem::Char(c) = first {
return Ok(Regex::Literal(c.to_string().into()));
Expand Down
1 change: 1 addition & 0 deletions pomsky-lib/src/exprs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub(crate) trait RuleExt<'i> {

/// A parsed pomsky expression, which might contain more sub-expressions.
#[derive(Clone)]
#[cfg_attr(not(feature = "dbg"), derive(Debug))]
pub struct Expr<'i>(Rule<'i>);

impl<'i> Expr<'i> {
Expand Down
4 changes: 4 additions & 0 deletions pomsky-lib/tests/testcases/basics/explicit_crlf.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#! flavor=pcre
[r][n]
-----
\r\n
2 changes: 1 addition & 1 deletion pomsky-syntax/src/exprs/alternation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::{Literal, Rule};
/// that alternative is a [`Rule::Group`]. Note that a group's parentheses are
/// removed when compiling to a regex if they aren't required. In other words,
/// `'a' | ('b' 'c')` compiles to `a|bc`.
#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct Alternation<'i> {
pub rules: Vec<Rule<'i>>,
pub(crate) span: Span,
Expand Down
5 changes: 2 additions & 3 deletions pomsky-syntax/src/exprs/boundary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::Span;
///
/// All boundaries use a variation of the `%` sigil, so they are easy to
/// remember.
#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Boundary {
pub kind: BoundaryKind,
pub span: Span,
Expand Down Expand Up @@ -38,8 +38,7 @@ impl Boundary {
}
}

#[derive(Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "dbg", derive(Debug))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BoundaryKind {
/// `Start`, the start of the string (or start of line in single-line mode)
Start,
Expand Down
4 changes: 2 additions & 2 deletions pomsky-syntax/src/exprs/char_class/char_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl CharGroup {
}

/// One item in a character class.
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum GroupItem {
/// A Unicode code point. It can be denoted in quotes (e.g. `'a'`) or in
/// hexadecimal notation (`U+201`).
Expand Down Expand Up @@ -125,7 +125,7 @@ impl GroupItem {
}
}

#[derive(Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum GroupName {
Word,
Digit,
Expand Down
2 changes: 1 addition & 1 deletion pomsky-syntax/src/exprs/char_class/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub use unicode::{blocks_supported_in_dotnet, list_shorthands};

/// A _character class_. Refer to the [module-level documentation](self) for
/// details.
#[derive(Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CharClass {
pub inner: Vec<GroupItem>,
pub span: Span,
Expand Down
6 changes: 3 additions & 3 deletions pomsky-syntax/src/exprs/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::Rule;
///
/// If it is capturing, it must be wrapped in parentheses, and can have a name.
/// If it is non-capturing, the parentheses can be omitted in same cases.
#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct Group<'i> {
pub parts: Vec<Rule<'i>>,
pub kind: GroupKind<'i>,
Expand Down Expand Up @@ -69,7 +69,7 @@ impl<'i> Group<'i> {
}
}

#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GroupKind<'i> {
/// A (possibly named) capturing group e.g. `:foo`
Capturing(Capture<'i>),
Expand All @@ -87,7 +87,7 @@ impl GroupKind<'_> {
}
}

#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Capture<'i> {
pub name: Option<&'i str>,
}
Expand Down
5 changes: 2 additions & 3 deletions pomsky-syntax/src/exprs/lookaround.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ use crate::Span;

use super::Rule;

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct Lookaround<'i> {
pub kind: LookaroundKind,
pub rule: Rule<'i>,
pub span: Span,
}

#[derive(Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "dbg", derive(Debug))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LookaroundKind {
Ahead,
Behind,
Expand Down
2 changes: 1 addition & 1 deletion pomsky-syntax/src/exprs/negation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::Span;

use super::Rule;

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct Negation<'i> {
pub rule: Rule<'i>,
pub not_span: Span,
Expand Down
2 changes: 1 addition & 1 deletion pomsky-syntax/src/exprs/range.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::Span;

#[derive(Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Range {
pub start: Vec<u8>,
pub end: Vec<u8>,
Expand Down
2 changes: 1 addition & 1 deletion pomsky-syntax/src/exprs/recursion.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::Span;

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct Recursion {
pub span: Span,
}
4 changes: 2 additions & 2 deletions pomsky-syntax/src/exprs/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

use crate::Span;

#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Reference<'i> {
pub target: ReferenceTarget<'i>,
pub span: Span,
}

#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ReferenceTarget<'i> {
Named(&'i str),
Number(u32),
Expand Down
2 changes: 1 addition & 1 deletion pomsky-syntax/src/exprs/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::borrow::Cow;

use crate::Span;

#[derive(Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Regex<'i> {
pub content: Cow<'i, str>,
pub span: Span,
Expand Down
8 changes: 3 additions & 5 deletions pomsky-syntax/src/exprs/repetition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{error::RepetitionError, Span};

use super::Rule;

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct Repetition<'i> {
pub rule: Rule<'i>,
pub kind: RepetitionKind,
Expand Down Expand Up @@ -53,8 +53,7 @@ impl<'i> Repetition<'i> {
}
}

#[derive(Clone, PartialEq, Eq, Copy)]
#[cfg_attr(feature = "dbg", derive(Debug))]
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
pub enum Quantifier {
Greedy,
Lazy,
Expand All @@ -68,8 +67,7 @@ pub enum Quantifier {
/// * `'x'?` is equivalent to `'x'{0,1}`
/// * `'x'+` is equivalent to `'x'{1,}`
/// * `'x'*` is equivalent to `'x'{0,}`
#[derive(Clone, Copy, PartialEq, Eq, Default)]
#[cfg_attr(feature = "dbg", derive(Debug))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct RepetitionKind {
/// The lower bound, e.g. `{4,}`
pub lower_bound: u32,
Expand Down
2 changes: 1 addition & 1 deletion pomsky-syntax/src/exprs/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::{
};

/// A parsed pomsky expression, which might contain more sub-expressions.
#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum Rule<'i> {
/// A string literal
Literal(Literal<'i>),
Expand Down
8 changes: 4 additions & 4 deletions pomsky-syntax/src/exprs/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ use crate::Span;

use super::{test::Test, Rule};

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct StmtExpr<'i> {
pub stmt: Stmt<'i>,
pub rule: Rule<'i>,
pub span: Span,
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum Stmt<'i> {
Enable(BooleanSetting, Span),
Disable(BooleanSetting, Span),
Let(Let<'i>),
Test(Test<'i>),
}

#[derive(Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BooleanSetting {
Lazy,
Unicode,
Expand All @@ -33,7 +33,7 @@ impl BooleanSetting {
}
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct Let<'i> {
pub name: &'i str,
pub rule: Rule<'i>,
Expand Down
8 changes: 4 additions & 4 deletions pomsky-syntax/src/exprs/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use crate::Span;

use super::Literal;

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct Test<'i> {
pub cases: Vec<TestCase<'i>>,
pub span: Span,
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum TestCase<'i> {
Match(TestCaseMatch<'i>),
MatchAll(TestCaseMatchAll<'i>),
Expand All @@ -22,13 +22,13 @@ pub struct TestCaseMatch<'i> {
pub span: Span,
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct TestCaseMatchAll<'i> {
pub literal: Literal<'i>,
pub matches: Vec<TestCaseMatch<'i>>,
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct TestCaseReject<'i> {
pub literal: Literal<'i>,
pub as_substring: bool,
Expand Down
2 changes: 1 addition & 1 deletion pomsky-syntax/src/exprs/var.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::Span;

#[derive(Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Variable<'i> {
pub name: &'i str,
pub span: Span,
Expand Down

0 comments on commit 3d2c356

Please sign in to comment.