Encapsulate scope into EvalContext;

Fix bug with custom syntax delta.
This commit is contained in:
Stephen Chung
2020-10-19 19:11:55 +08:00
parent d1f9f4096d
commit a9fd0ff4de
15 changed files with 138 additions and 108 deletions

View File

@@ -1736,31 +1736,33 @@ impl<'a> Iterator for TokenIterator<'a, '_> {
}
}
/// Tokenize an input text stream.
#[inline]
pub fn lex<'a, 'e>(
input: &'a [&'a str],
map: Option<Box<dyn Fn(Token) -> Token>>,
engine: &'e Engine,
) -> TokenIterator<'a, 'e> {
TokenIterator {
engine,
state: TokenizeState {
#[cfg(not(feature = "unchecked"))]
max_string_size: engine.limits_set.max_string_size,
#[cfg(feature = "unchecked")]
max_string_size: 0,
non_unary: false,
comment_level: 0,
end_with_none: false,
include_comments: false,
},
pos: Position::new(1, 0),
stream: MultiInputsStream {
buf: None,
streams: input.iter().map(|s| s.chars().peekable()).collect(),
index: 0,
},
map,
impl Engine {
/// Tokenize an input text stream.
#[inline]
pub fn lex<'a, 'e>(
&'e self,
input: impl IntoIterator<Item = &'a &'a str>,
map: Option<Box<dyn Fn(Token) -> Token>>,
) -> TokenIterator<'a, 'e> {
TokenIterator {
engine: self,
state: TokenizeState {
#[cfg(not(feature = "unchecked"))]
max_string_size: self.limits_set.max_string_size,
#[cfg(feature = "unchecked")]
max_string_size: 0,
non_unary: false,
comment_level: 0,
end_with_none: false,
include_comments: false,
},
pos: Position::new(1, 0),
stream: MultiInputsStream {
buf: None,
streams: input.into_iter().map(|s| s.chars().peekable()).collect(),
index: 0,
},
map,
}
}
}