mirror of
https://github.com/Noratrieb/haesli.git
synced 2026-01-16 20:55:03 +01:00
better parser generation
This commit is contained in:
parent
c43126af1f
commit
83778ac2c9
10 changed files with 859 additions and 516 deletions
|
|
@ -1,3 +1,5 @@
|
|||
use crate::classes::generated::Class;
|
||||
use crate::error::{ConException, ProtocolError, TransError};
|
||||
use std::collections::HashMap;
|
||||
|
||||
mod generated;
|
||||
|
|
@ -5,6 +7,7 @@ mod parse_helper;
|
|||
|
||||
pub type Table = HashMap<String, FieldValue>;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum FieldValue {
|
||||
Boolean(bool),
|
||||
ShortShortInt(i8),
|
||||
|
|
@ -25,3 +28,19 @@ pub enum FieldValue {
|
|||
FieldTable(Table),
|
||||
Void,
|
||||
}
|
||||
|
||||
pub use generated::*;
|
||||
|
||||
/// Parses the payload of a method frame into the class/method
|
||||
pub fn parse_method(payload: &[u8]) -> Result<Class, TransError> {
|
||||
let nom_result = generated::parse::parse_method(payload);
|
||||
|
||||
match nom_result {
|
||||
Ok(([], class)) => Ok(class),
|
||||
Ok((_, _)) => Err(ProtocolError::ConException(ConException::SyntaxError).into()),
|
||||
Err(nom::Err::Incomplete(_)) => {
|
||||
Err(ProtocolError::ConException(ConException::SyntaxError).into())
|
||||
}
|
||||
Err(nom::Err::Failure(err) | nom::Err::Error(err)) => Err(err),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue