This commit is contained in:
2026-05-18 13:58:59 +02:00
parent de1784f914
commit 5648c1da61
2 changed files with 25 additions and 2 deletions
+8 -1
View File
@@ -17,6 +17,9 @@ pub struct Identifier(pub String);
#[derive(Debug, Clone, Serialize, Default)] #[derive(Debug, Clone, Serialize, Default)]
pub struct ParamList(pub Vec<VarDecl>); pub struct ParamList(pub Vec<VarDecl>);
#[derive(Debug, Clone, Serialize)]
pub struct TypeExpr(pub TypeExprKind, pub Vec<TypePostfix>);
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]
pub enum TypePostfix { pub enum TypePostfix {
Ref, Ref,
@@ -34,7 +37,11 @@ pub enum TypeExprKind {
} }
#[derive(Debug, Clone, Serialize)] #[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 { impl TypeExpr {
pub fn no_px(kind: TypeExprKind) -> Self { pub fn no_px(kind: TypeExprKind) -> Self {
+17 -1
View File
@@ -1,7 +1,7 @@
pub mod common; pub mod common;
pub mod items; pub mod items;
use crate::Rule; use crate::{Rule, ast::Spanned};
pub fn listen_rule(pairs: &mut pest::iterators::Pairs<'_, Rule>, rule: Rule) -> bool { pub fn listen_rule(pairs: &mut pest::iterators::Pairs<'_, Rule>, rule: Rule) -> bool {
let consumed = pairs let consumed = pairs
@@ -27,3 +27,19 @@ pub fn consume_rule<'a>(
if consumed { pairs.next() } else { None } 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()?,
})
}
}