current tests pass

This commit is contained in:
gluax 2022-03-16 13:02:56 -07:00
parent 9391a31569
commit 0e7d36a61c
13 changed files with 175 additions and 157 deletions

View File

@ -90,7 +90,7 @@ impl Token {
// Account for the chars '\' and 'x'.
let mut len = 2;
// At least one hex character necessary.
// First hex character.
if let Some(c) = input.next_if(|c| c != &'\'') {
len += 1;
hex.push(c);
@ -100,10 +100,14 @@ impl Token {
return Err(ParserError::lexer_empty_input_tendril().into());
}
// Second hex character optional.
// Second hex character.
if let Some(c) = input.next_if(|c| c != &'\'') {
len += 1;
hex.push(c);
} else if let Some(c) = input.next() {
return Err(ParserError::lexer_expected_valid_hex_char(c).into());
} else {
return Err(ParserError::lexer_empty_input_tendril().into());
}
if let Ok(ascii_number) = u8::from_str_radix(&hex, 16) {
@ -313,10 +317,9 @@ impl Token {
return Ok((1, Token::Dot));
}
Some(c) if c == &'/' => {
let mut comment = String::from(*c);
input.next();
if let Some(c) = input.next_if_eq(&'/') {
comment.push(c);
if input.next_if_eq(&'/').is_some() {
let mut comment = String::from("//");
while let Some(c) = input.next_if(|c| c != &'\n') {
comment.push(c);
@ -324,12 +327,12 @@ impl Token {
if let Some(newline) = input.next_if_eq(&'\n') {
comment.push(newline);
return Ok((comment.len() + 1, Token::CommentLine(comment)));
return Ok((comment.len(), Token::CommentLine(comment)));
}
return Ok((comment.len(), Token::CommentLine(comment)));
} else if let Some(c) = input.next_if_eq(&'*') {
comment.push(c);
} else if input.next_if_eq(&'*').is_some() {
let mut comment = String::from("/*");
if input.peek().is_none() {
return Err(ParserError::lexer_empty_block_comment().into());
@ -348,7 +351,7 @@ impl Token {
if !ended {
return Err(ParserError::lexer_block_comment_does_not_close_before_eof(comment).into());
}
return Ok((comment.len() + 4, Token::CommentBlock(comment)));
return Ok((comment.len(), Token::CommentBlock(comment)));
} else if input.next_if_eq(&'=').is_some() {
return Ok((2, Token::DivEq));
}

View File

@ -237,6 +237,7 @@ mod tests {
});
}
#[test]
fn test_spans() {
create_session_if_not_set_then(|_| {
let raw = r#"

View File

@ -2,54 +2,54 @@
namespace: Token
expectation: Pass
outputs:
- "'a' @ 1:1-4"
- "'Z' @ 1:1-4"
- "'\"' @ 1:1-5"
- "'' @ 1:1-5"
- "'' @ 1:1-5"
- "'\u0000' @ 1:1-5"
- "'\u000f' @ 1:1-8"
- "'' @ 1:1-6"
- "'å' @ 1:1-9"
- "'å' @ 1:1-5"
- "'Ӡ' @ 1:1-10"
- "'Ӡ' @ 1:1-5"
- "'❤' @ 1:1-11"
- "'❤' @ 1:1-6"
- "'😢' @ 1:1-12"
- "'😭' @ 1:1-7"
- "'􀀟' @ 1:1-13"
- "'*' @ 1:1-7"
- "'\u007f' @ 1:1-7"
- "'\u0000' @ 1:1-7"
- "'\u0001' @ 1:1-7"
- "'\u0002' @ 1:1-7"
- "'\u0003' @ 1:1-7"
- "'\u0004' @ 1:1-7"
- "'\u0005' @ 1:1-7"
- "'\u0006' @ 1:1-7"
- "'\u0007' @ 1:1-7"
- "'\u0010' @ 1:1-7"
- "'\u0011' @ 1:1-7"
- "'\u0012' @ 1:1-7"
- "'\u0013' @ 1:1-7"
- "'\u0014' @ 1:1-7"
- "'\u0015' @ 1:1-7"
- "'\u0016' @ 1:1-7"
- "'\u0017' @ 1:1-7"
- "'' @ 1:1-7"
- "'!' @ 1:1-7"
- "'\"' @ 1:1-7"
- "'#' @ 1:1-7"
- "'$' @ 1:1-7"
- "'%' @ 1:1-7"
- "'&' @ 1:1-7"
- "''' @ 1:1-7"
- "'0' @ 1:1-7"
- "'1' @ 1:1-7"
- "'2' @ 1:1-7"
- "'3' @ 1:1-7"
- "'4' @ 1:1-7"
- "'5' @ 1:1-7"
- "'6' @ 1:1-7"
- "'7' @ 1:1-7"
- "''a'' @ 1:1-4"
- "''Z'' @ 1:1-4"
- "''\"'' @ 1:1-5"
- "''\t'' @ 1:1-5"
- "''\r'' @ 1:1-5"
- "''\u0000'' @ 1:1-5"
- "''\u000f'' @ 1:1-8"
- "'''' @ 1:1-6"
- "''å'' @ 1:1-9"
- "''å'' @ 1:1-5"
- "''Ӡ'' @ 1:1-10"
- "''Ӡ'' @ 1:1-5"
- "'''' @ 1:1-11"
- "'''' @ 1:1-6"
- "''😢'' @ 1:1-12"
- "''😭'' @ 1:1-7"
- "''􀀟'' @ 1:1-13"
- "''*'' @ 1:1-7"
- "''\u007f'' @ 1:1-7"
- "''\u0000'' @ 1:1-7"
- "''\u0001'' @ 1:1-7"
- "''\u0002'' @ 1:1-7"
- "''\u0003'' @ 1:1-7"
- "''\u0004'' @ 1:1-7"
- "''\u0005'' @ 1:1-7"
- "''\u0006'' @ 1:1-7"
- "''\u0007'' @ 1:1-7"
- "''\u0010'' @ 1:1-7"
- "''\u0011'' @ 1:1-7"
- "''\u0012'' @ 1:1-7"
- "''\u0013'' @ 1:1-7"
- "''\u0014'' @ 1:1-7"
- "''\u0015'' @ 1:1-7"
- "''\u0016'' @ 1:1-7"
- "''\u0017'' @ 1:1-7"
- "'' '' @ 1:1-7"
- "''!'' @ 1:1-7"
- "''\"'' @ 1:1-7"
- "''#'' @ 1:1-7"
- "''$'' @ 1:1-7"
- "''%'' @ 1:1-7"
- "''&'' @ 1:1-7"
- "''''' @ 1:1-7"
- "''0'' @ 1:1-7"
- "''1'' @ 1:1-7"
- "''2'' @ 1:1-7"
- "''3'' @ 1:1-7"
- "''4'' @ 1:1-7"
- "''5'' @ 1:1-7"
- "''6'' @ 1:1-7"
- "''7'' @ 1:1-7"

View File

@ -2,22 +2,22 @@
namespace: Token
expectation: Fail
outputs:
- "Error [EPAR0370028]: Expected a closed char but found `'\\'`."
- "Error [EPAR0370028]: Expected a closed char but found `'a`."
- "Error [EPAR0370024]: Expected more characters to lex but found none."
- "Error [EPAR0370036]: Expected a valid hex character but found `154`."
- "Error [EPAR0370035]: Could not lex the following escaped hex due to being given more than two chars: `7`."
- "Error [EPAR0370028]: Expected a closed char but found `\\x7g`."
- "Error [EPAR0370035]: Could not lex the following escaped hex due to being given more than two chars: `z`."
- "Error [EPAR0370036]: Expected a valid hex character but found `128`."
- "Error [EPAR0370036]: Expected a valid hex character but found `193`."
- "Error [EPAR0370036]: Expected a valid hex character but found `194`."
- "Error [EPAR0370036]: Expected a valid hex character but found `223`."
- "Error [EPAR0370036]: Expected a valid hex character but found `192`."
- "Error [EPAR0370036]: Expected a valid hex character but found `224`."
- "Error [EPAR0370036]: Expected a valid hex character but found `159`."
- "Error [EPAR0370028]: Expected a closed char but found `abcdefg`."
- "Error [EPAR0370033]: Could not lex the following escaped char due to being given more than one char: `t\\t`."
- "Error [EPAR0370024]: Expected more characters to lex but found none."
- "Error [EPAR0370024]: Expected more characters to lex but found none."
- "Error [EPAR0370036]: Expected a valid hex character but found `9A`."
- "Error [EPAR0370036]: Expected a valid hex character but found `'`."
- "Error [EPAR0370036]: Expected a valid hex character but found `7g`."
- "Error [EPAR0370036]: Expected a valid hex character but found `'`."
- "Error [EPAR0370036]: Expected a valid hex character but found `80`."
- "Error [EPAR0370036]: Expected a valid hex character but found `c1`."
- "Error [EPAR0370036]: Expected a valid hex character but found `c2`."
- "Error [EPAR0370036]: Expected a valid hex character but found `DF`."
- "Error [EPAR0370036]: Expected a valid hex character but found `C0`."
- "Error [EPAR0370036]: Expected a valid hex character but found `e0`."
- "Error [EPAR0370036]: Expected a valid hex character but found `9f`."
- "Error [EPAR0370027]: Expected a closed string but found `'b'`."
- "Error [EPAR0370027]: Expected a closed string but found `'\\\\'`."
- "Error [EPAR0370026]: Expected a valid escape character but found `a`."
- "Error [EPAR0370026]: Expected a valid escape character but found `z`."
- "Error [EPAR0370026]: Expected a valid escape character but found `A`."
@ -25,20 +25,20 @@ outputs:
- "Error [EPAR0370026]: Expected a valid escape character but found `1`."
- "Error [EPAR0370026]: Expected a valid escape character but found `9`."
- "Error [EPAR0370026]: Expected a valid escape character but found `*`."
- "Error [EPAR0370035]: Could not lex the following escaped hex due to being given more than two chars: ``."
- "Error [EPAR0370026]: Expected a valid escape character but found `39`."
- "Error [EPAR0370038]: The escaped unicode char `bbbbb}\\u{aaaa` is not within valid length of [1, 6]."
- "Error [EPAR0370026]: Expected a valid escape character but found `122`."
- "Error [EPAR0370026]: Expected a valid escape character but found `49`."
- "Error [EPAR0370026]: Expected a valid escape character but found `49`."
- "Error [EPAR0370037]: There was no closing `}` after a escaped unicode `\\u{2764z`."
- "Error [EPAR0370028]: Expected a closed char but found `\\u{276g}`."
- "Error [EPAR0370026]: Expected a valid escape character but found `48`."
- "Error [EPAR0370026]: Expected a valid escape character but found `48`."
- "Error [EPAR0370026]: Expected a valid escape character but found `57`."
- "Error [EPAR0370036]: Expected a valid hex character but found `'`."
- "Error [EPAR0370042]: There was no opening `{` after starting an escaped unicode `'`."
- "Error [EPAR0370027]: Expected a closed string but found `'\\\\'`."
- "Error [EPAR0370042]: There was no opening `{` after starting an escaped unicode `z`."
- "Error [EPAR0370042]: There was no opening `{` after starting an escaped unicode `1`."
- "Error [EPAR0370042]: There was no opening `{` after starting an escaped unicode `1`."
- "Error [EPAR0370037]: There was no closing `}` after a escaped unicode `2764z'`."
- "Error [EPAR0370036]: Expected a valid hex character but found `276g`."
- "Error [EPAR0370042]: There was no opening `{` after starting an escaped unicode `0`."
- "Error [EPAR0370042]: There was no opening `{` after starting an escaped unicode `0`."
- "Error [EPAR0370042]: There was no opening `{` after starting an escaped unicode `9`."
- "Error [EPAR0370039]: The escaped unicode char `110000` is greater than 0x10FFFF."
- "Error [EPAR0370026]: Expected a valid escape character but found `125`."
- "Error [EPAR0370037]: There was no closing `}` after a escaped unicode `\\u{af🦀`."
- "Error [EPAR0370029]: Expected valid character but found `'🦀\\n`."
- "Error [EPAR0370029]: Expected valid character but found `'🦀1🦀`."
- "Error [EPAR0370029]: Expected valid character but found `'😭😂`."
- "Error [EPAR0370042]: There was no opening `{` after starting an escaped unicode `}`."
- "Error [EPAR0370037]: There was no closing `}` after a escaped unicode `af🦀'`."
- "Error [EPAR0370027]: Expected a closed string but found `'\\\\'`."
- "Error [EPAR0370027]: Expected a closed string but found `'1'`."
- "Error [EPAR0370027]: Expected a closed string but found `'😂'`."

View File

@ -2,54 +2,54 @@
namespace: Token
expectation: Pass
outputs:
- "'a' @ 1:1-4"
- "'Z' @ 1:1-4"
- "'\"' @ 1:1-5"
- "'' @ 1:1-5"
- "'' @ 1:1-5"
- "'\u0000' @ 1:1-5"
- "'\u000f' @ 1:1-8"
- "'' @ 1:1-6"
- "'å' @ 1:1-9"
- "'å' @ 1:1-5"
- "'Ӡ' @ 1:1-10"
- "'Ӡ' @ 1:1-5"
- "'❤' @ 1:1-11"
- "'❤' @ 1:1-6"
- "'😢' @ 1:1-12"
- "'😭' @ 1:1-7"
- "'􀀟' @ 1:1-13"
- "'*' @ 1:1-7"
- "'\u007f' @ 1:1-7"
- "'\u0000' @ 1:1-7"
- "'\u0001' @ 1:1-7"
- "'\u0002' @ 1:1-7"
- "'\u0003' @ 1:1-7"
- "'\u0004' @ 1:1-7"
- "'\u0005' @ 1:1-7"
- "'\u0006' @ 1:1-7"
- "'\u0007' @ 1:1-7"
- "'\u0010' @ 1:1-7"
- "'\u0011' @ 1:1-7"
- "'\u0012' @ 1:1-7"
- "'\u0013' @ 1:1-7"
- "'\u0014' @ 1:1-7"
- "'\u0015' @ 1:1-7"
- "'\u0016' @ 1:1-7"
- "'\u0017' @ 1:1-7"
- "'' @ 1:1-7"
- "'!' @ 1:1-7"
- "'\"' @ 1:1-7"
- "'#' @ 1:1-7"
- "'$' @ 1:1-7"
- "'%' @ 1:1-7"
- "'&' @ 1:1-7"
- "''' @ 1:1-7"
- "'0' @ 1:1-7"
- "'1' @ 1:1-7"
- "'2' @ 1:1-7"
- "'3' @ 1:1-7"
- "'4' @ 1:1-7"
- "'5' @ 1:1-7"
- "'6' @ 1:1-7"
- "'7' @ 1:1-7"
- "''a'' @ 1:1-4"
- "''Z'' @ 1:1-4"
- "''\"'' @ 1:1-5"
- "''\t'' @ 1:1-5"
- "''\r'' @ 1:1-5"
- "''\u0000'' @ 1:1-5"
- "''\u000f'' @ 1:1-8"
- "'''' @ 1:1-6"
- "''å'' @ 1:1-9"
- "''å'' @ 1:1-5"
- "''Ӡ'' @ 1:1-10"
- "''Ӡ'' @ 1:1-5"
- "'''' @ 1:1-11"
- "'''' @ 1:1-6"
- "''😢'' @ 1:1-12"
- "''😭'' @ 1:1-7"
- "''􀀟'' @ 1:1-13"
- "''*'' @ 1:1-7"
- "''\u007f'' @ 1:1-7"
- "''\u0000'' @ 1:1-7"
- "''\u0001'' @ 1:1-7"
- "''\u0002'' @ 1:1-7"
- "''\u0003'' @ 1:1-7"
- "''\u0004'' @ 1:1-7"
- "''\u0005'' @ 1:1-7"
- "''\u0006'' @ 1:1-7"
- "''\u0007'' @ 1:1-7"
- "''\u0010'' @ 1:1-7"
- "''\u0011'' @ 1:1-7"
- "''\u0012'' @ 1:1-7"
- "''\u0013'' @ 1:1-7"
- "''\u0014'' @ 1:1-7"
- "''\u0015'' @ 1:1-7"
- "''\u0016'' @ 1:1-7"
- "''\u0017'' @ 1:1-7"
- "'' '' @ 1:1-7"
- "''!'' @ 1:1-7"
- "''\"'' @ 1:1-7"
- "''#'' @ 1:1-7"
- "''$'' @ 1:1-7"
- "''%'' @ 1:1-7"
- "''&'' @ 1:1-7"
- "''''' @ 1:1-7"
- "''0'' @ 1:1-7"
- "''1'' @ 1:1-7"
- "''2'' @ 1:1-7"
- "''3'' @ 1:1-7"
- "''4'' @ 1:1-7"
- "''5'' @ 1:1-7"
- "''6'' @ 1:1-7"
- "''7'' @ 1:1-7"

View File

@ -15,5 +15,5 @@ outputs:
- "'\"\n\"' @ 1:1-7"
- "'\"\u007f\"' @ 1:1-7"
- "'\"aa \\ \" \n aa \t \r \u0000\"' @ 1:1-28"
- "'\"test \"' @ 1:1-15"
- "'\"\"' @ 1:1-15"
- "'\"test 😒€\"' @ 1:1-15"
- "'\"😭😂😘\"' @ 1:1-15"

View File

@ -2,12 +2,12 @@
namespace: Token
expectation: Fail
outputs:
- "Error [EPAR0370027]: Expected a closed string but found `\"Hello world!`."
- "Error [EPAR0370027]: Expected a closed string but found `\"\\\"`."
- "Error [EPAR0370027]: Expected a closed string but found `[Scalar('H'), Scalar('e'), Scalar('l'), Scalar('l'), Scalar('o'), Scalar(' '), Scalar('w'), Scalar('o'), Scalar('r'), Scalar('l'), Scalar('d'), Scalar('!')]`."
- "Error [EPAR0370027]: Expected a closed string but found `[Scalar('\"')]`."
- "Error [EPAR0370026]: Expected a valid escape character but found `l`."
- "Error [EPAR0370027]: Expected a closed string but found `\"\\uaaa\"`."
- "Error [EPAR0370027]: Expected a closed string but found `\"\\u\"`."
- "Error [EPAR0370036]: Expected a valid hex character but found `255`."
- "Error [EPAR0370027]: Expected a closed string but found `\"\\x\"`."
- "Error [EPAR0370042]: There was no opening `{` after starting an escaped unicode `\\u}`."
- "Error [EPAR0370043]: There was an emoji found in the escaped unicode character: `\"\\u6🦀`."
- "Error [EPAR0370042]: There was no opening `{` after starting an escaped unicode `a`."
- "Error [EPAR0370042]: There was no opening `{` after starting an escaped unicode `\"`."
- "Error [EPAR0370036]: Expected a valid hex character but found `FF`."
- "Error [EPAR0370024]: Expected more characters to lex but found none."
- "Error [EPAR0370042]: There was no opening `{` after starting an escaped unicode `}`."
- "Error [EPAR0370042]: There was no opening `{` after starting an escaped unicode `6`."

View File

@ -177,6 +177,8 @@ outputs:
- Scalar: 115
- Scalar: 116
- Scalar: 32
- Scalar: 128530
- Scalar: 8364
- span:
line_start: 1
line_stop: 1
@ -186,7 +188,9 @@ outputs:
content: "\"test 😒€\""
- Value:
String:
- []
- - Scalar: 128557
- Scalar: 128514
- Scalar: 128536
- span:
line_start: 1
line_stop: 1

View File

@ -2,4 +2,4 @@
namespace: Parse
expectation: Fail
outputs:
- "Error [EPAR0370032]: Could not lex the following content: `|`."
- "Error [EPAR0370024]: Expected more characters to lex but found none."

View File

@ -2,4 +2,4 @@
namespace: Parse
expectation: Fail
outputs:
- "Error [EPAR0370027]: Expected a closed string but found `\"`."
- "Error [EPAR0370027]: Expected a closed string but found `[]`."

View File

@ -2,4 +2,4 @@
namespace: Parse
expectation: Fail
outputs:
- "Error [EPAR0370028]: Expected a closed char but found `'`."
- "Error [EPAR0370024]: Expected more characters to lex but found none."

View File

@ -2,4 +2,4 @@
namespace: Parse
expectation: Fail
outputs:
- "Error [EPAR0370026]: Expected a valid escape character but found `117`."
- "Error [EPAR0370024]: Expected more characters to lex but found none."

View File

@ -416,6 +416,10 @@ outputs:
arguments:
- Value:
String:
- Scalar: 128512
- Scalar: 128512
- Scalar: 128512
- Scalar: 128512
- Scalar: 128512
- Scalar: 32
- Scalar: 32
@ -426,6 +430,12 @@ outputs:
- Scalar: 32
- Scalar: 32
- Scalar: 32
- Scalar: 32
- Scalar: 128512
- Scalar: 128512
- Scalar: 128512
- Scalar: 128512
- Scalar: 128512
- Console:
function:
Assert: