-
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.
Lexer infrastructure for testing #52
- Loading branch information
Showing
7 changed files
with
72 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ pub mod code_lexer; | |
pub mod comment_lexer; | ||
|
||
pub mod string_lexer; | ||
|
||
pub mod util; |
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,34 @@ | ||
use mango::io::typ::Reader; | ||
use mango::lexing::code_lexer::CodeLexer; | ||
use mango::lexing::typ::Lexer; | ||
use mango::lexing::typ::MaybeToken; | ||
use mango::token::Token; | ||
use mango::token::Tokens; | ||
use std::cell::RefCell; | ||
use std::rc::Rc; | ||
|
||
/// Represents all the lex tokens in a source. | ||
#[derive(PartialEq, Eq, Debug)] | ||
pub struct LexList { | ||
tokens: Vec<Tokens>, | ||
} | ||
|
||
impl LexList { | ||
pub fn from_tokens(tokens: Vec<Tokens>) -> Self { | ||
LexList { tokens } | ||
} | ||
|
||
pub fn from_reader(reader: Rc<RefCell<Reader>>) -> Self { | ||
lex_all(reader) | ||
} | ||
} | ||
|
||
pub fn lex_all(reader: Rc<RefCell<Reader>>) -> LexList { | ||
let mut list = Vec::with_capacity(512); | ||
let mut lexer = CodeLexer::new(reader); | ||
while let MaybeToken::Token(token) = lexer.lex() { | ||
list.push(token) | ||
} | ||
list.shrink_to_fit(); | ||
LexList { tokens: list } | ||
} |
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 @@ | ||
pub mod lex_all; |
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