Skip to content

Commit

Permalink
Add new token types and make some lexer fns pub
Browse files Browse the repository at this point in the history
  • Loading branch information
vcfxb committed Mar 13, 2024
1 parent 3ce43b9 commit b515609
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
15 changes: 7 additions & 8 deletions wright/src/parser/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ impl<'src> Lexer<'src> {
}

/// "Fork" this lexer, creating a new [`Lexer`] at the same position as this one that can be used for
/// failable parsing. This can be compared to the original lexer it was forked from using [Lexer::offset_from]
/// on the underlying `remaining` fragments.
fn fork(&self) -> Self {
/// failable parsing. This can be compared to the original lexer it was forked from using [Lexer::offset_from].
pub fn fork(&self) -> Self {
*self
}

Expand All @@ -82,12 +81,12 @@ impl<'src> Lexer<'src> {
/// - Generally the best way to avoid panics is to only call this function on
/// [Lexer]s created using [Lexer::fork] on the `origin` lexer.
#[inline]
fn offset_from(&self, origin: &Self) -> usize {
pub fn offset_from(&self, origin: &Self) -> usize {
self.remaining.offset_from(&origin.remaining)
}

/// Remove and ignore any whitespace at the start of the remaining fragment.
fn ignore_whitespace(&mut self) {
/// Remove and ignore any whitespace at the start of the [Lexer::remaining] [Fragment].
pub fn ignore_whitespace(&mut self) {
// Get a reference to the slice of the string past any whitespace at the start.
let without_whitespace: &str = self.remaining.inner.trim_start();

Expand All @@ -97,8 +96,8 @@ impl<'src> Lexer<'src> {
}
}

/// Check if a pattern matches at the start of the remaining fragment, and if so return the number of bytes.
fn matches(&self, pattern: &str) -> bool {
/// Check if a pattern matches at the start of the [Lexer::remaining] [Fragment].
pub fn matches(&self, pattern: &str) -> bool {
self.remaining.inner.starts_with(pattern)
}

Expand Down
7 changes: 5 additions & 2 deletions wright/src/parser/lexer/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ pub enum TokenTy {
InnerDocComment, InnerBlockDocComment,

/// Indicates a block style comment without termination.
/// Separate from [TokenTy::InnerDocComment] and [TokenTy::OuterDocComment] to indicate that
/// unterminated comments will be handled differently (produce errors eventually).
UnterminatedBlockComment,

KwRecord,
Expand Down Expand Up @@ -82,8 +84,9 @@ pub enum TokenTy {
KwWhere,

IntegerLiteral,
StringLiteral,
CharLiteral,
StringLiteral { terminated: bool },
FormatStringLiteral { terminated: bool },
CharLiteral { terminated: bool },

/// Unknown character in lexer fragment.
Unknown
Expand Down

0 comments on commit b515609

Please sign in to comment.