-
Notifications
You must be signed in to change notification settings - Fork 4
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 #196 from JSAbrahams/v0.2.2
V0.2.2
- Loading branch information
Showing
77 changed files
with
1,084 additions
and
692 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,6 +1,6 @@ | ||
[package] | ||
name = "mamba" | ||
version = "0.2.1" | ||
version = "0.2.2" | ||
authors = ["Joel Abrahams <[email protected]>"] | ||
description = "A transpiler which translates Mamba to Python 3 files" | ||
edition = "2018" | ||
|
@@ -23,3 +23,4 @@ clap = {version = "2.33", features = ["yaml"]} | |
leg = "0.1.3" | ||
pathdiff = "0.1.0" | ||
glob = "0.3.0" | ||
itertools = "0.8.2" |
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 |
---|---|---|
|
@@ -77,6 +77,9 @@ pub enum Core { | |
num: String, | ||
exp: String | ||
}, | ||
DocStr { | ||
_str: String | ||
}, | ||
Str { | ||
_str: String | ||
}, | ||
|
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
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,73 @@ | ||
use crate::lexer::pass::Pass; | ||
use crate::lexer::token::{Lex, Token}; | ||
|
||
pub struct DocString { | ||
front: Option<Lex>, | ||
middle: Option<Lex>, | ||
back: Option<Lex> | ||
} | ||
|
||
impl DocString { | ||
pub fn new() -> DocString { DocString { front: None, middle: None, back: None } } | ||
|
||
fn add(&mut self, lex: &Lex) { | ||
self.front = self.middle.clone(); | ||
self.middle = self.back.clone(); | ||
self.back = Some(lex.clone()); | ||
} | ||
|
||
fn get(&mut self) -> Vec<Lex> { | ||
match (self.front.clone(), self.middle.clone(), self.back.clone()) { | ||
(Some(front), Some(middle), Some(back)) => | ||
match (front.token, middle.token, back.token) { | ||
(Token::Str(f_str, _), Token::Str(doc_str, _), Token::Str(b_str, _)) => | ||
if f_str.is_empty() && b_str.is_empty() | ||
// No spaces in between | ||
&& front.pos.end.pos == middle.pos.start.pos | ||
&& middle.pos.end.pos == back.pos.start.pos | ||
{ | ||
self.front = None; | ||
self.middle = None; | ||
self.back = None; | ||
return vec![Lex::new(&front.pos.start, Token::DocStr(doc_str))]; | ||
}, | ||
_ => {} | ||
}, | ||
_ => {} | ||
}; | ||
|
||
if let Some(lex) = &self.front.clone() { | ||
self.front = None; | ||
vec![lex.clone()] | ||
} else { | ||
vec![] | ||
} | ||
} | ||
|
||
fn flush(&mut self) -> Vec<Lex> { | ||
let mut remaining = vec![]; | ||
if let Some(lex) = &self.front { | ||
remaining.push(lex.clone()); | ||
} | ||
if let Some(lex) = &self.middle { | ||
remaining.push(lex.clone()); | ||
} | ||
if let Some(lex) = &self.back { | ||
remaining.push(lex.clone()); | ||
} | ||
remaining | ||
} | ||
} | ||
|
||
impl Pass for DocString { | ||
fn modify(&mut self, input: &[Lex]) -> Vec<Lex> { | ||
let mut out = vec![]; | ||
for lex in input { | ||
self.add(lex); | ||
out.append(&mut self.get()) | ||
} | ||
|
||
out.append(&mut self.flush()); | ||
out | ||
} | ||
} |
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,18 @@ | ||
use crate::lexer::pass::docstring::DocString; | ||
use crate::lexer::token::Lex; | ||
|
||
mod docstring; | ||
|
||
pub fn pass(input: &[Lex]) -> Vec<Lex> { | ||
let passes: Vec<Box<dyn Pass>> = vec![Box::from(DocString::new())]; | ||
|
||
let mut input = input.to_vec(); | ||
for mut pass in passes { | ||
input = pass.modify(&input); | ||
} | ||
input | ||
} | ||
|
||
trait Pass { | ||
fn modify(&mut self, input: &[Lex]) -> Vec<Lex>; | ||
} |
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
Oops, something went wrong.