Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions peg-macros/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ impl Grammar {
pub enum Item {
Use(TokenStream),
Rule(Rule),
StackLimit(TokenStream),
}

#[derive(Debug)]
pub enum Cache {
Simple,
Recursive
Recursive,
}

#[derive(Debug)]
Expand Down Expand Up @@ -77,7 +78,11 @@ pub enum Expr {
MethodExpr(Ident, TokenStream),
ChoiceExpr(Vec<SpannedExpr>),
OptionalExpr(Box<SpannedExpr>),
Repeat { inner: Box<SpannedExpr>, bound: BoundedRepeat, sep: Option<Box<SpannedExpr>> },
Repeat {
inner: Box<SpannedExpr>,
bound: BoundedRepeat,
sep: Option<Box<SpannedExpr>>,
},
PosAssertExpr(Box<SpannedExpr>),
NegAssertExpr(Box<SpannedExpr>),
ActionExpr(Vec<TaggedExpr>, Option<Group>),
Expand All @@ -93,7 +98,10 @@ pub enum Expr {

impl Expr {
pub fn at(self, sp: Span) -> SpannedExpr {
SpannedExpr { expr: self, span:sp }
SpannedExpr {
expr: self,
span: sp,
}
}
}

Expand Down Expand Up @@ -127,14 +135,14 @@ impl BoundedRepeat {
pub fn has_lower_bound(&self) -> bool {
match self {
BoundedRepeat::None | BoundedRepeat::Both(None, _) => false,
BoundedRepeat::Plus | BoundedRepeat::Exact(_) | BoundedRepeat::Both(Some(_), _) => true
BoundedRepeat::Plus | BoundedRepeat::Exact(_) | BoundedRepeat::Both(Some(_), _) => true,
}
}

pub fn has_upper_bound(&self) -> bool {
match self {
BoundedRepeat::None | BoundedRepeat::Plus | BoundedRepeat::Both(_, None) => false,
BoundedRepeat::Exact(_) | BoundedRepeat::Both(_, Some(_)) => true
BoundedRepeat::None | BoundedRepeat::Plus | BoundedRepeat::Both(_, None) => false,
BoundedRepeat::Exact(_) | BoundedRepeat::Both(_, Some(_)) => true,
}
}
}
Loading