-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into generic-parselets
- Loading branch information
Showing
46 changed files
with
1,110 additions
and
424 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
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,10 +1,16 @@ | ||
# Tokay code generator for generating a builtin registration function in Rust written in Tokay v0.4 | ||
|
||
'impl' _ Identifier _ '{' { | ||
impl = $3 | ||
accept | ||
} | ||
|
||
'tokay_' kind => { | ||
''function'' | ||
''method'' | ||
''token'' | ||
} '!' _ '(' _ '"' _ name => Identifier #{ | ||
} '!' _ '(' _ '"' _ name => Identifier { | ||
kind => $kind, name => $name, impl => impl | ||
#accept "register(\"" + $name + "\", tokay_" + $kind + "_" + $name.lower() + ")" | ||
#print("register(\"" + $name + "\", tokay_" + $kind + "_" + $name.lower() + ")") | ||
#} | ||
} |
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,81 @@ | ||
use crate::value::{Iter, Object, RefValue, RefValueIter}; | ||
use crate::{Context, Error}; | ||
use num::{One, Zero}; | ||
use num_bigint::BigInt; | ||
use tokay_macros::tokay_function; | ||
extern crate self as tokay; | ||
|
||
#[derive(Clone)] | ||
struct RangeIter { | ||
next: Option<BigInt>, | ||
stop: BigInt, | ||
step: BigInt, | ||
} | ||
|
||
impl RefValueIter for RangeIter { | ||
fn next(&mut self, _context: Option<&mut Context>) -> Option<RefValue> { | ||
if let Some(next) = self.next.as_mut() { | ||
if *next != self.stop { | ||
let ret = next.clone(); | ||
*next += &self.step; | ||
return Some(RefValue::from(ret)); | ||
} | ||
|
||
self.next = None; | ||
} | ||
|
||
None | ||
} | ||
|
||
fn repr(&self) -> String { | ||
if self.step.is_one() { | ||
format!( | ||
"range({}, {})", | ||
self.next.as_ref().unwrap_or(&self.stop), | ||
self.stop | ||
) | ||
} else { | ||
format!( | ||
"range({}, {}, {})", | ||
self.next.as_ref().unwrap_or(&self.stop), | ||
self.stop, | ||
self.step | ||
) | ||
} | ||
} | ||
|
||
fn rev(&mut self) -> Result<(), Error> { | ||
self.step = -self.step.clone(); | ||
let next = self.next.as_ref().unwrap_or(&self.stop).clone(); | ||
(self.next, self.stop) = (Some(self.stop.clone() + &self.step), next + &self.step); | ||
Ok(()) | ||
} | ||
} | ||
|
||
tokay_function!("range : @start, stop=void, step=1", { | ||
let start = if stop.is_void() { | ||
stop = start; | ||
BigInt::from(0) | ||
} else { | ||
start.to_bigint()? | ||
}; | ||
|
||
let stop = stop.to_bigint()?; | ||
let step = step.to_bigint()?; | ||
|
||
if step.is_zero() { | ||
return Error::from(format!("{} argument 'step' may not be 0", __function)).into(); | ||
} | ||
|
||
RefValue::from(Iter::new(Box::new(RangeIter { | ||
next: if (step > BigInt::zero() && start > stop) || (step < BigInt::zero() && stop > start) | ||
{ | ||
None | ||
} else { | ||
Some(start) | ||
}, | ||
stop, | ||
step, | ||
}))) | ||
.into() | ||
}); |
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.