mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-07 04:06:48 +01:00
dsl: extract dsl_error; ParseError -> DslError
This commit is contained in:
parent
f18e01c220
commit
ed772b9872
4 changed files with 34 additions and 21 deletions
|
|
@ -1,20 +1,5 @@
|
|||
use crate::*;
|
||||
|
||||
pub type ParseResult<T> = Result<T, ParseError>;
|
||||
|
||||
#[derive(Error, Debug, Copy, Clone, PartialEq)] pub enum ParseError {
|
||||
#[error("parse failed: not implemented")]
|
||||
Unimplemented,
|
||||
#[error("parse failed: empty")]
|
||||
Empty,
|
||||
#[error("parse failed: incomplete")]
|
||||
Incomplete,
|
||||
#[error("parse failed: unexpected character '{0}'")]
|
||||
Unexpected(char),
|
||||
#[error("parse failed: error #{0}")]
|
||||
Code(u8),
|
||||
}
|
||||
|
||||
/// Implement the const iterator pattern.
|
||||
#[macro_export] macro_rules! const_iter {
|
||||
($(<$l:lifetime>)?|$self:ident: $Struct:ty| => $Item:ty => $expr:expr) => {
|
||||
|
|
@ -170,7 +155,7 @@ pub const fn peek_src <'a> (source: &'a str) -> Option<Token<'a>> {
|
|||
}
|
||||
}
|
||||
|
||||
pub const fn to_number (digits: &str) -> Result<usize, ParseError> {
|
||||
pub const fn to_number (digits: &str) -> DslResult<usize> {
|
||||
let mut value = 0;
|
||||
iterate!(char_indices(digits) => (_, c) => match to_digit(c) {
|
||||
Ok(digit) => value = 10 * value + digit,
|
||||
|
|
@ -179,7 +164,7 @@ pub const fn to_number (digits: &str) -> Result<usize, ParseError> {
|
|||
Ok(value)
|
||||
}
|
||||
|
||||
pub const fn to_digit (c: char) -> Result<usize, ParseError> {
|
||||
pub const fn to_digit (c: char) -> DslResult<usize> {
|
||||
Ok(match c {
|
||||
'0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4,
|
||||
'5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9,
|
||||
|
|
@ -196,7 +181,7 @@ pub const fn to_digit (c: char) -> Result<usize, ParseError> {
|
|||
|
||||
#[derive(Debug, Copy, Clone, Default, PartialEq)] pub enum Value<'source> {
|
||||
#[default] Nil,
|
||||
Err(ParseError),
|
||||
Err(DslError),
|
||||
Num(usize),
|
||||
Sym(&'source str),
|
||||
Key(&'source str),
|
||||
|
|
@ -228,7 +213,7 @@ impl<'source> Token<'source> {
|
|||
pub const fn value (&self) -> Value {
|
||||
self.value
|
||||
}
|
||||
pub const fn error (self, error: ParseError) -> Self {
|
||||
pub const fn error (self, error: DslError) -> Self {
|
||||
Self { value: Value::Err(error), ..self }
|
||||
}
|
||||
pub const fn grow (self) -> Self {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue