Skip to content
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 Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "noa-parser"
version = "0.3.0"
version = "0.4.0"
edition = "2024"
homepage = "https://github.com/Akanoa/noa-parser"
repository = "https://github.com/Akanoa/noa-parser"
Expand Down
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

**0.4.0**

- Add support to carriage return and tab recognizer

**0.3.0**

- Add support to delimited group
Expand Down
4 changes: 3 additions & 1 deletion examples/delimited_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use noa_parser::peek::peek;
fn main() {
let data = b"(2 * 3)";
let mut scanner = noa_parser::scanner::Scanner::new(data);
let result = peek(GroupKind::Parenthesis, &mut scanner).expect("failed to parse").expect("failed to peek");
let result = peek(GroupKind::Parenthesis, &mut scanner)
.expect("failed to parse")
.expect("failed to peek");
println!(
"{}",
String::from_utf8_lossy(result.peeked_slice()) // 2 * 3
Expand Down
4 changes: 2 additions & 2 deletions src/bytes/components/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ impl<'a> Peekable<'a, u8, Token, Token> for GroupKind {

#[cfg(test)]
mod tests {
use crate::bytes::components::groups::{match_for_delimited_group, match_group, GroupKind};
use crate::bytes::components::groups::{GroupKind, match_for_delimited_group, match_group};
use crate::bytes::token::Token;
use crate::peek::{peek, PeekResult, Peeking};
use crate::peek::{PeekResult, Peeking, peek};
use crate::scanner::Scanner;

#[test]
Expand Down
18 changes: 17 additions & 1 deletion src/bytes/token.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Classic tokens

use crate::bytes::matchers::match_char;
use crate::bytes::matchers::{match_char, match_pattern};
use crate::matcher::{Match, MatchSize};

#[derive(Copy, Clone)]
Expand Down Expand Up @@ -65,6 +65,14 @@ pub enum Token {
Underscore,
/// The `#` character
Sharp,
/// The `\n` character
Ln,
/// The `\r` character
Cr,
/// The `\t` character
Tab,
/// The `\r\n` character
CrLn,
}

impl Match<u8> for Token {
Expand Down Expand Up @@ -99,6 +107,10 @@ impl Match<u8> for Token {
Token::Backslash => match_char('\\', data),
Token::Underscore => match_char('_', data),
Token::Sharp => match_char('#', data),
Token::Ln => match_char('\n', data),
Token::Cr => match_char('\r', data),
Token::Tab => match_char('\t', data),
Token::CrLn => match_pattern(b"\r\n", data),
}
}
}
Expand Down Expand Up @@ -135,6 +147,10 @@ impl MatchSize for Token {
Token::Backslash => 1,
Token::Underscore => 1,
Token::Sharp => 1,
Token::Ln => 1,
Token::Cr => 1,
Token::Tab => 1,
Token::CrLn => 2,
}
}
}
2 changes: 1 addition & 1 deletion src/peek.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use crate::errors::ParseResult;
use crate::matcher::MatchSize;
use crate::recognizer::{recognize, Recognizable};
use crate::recognizer::{Recognizable, recognize};
use crate::scanner::Scanner;
use std::marker::PhantomData;

Expand Down