Skip to content

Commit

Permalink
Add ##method() syntax to call a method on the input object
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmehall committed Dec 3, 2018
1 parent c58d620 commit 1f3418c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion peg-codegen/grammar.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions peg-codegen/grammar.rustpeg
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ primary -> Spanned<Expr>
/ class
/ "." { AnyCharExpr }
/ "@" { MarkerExpr }
/ "##" _ method:identifier _ "(" args:$((!")" .)*) ")" { MethodExpr(method, args.to_owned()) }
/ "#position" { PositionExpr }
/ "#quiet" _ "<" _ e:expression _ ">" { QuietExpr(Box::new(e)) }
/ "#expected" _ "(" _ s:doubleQuotedString _ ")" { FailExpr(s) }
Expand Down
7 changes: 7 additions & 0 deletions peg-codegen/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ pub enum Expr {
LiteralExpr(String),
PatternExpr(String),
RuleExpr(String),
MethodExpr(String, String),
SequenceExpr(Vec<Spanned<Expr>>),
ChoiceExpr(Vec<Spanned<Expr>>),
OptionalExpr(Box<Spanned<Expr>>),
Expand Down Expand Up @@ -598,6 +599,12 @@ fn compile_expr(compiler: &mut PegCompiler, cx: Context, e: &Spanned<Expr>) -> T
}
}

MethodExpr(ref method, ref args) => {
let method = raw(method);
let args = raw(args);
quote!{ __input.#method(__pos, #args) }
}

TemplateInvoke(ref name, ref params) => {
let template = match cx.grammar.templates.get(&name[..]) {
Some(x) => x,
Expand Down

0 comments on commit 1f3418c

Please sign in to comment.