fix more bugs, add type checking

This commit is contained in:
gluax 2022-06-01 11:16:00 -07:00
parent 3b62e3cc97
commit 9638a695aa
17 changed files with 93 additions and 86 deletions

View File

@ -189,7 +189,6 @@ impl Token {
let mut ended = false;
while let Some(c) = input.next() {
// Check for illegal characters.
if is_bidi_override(c) {
return Err(ParserError::lexer_bidi_override().into());
@ -202,7 +201,6 @@ impl Token {
break;
}
string.push(c);
}
if !ended {
@ -403,6 +401,7 @@ impl Token {
"public" => Token::Public,
"return" => Token::Return,
"scalar" => Token::Scalar,
"string" => Token::String,
"true" => Token::True,
"u8" => Token::U8,
"u16" => Token::U16,

View File

@ -185,7 +185,7 @@ impl fmt::Display for Token {
match self {
CommentLine(s) => write!(f, "{}", s),
CommentBlock(s) => write!(f, "{}", s),
StaticString(s) => write!(f, "{}", s),
StaticString(s) => write!(f, "\"{}\"", s),
Ident(s) => write!(f, "{}", s),
Int(s) => write!(f, "{}", s),
True => write!(f, "true"),

View File

@ -137,7 +137,7 @@ impl<'a> TypeChecker<'a> {
}
ValueExpression::Group(_) => Some(self.assert_type(Type::Group, expected, value.span())),
ValueExpression::Scalar(_, _) => Some(self.assert_type(Type::Scalar, expected, value.span())),
ValueExpression::String(_, _) => unreachable!("String types are not reachable"),
ValueExpression::String(_, _) => Some(self.assert_type(Type::String, expected, value.span())),
},
Expression::Binary(binary) => match binary.op {
BinaryOperation::And | BinaryOperation::Or => {

View File

@ -0,0 +1,5 @@
[main]
hello: string = "hello";
[registers]
r: string = "world";

View File

@ -0,0 +1,11 @@
/*
namespace: Compile
expectation: Pass
input_file:
- inputs/string.in
*/
function main(hello: string) -> string {
let world: string = "world";
return world;
}

View File

@ -0,0 +1,11 @@
/*
namespace: Compile
expectation: Fail
input_file: inputs/dummy.in
*/
function main(y: bool) -> bool {
let hello: string = "hello world";
console.log(hello);
return y == true;
}

View File

@ -0,0 +1,8 @@
---
namespace: Compile
expectation: Pass
outputs:
- output:
- initial_input_ast: a7361387d9919bb2857c23ee47cc37c63f0c7cbbb7e7c92b700e2c33403fb4eb
initial_ast: 7198afa4563739d4a07c736554459c1b59cf66c96292c67b7853b2dbc4625efe
symbol_table: 4a29c4b5af2ad1879798454b95b7dd04ae7ecd48289c5f3e7a1e19eaf3921c3b

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EPAR0370009]: unexpected string: expected 'formatted static_string', got 'hello'\n --> compiler-test:5:17\n |\n 5 | console.log(hello);\n | ^^^^^"

View File

@ -5,15 +5,6 @@ outputs:
- "'\"string\"' @ 1:1-9"
- "'\"another { } string\"' @ 1:1-21"
- "'\"{ ] [ ; a\"' @ 1:1-12"
- "'\"࿺\"' @ 1:1-10"
- "'\"򯫺\"' @ 1:1-12"
- "'\"꾯\"' @ 1:1-11"
- "'\"ૺ\"' @ 1:1-10"
- "'\"¯\"' @ 1:1-9"
- "'\"\n\"' @ 1:1-8"
- "'\"\n\"' @ 1:1-7"
- "'\"\u007f\"' @ 1:1-7"
- "'\"aa \\ \" ' \n aa \t \r \u0000\"' @ 1:1-30"
- "'\"test 😒€\"' @ 1:1-10"
- "'\"😭😂😘\"' @ 1:1-6"
- "'\"✋🏿\"' @ 1:1-5"

View File

@ -3,16 +3,6 @@ namespace: Token
expectation: Fail
outputs:
- "Error [EPAR0370023]: Expected a closed string but found `Hello world!`."
- "Error [EPAR0370023]: Expected a closed string but found `\"`."
- "Error [EPAR0370021]: Expected more characters to lex but found none."
- "Error [EPAR0370022]: Expected a valid escape character but found `l`."
- "Error [EPAR0370034]: There was no opening `{` after starting an escaped unicode `a`."
- "Error [EPAR0370034]: There was no opening `{` after starting an escaped unicode `\"`."
- "Error [EPAR0370027]: Expected a valid hex character but found `FF`."
- "Error [EPAR0370021]: Expected more characters to lex but found none."
- "Error [EPAR0370034]: There was no opening `{` after starting an escaped unicode `}`."
- "Error [EPAR0370034]: There was no opening `{` after starting an escaped unicode `6`."
- "Error [EPAR0370029]: There was no closing `}` after a escaped unicode `af🦀\"`."
- "Error [EPAR0370023]: Expected a closed string but found `\"`."
- "Error [EPAR0370023]: Expected a closed string but found `\\`."
- "Error [EPAR0370023]: Expected a closed string but found `⭇😍;`."
- "Error [EPAR0370040]: Unicode bidi override code point encountered."

View File

@ -12,9 +12,7 @@ outputs:
- Console:
function:
Error:
string:
- Scalar: 123
- Scalar: 125
string: "{}"
parameters:
- Identifier: "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":20,\\\"hi\\\":21}\"}"
span:
@ -26,11 +24,7 @@ outputs:
- Console:
function:
Error:
string:
- Scalar: 123
- Scalar: 125
- Scalar: 123
- Scalar: 125
string: "{}{}"
parameters:
- Identifier: "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":22,\\\"hi\\\":23}\"}"
- Identifier: "{\"name\":\"y\",\"span\":\"{\\\"lo\\\":25,\\\"hi\\\":26}\"}"
@ -43,8 +37,7 @@ outputs:
- Console:
function:
Error:
string:
- Scalar: 120
string: x
parameters: []
span:
lo: 13
@ -55,9 +48,7 @@ outputs:
- Console:
function:
Log:
string:
- Scalar: 123
- Scalar: 125
string: "{}"
parameters:
- Identifier: "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":18,\\\"hi\\\":19}\"}"
span:
@ -69,11 +60,7 @@ outputs:
- Console:
function:
Log:
string:
- Scalar: 123
- Scalar: 125
- Scalar: 123
- Scalar: 125
string: "{}{}"
parameters:
- Identifier: "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":20,\\\"hi\\\":21}\"}"
- Identifier: "{\"name\":\"y\",\"span\":\"{\\\"lo\\\":23,\\\"hi\\\":24}\"}"
@ -86,8 +73,7 @@ outputs:
- Console:
function:
Log:
string:
- Scalar: 120
string: x
parameters: []
span:
lo: 11

View File

@ -3,5 +3,5 @@ namespace: ParseStatement
expectation: Fail
outputs:
- "Error [EPAR0370040]: Unicode bidi override code point encountered."
- "Error [EPAR0370009]: unexpected string: expected 'formatted string', got '1'\n --> test:1:13\n |\n 1 | console.log(1);\n | ^"
- "Error [EPAR0370009]: unexpected string: expected 'formatted static_string', got '1'\n --> test:1:13\n |\n 1 | console.log(1);\n | ^"
- "Error [EPAR0370007]: unexpected identifier: expected 'assert', 'error', 'log' -- got 'test'\n --> test:1:9\n |\n 1 | console.test();\n | ^^^^"

View File

@ -61,6 +61,20 @@ outputs:
span:
lo: 0
hi: 15
- Definition:
declaration_type: Let
variable_names:
- mutable: true
identifier: "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":4,\\\"hi\\\":5}\"}"
span:
lo: 4
hi: 5
type_: String
value:
Identifier: "{\"name\":\"expr\",\"span\":\"{\\\"lo\\\":16,\\\"hi\\\":20}\"}"
span:
lo: 0
hi: 20
- Definition:
declaration_type: Const
variable_names:
@ -120,6 +134,20 @@ outputs:
span:
lo: 0
hi: 17
- Definition:
declaration_type: Const
variable_names:
- mutable: false
identifier: "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":6,\\\"hi\\\":7}\"}"
span:
lo: 6
hi: 7
type_: String
value:
Identifier: "{\"name\":\"expr\",\"span\":\"{\\\"lo\\\":18,\\\"hi\\\":22}\"}"
span:
lo: 0
hi: 22
- Definition:
declaration_type: Let
variable_names:

View File

@ -25,23 +25,23 @@ outputs:
- "Error [EPAR0370009]: unexpected string: expected 'ident', got ','\n --> test:1:10\n |\n 1 | let (x,y,,) = ();\n | ^"
- "Error [EPAR0370009]: unexpected string: expected 'ident', got ','\n --> test:1:6\n |\n 1 | let (,x,y) = ();\n | ^"
- "Error [EPAR0370009]: unexpected string: expected 'ident', got ','\n --> test:1:8\n |\n 1 | let (x,,y) = ();\n | ^"
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '['\n --> test:1:8\n |\n 1 | let x: [u8; (2,,)] = [[0,0], [0,0]];\n | ^"
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got 'const'\n --> test:1:8\n |\n 1 | let x: const = expr;\n | ^^^^^"
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got 'let'\n --> test:1:10\n |\n 1 | const x: let = expr;\n | ^^^"
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got 'mut'\n --> test:1:8\n |\n 1 | let x: mut = expr;\n | ^^^"
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'string', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '['\n --> test:1:8\n |\n 1 | let x: [u8; (2,,)] = [[0,0], [0,0]];\n | ^"
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'string', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got 'const'\n --> test:1:8\n |\n 1 | let x: const = expr;\n | ^^^^^"
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'string', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got 'let'\n --> test:1:10\n |\n 1 | const x: let = expr;\n | ^^^"
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'string', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got 'mut'\n --> test:1:8\n |\n 1 | let x: mut = expr;\n | ^^^"
- "Error [EPAR0370009]: unexpected string: expected 'ident', got '<eof>'\n --> test:1:1\n |\n 1 | let\n | ^^^"
- "Error [EPAR0370005]: expected : -- got '<eof>'\n --> test:1:5\n |\n 1 | let x\n | ^"
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '<eof>'\n --> test:1:6\n |\n 1 | let x:\n | ^"
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'string', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '<eof>'\n --> test:1:6\n |\n 1 | let x:\n | ^"
- "Error [EPAR0370005]: expected : -- got '='\n --> test:1:7\n |\n 1 | let x = (a, y]);\n | ^"
- "Error [EPAR0370009]: unexpected string: expected 'ident', got '='\n --> test:1:5\n |\n 1 | let = 1u8;\n | ^"
- "Error [EPAR0370009]: unexpected string: expected 'ident', got ';'\n --> test:1:4\n |\n 1 | let;\n | ^"
- "Error [EPAR0370005]: expected : -- got '1'\n --> test:1:7\n |\n 1 | let x 1u8;\n | ^"
- "Error [EPAR0370005]: expected = -- got ';'\n --> test:1:10\n |\n 1 | let x: u8;\n | ^"
- "Error [EPAR0370005]: expected = -- got '<eof>'\n --> test:1:8\n |\n 1 | let x: u8\n | ^^"
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '='\n --> test:1:8\n |\n 1 | let x: = 1;\n | ^"
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '['\n --> test:1:8\n |\n 1 | let x: [u8] = 1;\n | ^"
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '['\n --> test:1:8\n |\n 1 | let x: [u8;\n | ^"
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '['\n --> test:1:8\n |\n 1 | let x: [u8; 1u8] = [1,\n | ^"
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'string', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '='\n --> test:1:8\n |\n 1 | let x: = 1;\n | ^"
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'string', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '['\n --> test:1:8\n |\n 1 | let x: [u8] = 1;\n | ^"
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'string', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '['\n --> test:1:8\n |\n 1 | let x: [u8;\n | ^"
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'string', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '['\n --> test:1:8\n |\n 1 | let x: [u8; 1u8] = [1,\n | ^"
- "Error [EPAR0370009]: unexpected string: expected 'expression', got ']'\n --> test:1:15\n |\n 1 | let dbg: u8 = ];\n | ^"
- "Error [EPAR0370026]: Could not lex the following content: `🦀: u8 = 0;`."
- "Error [EPAR0370035]: do not put parens around single variable names\n --> test:1:6\n |\n 1 | let (x) = ...;\n | ^\nError [EPAR0370005]: expected : -- got '='\n --> test:1:9\n |\n 1 | let (x) = ...;\n | ^"

View File

@ -9,19 +9,6 @@ expectation: Pass
"{ ] [ ; a"
"\u{FFA}"
"\u{afafa}"
"\u{afaf}"
"\u{afa}"
"\u{af}"
"\u{a}"
"\x0A"
"\x7F"
"aa \\ \" \' \n aa \t \r \0"
"test 😒€"
"😭😂😘"

View File

@ -5,28 +5,10 @@ expectation: Fail
"Hello world!
"\"
"\
"\l"
"\uaaa"
"\u"
"\xFF"
"\x"
"\u}"
"\u6🦀}"
"\u{af🦀"
"\"
"⭇😍;
"2066:"

View File

@ -9,6 +9,8 @@ let x: u16 = x+y;
let x: u8 = x();
let x: string = expr;
const x: i8 = expr;
@ -16,6 +18,8 @@ const x: i16 = x+y;
const x: i8 = x();
const x: string = expr;
let x: u32 = expr;