Merge branch 'v1.3-fixes'

This commit is contained in:
Stephen Chung
2021-12-16 16:10:39 +08:00
7 changed files with 97 additions and 44 deletions

View File

@@ -1570,9 +1570,26 @@ fn parse_unary(
settings.ensure_level_within_max_limit(state.max_expr_depth)?;
let (token, token_pos) = input.peek().expect(NEVER_ENDS);
let token_pos = *token_pos;
let mut settings = settings;
settings.pos = *token_pos;
settings.pos = token_pos;
// Check if it is a custom syntax.
if !state.engine.custom_syntax.is_empty() {
match token {
Token::Custom(key) | Token::Reserved(key) | Token::Identifier(key) => {
if let Some((key, syntax)) = state.engine.custom_syntax.get_key_value(key.as_ref())
{
input.next().expect(NEVER_ENDS);
return parse_custom_syntax(
input, state, lib, settings, key, syntax, token_pos,
);
}
}
_ => (),
}
}
match token {
// -expr
@@ -2259,25 +2276,6 @@ fn parse_expr(
let mut settings = settings;
settings.pos = input.peek().expect(NEVER_ENDS).1;
// Check if it is a custom syntax.
if !state.engine.custom_syntax.is_empty() {
let (token, pos) = input.peek().expect(NEVER_ENDS);
let token_pos = *pos;
match token {
Token::Custom(key) | Token::Reserved(key) | Token::Identifier(key) => {
if let Some((key, syntax)) = state.engine.custom_syntax.get_key_value(key.as_ref())
{
input.next().expect(NEVER_ENDS);
return parse_custom_syntax(
input, state, lib, settings, key, syntax, token_pos,
);
}
}
_ => (),
}
}
// Parse expression normally.
let lhs = parse_unary(input, state, lib, settings.level_up())?;
parse_binary_op(

View File

@@ -883,11 +883,6 @@ impl Token {
use Token::*;
Precedence::new(match self {
// Assignments are not considered expressions - set to zero
Equals | PlusAssign | MinusAssign | MultiplyAssign | DivideAssign | PowerOfAssign
| LeftShiftAssign | RightShiftAssign | AndAssign | OrAssign | XOrAssign
| ModuloAssign => 0,
Or | XOr | Pipe => 30,
And | Ampersand => 60,
@@ -908,8 +903,6 @@ impl Token {
LeftShift | RightShift => 210,
Period => 240,
_ => 0,
})
}
@@ -920,14 +913,6 @@ impl Token {
use Token::*;
match self {
// Assignments bind to the right
Equals | PlusAssign | MinusAssign | MultiplyAssign | DivideAssign | PowerOfAssign
| LeftShiftAssign | RightShiftAssign | AndAssign | OrAssign | XOrAssign
| ModuloAssign => true,
// Property access binds to the right
Period => true,
// Exponentiation binds to the right
PowerOf => true,
@@ -1685,6 +1670,17 @@ fn get_next_token_inner(
// Shebang
('#', '!') => return Some((Token::Reserved("#!".into()), start_pos)),
('#', ' ') => {
eat_next(stream, pos);
let token = if stream.peek_next() == Some('{') {
eat_next(stream, pos);
"# {"
} else {
"#"
};
return Some((Token::Reserved(token.into()), start_pos));
}
('#', _) => return Some((Token::Reserved("#".into()), start_pos)),
// Operators
@@ -2212,7 +2208,7 @@ impl<'a> Iterator for TokenIterator<'a> {
("(*", false) | ("*)", false) => Token::LexError(LERR::ImproperSymbol(s.to_string(),
"'(* .. *)' is not a valid comment format. This is not Pascal! Should it be '/* .. */'?".to_string(),
)),
("#", false) => Token::LexError(LERR::ImproperSymbol(s.to_string(),
("# {", false) => Token::LexError(LERR::ImproperSymbol(s.to_string(),
"'#' is not a valid symbol. Should it be '#{'?".to_string(),
)),
// Reserved keyword/operator that is custom.

View File

@@ -703,7 +703,16 @@ impl fmt::Debug for Dynamic {
#[cfg(not(feature = "no_index"))]
Union::Array(ref value, _, _) => fmt::Debug::fmt(value, f),
#[cfg(not(feature = "no_index"))]
Union::Blob(ref value, _, _) => fmt::Debug::fmt(value, f),
Union::Blob(ref value, _, _) => {
f.write_str("[")?;
value.iter().enumerate().try_for_each(|(i, v)| {
if i > 0 && i % 8 == 0 {
f.write_str(" ")?;
}
write!(f, "{:02x}", v)
})?;
f.write_str("]")
}
#[cfg(not(feature = "no_object"))]
Union::Map(ref value, _, _) => {
f.write_str("#")?;