forked from pest-parser/pest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request pest-parser#55 from steffengy/example
Implement support for references within StringInput
- Loading branch information
Showing
5 changed files
with
59 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// pest. Elegant, efficient grammars | ||
// Copyright (C) 2016 Dragoș Tiselice | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#[macro_use] | ||
extern crate pest; | ||
|
||
use std::collections::LinkedList; | ||
|
||
use pest::prelude::*; | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub enum Node<'a> { | ||
Sentence(&'a str), | ||
} | ||
|
||
impl_rdp! { | ||
grammar! { | ||
word = { letter* } | ||
letter = { ['a'..'z'] } | ||
} | ||
|
||
process! { | ||
main(&self) -> Node<'n> { | ||
(&w: word) => Node::Sentence(w) | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn word() { | ||
let file = "abc def"; | ||
let result = { | ||
let mut parser = Rdp::new(StringInput::new(&file)); | ||
|
||
assert!(parser.word()); | ||
parser.process() | ||
}; | ||
assert_eq!(result, Node::Sentence("abc")); | ||
} |