-
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.
Add a fake io reader to test lexing #56
- Loading branch information
Showing
5 changed files
with
49 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use mango::io::typ::Reader; | ||
use regex::Regex; | ||
|
||
/// 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 equals(&mut self, text: &str) -> bool { | ||
if &self.code[self.index..self.index + text.len()] == text { | ||
self.index += text.len(); | ||
return true; | ||
} | ||
false | ||
} | ||
|
||
fn matches(&mut self, pattern: Regex) -> Option<String> { | ||
unimplemented!() // TODO | ||
} | ||
} |
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,2 @@ | ||
pub mod fromstr; | ||
pub use self::fromstr::*; |
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,3 @@ | ||
pub mod typ; | ||
|
||
pub mod fortest; |
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,14 @@ | ||
use regex::Regex; | ||
|
||
/// A reader represents a source 'file', which may be a file, webpage, string, ... | ||
pub trait Reader { | ||
/// Checks whether the `text` is found starting from the current position. | ||
fn equals(&mut self, text: &str) -> bool; | ||
|
||
/// Checks whether the code from the current position matches a regex pattern. | ||
fn matches(&mut self, pattern: Regex) -> Option<String>; | ||
} | ||
|
||
pub trait Writer { | ||
// TODO | ||
} |