-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
66 additions
and
68 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
pub mod fromstr; | ||
pub use self::fromstr::*; | ||
pub mod stringreader; | ||
pub use self::stringreader::*; |
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,49 @@ | ||
use mango::io::typ::Reader; | ||
use mango::io::typ::ReaderResult; | ||
use mango::io::util::REXCACHE; | ||
|
||
/// Implementation of [Reader] that reads from a pre-provided string. | ||
/// Mostly for testing purposes. | ||
pub struct StringReader { | ||
code: String, | ||
index: usize, | ||
} | ||
|
||
impl StringReader { | ||
pub fn new(code: String) -> Self { | ||
StringReader { code, index: 0 } | ||
} | ||
} | ||
|
||
impl Reader for StringReader { | ||
fn matches(&mut self, subpattern: &str) -> ReaderResult { | ||
// Check for subpattern | ||
REXCACHE.with(|rl| { | ||
let mut rexlib = rl.borrow_mut(); | ||
{ | ||
// Check for end of file | ||
// TODO: is there a better/faster way for this? maybe try this after a match and set a flag? | ||
let regex = rexlib.make_or_get(r"\s*"); | ||
match regex.find(&self.code[self.index..]) { | ||
Some(mtch) => { | ||
self.index += mtch.as_str().len(); | ||
return ReaderResult::EOF(); | ||
} | ||
None => (), | ||
} | ||
} | ||
{ | ||
// Check for subpattern | ||
let regex = rexlib.make_or_get(subpattern); | ||
return match regex.find(&self.code[self.index..]) { | ||
Some(mtch) => { | ||
self.index += mtch.as_str().len(); | ||
println!(">>> {}", mtch.as_str()); | ||
ReaderResult::Match(mtch.as_str().to_owned()) | ||
} | ||
None => ReaderResult::NoMatch(), | ||
}; | ||
} | ||
}) | ||
} | ||
} |
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