Spanned
This commit is contained in:
@@ -17,6 +17,9 @@ pub struct Identifier(pub String);
|
||||
#[derive(Debug, Clone, Serialize, Default)]
|
||||
pub struct ParamList(pub Vec<VarDecl>);
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct TypeExpr(pub TypeExprKind, pub Vec<TypePostfix>);
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub enum TypePostfix {
|
||||
Ref,
|
||||
@@ -34,7 +37,11 @@ pub enum TypeExprKind {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct TypeExpr(pub TypeExprKind, pub Vec<TypePostfix>);
|
||||
pub struct Spanned<T> {
|
||||
pub line: usize,
|
||||
pub column: usize,
|
||||
pub item: T,
|
||||
}
|
||||
|
||||
impl TypeExpr {
|
||||
pub fn no_px(kind: TypeExprKind) -> Self {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
pub mod common;
|
||||
pub mod items;
|
||||
|
||||
use crate::Rule;
|
||||
use crate::{Rule, ast::Spanned};
|
||||
|
||||
pub fn listen_rule(pairs: &mut pest::iterators::Pairs<'_, Rule>, rule: Rule) -> bool {
|
||||
let consumed = pairs
|
||||
@@ -27,3 +27,19 @@ pub fn consume_rule<'a>(
|
||||
|
||||
if consumed { pairs.next() } else { None }
|
||||
}
|
||||
|
||||
impl<'a, T: TryFrom<pest::iterators::Pair<'a, Rule>>> TryFrom<pest::iterators::Pair<'a, Rule>>
|
||||
for Spanned<T>
|
||||
{
|
||||
type Error = T::Error;
|
||||
|
||||
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||
let span = pair.as_span().start_pos().line_col();
|
||||
|
||||
Ok(Self {
|
||||
line: span.0,
|
||||
column: span.1,
|
||||
item: pair.try_into()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user