draft fix for datetimes in record values

This commit is contained in:
Kira 2024-07-19 23:32:42 +02:00
parent ca8eb856e8
commit ca22477511
2 changed files with 47 additions and 2 deletions

View File

@ -454,6 +454,26 @@ pub fn lex_signature(
special_tokens,
skip_comment,
true,
false,
)
}
// temporary name because i cant decide on a better one
pub fn lex_but_ignore_specials_after_special(
input: &[u8],
span_offset: usize,
additional_whitespace: &[u8],
special_tokens: &[u8],
skip_comment: bool,
) -> (Vec<Token>, Option<ParseError>) {
lex_internal(
input,
span_offset,
additional_whitespace,
special_tokens,
skip_comment,
false,
true,
)
}
@ -471,6 +491,7 @@ pub fn lex(
special_tokens,
skip_comment,
false,
false,
)
}
@ -482,7 +503,12 @@ fn lex_internal(
skip_comment: bool,
// within signatures we want to treat `<` and `>` specially
in_signature: bool,
// after lexing a special item, disable special items when lexing the next item.
// necessary because colons are special in records, but datetime literals may contain colons
ignore_specials_after_special: bool,
) -> (Vec<Token>, Option<ParseError>) {
let mut specials_disabled = false;
let mut error = None;
let mut curr_offset = 0;
@ -612,7 +638,22 @@ fn lex_internal(
} else if c == b' ' || c == b'\t' || additional_whitespace.contains(&c) {
// If the next character is non-newline whitespace, skip it.
curr_offset += 1;
} else if ignore_specials_after_special && !specials_disabled && special_tokens.contains(&c)
{
// If disabling special items but if they're not currently disabled, handle a special item
// character right here, bypassing lex_item
output.push(Token::new(
TokenContents::Item,
Span::new(span_offset + curr_offset, span_offset + curr_offset + 1),
));
curr_offset += 1;
specials_disabled = true;
} else {
let special_tokens = if specials_disabled {
&[]
} else {
special_tokens
};
let (token, err) = lex_item(
input,
&mut curr_offset,
@ -625,6 +666,9 @@ fn lex_internal(
error = err;
}
is_complete = true;
if token.contents == TokenContents::Item {
specials_disabled = false;
}
output.push(token);
}
}

View File

@ -1,5 +1,5 @@
use crate::{
lex::{is_assignment_operator, lex, lex_signature},
lex::{is_assignment_operator, lex, lex_but_ignore_specials_after_special, lex_signature},
lite_parser::{lite_parse, LiteCommand, LitePipeline, LiteRedirection, LiteRedirectionTarget},
parse_keywords::*,
parse_patterns::parse_pattern,
@ -5601,7 +5601,8 @@ pub fn parse_record(working_set: &mut StateWorkingSet, span: Span) -> Expression
let inner_span = Span::new(start, end);
let source = working_set.get_span_contents(inner_span);
let (tokens, err) = lex(source, start, &[b'\n', b'\r', b','], &[b':'], true);
let (tokens, err) =
lex_but_ignore_specials_after_special(source, start, &[b'\n', b'\r', b','], &[b':'], true);
if let Some(err) = err {
working_set.error(err);
}