-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Statically computes text value kind lookup table
- Loading branch information
Showing
3 changed files
with
90 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ pub mod encoded_value; | |
pub mod matched; | ||
pub mod parse_result; | ||
pub mod raw; | ||
mod token_kind; | ||
pub mod value; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#[derive(Debug, Clone, Copy)] | ||
pub enum ValueTokenKind { | ||
// An ASCII decimal digit, 0-9 inclusive, as well as `-` and `+` | ||
// Could be the start of an int, float, decimal, or timestamp. | ||
NumberOrTimestamp, | ||
// An ASCII letter, [a-zA-Z] inclusive. | ||
// Could be the start of a null, bool, identifier, or float (`nan`). | ||
Letter, | ||
// A `$` or `_`, which could be either a symbol ID (`$10`) | ||
// or an identifier (`$foo`, `_`). | ||
Symbol, | ||
// A `"` or `'`, which could be either a string or symbol. | ||
QuotedText, | ||
// `[` | ||
List, | ||
// `(` | ||
SExp, | ||
// `{` | ||
LobOrStruct, | ||
// Any other byte | ||
Invalid(u8), | ||
} | ||
|
||
/// A table of `ValueTokenKind` instances that can be queried by using the | ||
/// byte in question as an index. | ||
pub(crate) static TEXT_ION_TOKEN_KINDS: &[ValueTokenKind] = &init_value_token_cache(); | ||
|
||
pub(crate) const fn init_value_token_cache() -> [ValueTokenKind; 256] { | ||
let mut jump_table = [ValueTokenKind::Invalid(0); 256]; | ||
let mut index: usize = 0; | ||
while index < 256 { | ||
let byte = index as u8; | ||
jump_table[index] = match byte { | ||
b'0'..=b'9' | b'-' | b'+' => ValueTokenKind::NumberOrTimestamp, | ||
b'a'..=b'z' | b'A'..=b'Z' => ValueTokenKind::Letter, | ||
b'$' | b'_' => ValueTokenKind::Symbol, | ||
b'"' | b'\'' => ValueTokenKind::QuotedText, | ||
b'[' => ValueTokenKind::List, | ||
b'(' => ValueTokenKind::SExp, | ||
b'{' => ValueTokenKind::LobOrStruct, | ||
other_byte => ValueTokenKind::Invalid(other_byte), | ||
}; | ||
index += 1; | ||
} | ||
jump_table | ||
} |