-
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 block start/end token and lexing #56
- Loading branch information
Showing
5 changed files
with
111 additions
and
8 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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
use mango::io::typ::Reader; | ||
use mango::token::Tokens; | ||
|
||
pub enum MaybeToken { | ||
|
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,46 @@ | ||
use mango::token::Token; | ||
use mango::util::encdec::ToText; | ||
|
||
/// Start and end of blocks, signalled e.g. by indentation. | ||
#[derive(Debug, PartialEq, Eq, Hash, Clone)] | ||
pub struct StartBlockToken {} | ||
|
||
#[derive(Debug, PartialEq, Eq, Hash, Clone)] | ||
pub struct EndBlockToken { | ||
is_dedent: bool, | ||
is_end_keyword: bool, | ||
} | ||
|
||
impl StartBlockToken { | ||
pub fn new() -> Self { | ||
StartBlockToken {} | ||
} | ||
} | ||
|
||
impl EndBlockToken { | ||
pub fn new(is_dedent: bool, is_end_keyword: bool) -> Self { | ||
assert!(is_dedent || is_end_keyword); | ||
EndBlockToken { | ||
is_dedent, | ||
is_end_keyword, | ||
} | ||
} | ||
} | ||
|
||
impl ToText for StartBlockToken { | ||
// TODO: needs context information to render indents | ||
fn to_text(&self) -> String { | ||
" { ".to_owned() | ||
} | ||
} | ||
|
||
impl ToText for EndBlockToken { | ||
// TODO: needs context information to render indents | ||
fn to_text(&self) -> String { | ||
" } ".to_owned() | ||
} | ||
} | ||
|
||
impl Token for StartBlockToken {} | ||
|
||
impl Token for EndBlockToken {} |
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