From a8cc73f6d920e571148de961363518dee2de37b2 Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 24 May 2021 22:18:23 +0200 Subject: [PATCH 1/3] Change type separator from : to < --- .gitignore | 1 + Cargo.lock | 14 +++++++------- a.out | 0 ci/simple.Dockerfile | 3 ++- src/lexeme/lexemes/operator.rs | 4 ++-- src/parsing/partial/parameters.rs | 6 ++++-- 6 files changed, 16 insertions(+), 12 deletions(-) delete mode 100644 a.out diff --git a/.gitignore b/.gitignore index d3a1a1f3..102a12d7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ target/ *.iml __pycache__/ *.pyc +*.out ### PREVIOUS KOTLIN AND IDEA IGNORES ### diff --git a/Cargo.lock b/Cargo.lock index bc5417bd..11b2a10f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "ahash" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f200cbb1e856866d9eade941cf3aa0c5d7dd36f74311c4273b494f4ef036957" +checksum = "11149c3eb723d15cb065a9ea5cc74ab57250f098ef33c9f6f7f39b48bd207750" dependencies = [ "getrandom", "once_cell", @@ -105,9 +105,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ "cfg-if 1.0.0", "libc", @@ -246,9 +246,9 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro2" -version = "1.0.26" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" +checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" dependencies = [ "unicode-xid", ] @@ -366,7 +366,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb975d3ddaf19128799ec5be6300d4d371b2ee1c977d6115385749dda011e790" dependencies = [ - "ahash 0.7.2", + "ahash 0.7.3", "byteorder", "lazy_static", "parking_lot 0.11.1", diff --git a/a.out b/a.out deleted file mode 100644 index e69de29b..00000000 diff --git a/ci/simple.Dockerfile b/ci/simple.Dockerfile index 7998e819..116b56c4 100644 --- a/ci/simple.Dockerfile +++ b/ci/simple.Dockerfile @@ -5,7 +5,8 @@ FROM mangocode/mango_daily_base:2021-05-02 AS build ENV RUST_LOG='debug,ws=warn,mio=warn' # Copy the actual code. -COPY ./Cargo.toml ./Cargo.lock ./deny.toml ./rustfmt.toml ./ +# exclude .lock file for now as it slows down dependencies +COPY ./Cargo.toml ./deny.toml ./rustfmt.toml ./ COPY ./src/ ./src # Build (for test) diff --git a/src/lexeme/lexemes/operator.rs b/src/lexeme/lexemes/operator.rs index 367ec692..54df2467 100644 --- a/src/lexeme/lexemes/operator.rs +++ b/src/lexeme/lexemes/operator.rs @@ -9,8 +9,8 @@ use crate::lexeme::Lexeme; /// Also in-place operations like *=, += etc. #[derive(Debug, Eq, Clone)] pub struct OperatorLexeme { - symbol: Symbol, - source: SourceSlice, + pub symbol: Symbol, + pub source: SourceSlice, } impl OperatorLexeme { diff --git a/src/parsing/partial/parameters.rs b/src/parsing/partial/parameters.rs index b102a959..55cdb2a2 100644 --- a/src/parsing/partial/parameters.rs +++ b/src/parsing/partial/parameters.rs @@ -2,11 +2,12 @@ use std::collections::HashSet; use ::smallvec::smallvec; -use crate::lexeme::Lexeme; +use crate::lexeme::{Lexeme, OperatorLexeme}; use crate::parselet::signature::parameters::{ParametersParselet, TypedValueParselet}; use crate::parsing::partial::typ::parse_type; use crate::parsing::util::cursor::ParseCursor; use crate::parsing::util::{NoMatch, ParseRes}; +use crate::ir::codeparts::Symbol; /// Parse a series of names with types, e.g. for function declarations, including the parentheses (). pub fn parse_parenthesised_parameters(mut cursor: ParseCursor) -> ParseRes { @@ -30,7 +31,8 @@ pub fn parse_parameters(mut cursor: ParseCursor) -> ParseRes Ok(Lexeme::Identifier(name)) => { if let Some(name) = name.to_simple() { let name = name.clone(); - if let Lexeme::Colon(_) = iter_cursor.take()? { + //TODO @mark: ':' to '<' ? + if let Lexeme::Operator(OperatorLexeme { symbol: Symbol::LT, source: _ }) = iter_cursor.take()? { //TODO @mark: parse complex types like [int, double] or Vec[int] if let Ok((typ_cursor, typ)) = parse_type(iter_cursor) { if names_seen.contains(name.name.as_ustr()) { From 0de17b7e60fe111649b75f2b78e3e5f169ea3026 Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 25 May 2021 23:23:42 +0200 Subject: [PATCH 2/3] Update tests to use < instead of : for types --- src/lexeme/collect/for_test.rs | 4 ++ src/parsing/files/file.rs | 4 +- src/parsing/partial/parameters.rs | 65 +++++++++++++++---------------- src/parsing/signature/function.rs | 12 +++--- 4 files changed, 44 insertions(+), 41 deletions(-) diff --git a/src/lexeme/collect/for_test.rs b/src/lexeme/collect/for_test.rs index 1d23926d..7aac4f05 100644 --- a/src/lexeme/collect/for_test.rs +++ b/src/lexeme/collect/for_test.rs @@ -235,6 +235,10 @@ impl TestLexemeBuilder { self.add_simple(": ", |src| Lexeme::Colon(ColonLexeme::new(src))) } + pub fn type_sep(self) -> Self { + self.add_simple("< ", |src| Lexeme::Operator(OperatorLexeme::from_symbol(Symbol::LT, src))) + } + pub fn comma(self) -> Self { self.add_simple(",", |src| Lexeme::Comma(CommaLexeme::new(src))) } diff --git a/src/parsing/files/file.rs b/src/parsing/files/file.rs index 3ace4cf6..8f18326e 100644 --- a/src/parsing/files/file.rs +++ b/src/parsing/files/file.rs @@ -130,11 +130,11 @@ mod tests { .identifier("gcd") .parenthesis_open() .identifier("x") - .colon() + .type_sep() .identifier("int") .comma() .identifier("y") - .colon() + .type_sep() .identifier("int") .parenthesis_close() .operator("➔") diff --git a/src/parsing/partial/parameters.rs b/src/parsing/partial/parameters.rs index 55cdb2a2..b5ecf9a8 100644 --- a/src/parsing/partial/parameters.rs +++ b/src/parsing/partial/parameters.rs @@ -31,7 +31,6 @@ pub fn parse_parameters(mut cursor: ParseCursor) -> ParseRes Ok(Lexeme::Identifier(name)) => { if let Some(name) = name.to_simple() { let name = name.clone(); - //TODO @mark: ':' to '<' ? if let Lexeme::Operator(OperatorLexeme { symbol: Symbol::LT, source: _ }) = iter_cursor.take()? { //TODO @mark: parse complex types like [int, double] or Vec[int] if let Ok((typ_cursor, typ)) = parse_type(iter_cursor) { @@ -80,7 +79,7 @@ mod with_parentheses { let lexemes = builder() .parenthesis_open() .identifier("name") - .colon() + .type_sep() .identifier("type") .parenthesis_close() .file(); @@ -95,7 +94,7 @@ mod with_parentheses { let lexemes = builder() .parenthesis_open() .identifier("name") - .colon() + .type_sep() .identifier("type") .comma() .parenthesis_close() @@ -111,7 +110,7 @@ mod with_parentheses { let lexemes = builder() .parenthesis_open() .identifier("name") - .colon() + .type_sep() .identifier("type") .newline() .parenthesis_close() @@ -127,7 +126,7 @@ mod with_parentheses { let lexemes = builder() .parenthesis_open() .identifier("name") - .colon() + .type_sep() .identifier("type") .comma() .newline() @@ -144,19 +143,19 @@ mod with_parentheses { let lexemes = builder() .parenthesis_open() .identifier("name1") - .colon() + .type_sep() .identifier("type1") .comma() .identifier("name2") - .colon() + .type_sep() .identifier("type2") .comma() .identifier("name3") - .colon() + .type_sep() .identifier("type3") .newline() .identifier("name4") - .colon() + .type_sep() .identifier("type4") .newline() .parenthesis_close() @@ -175,11 +174,11 @@ mod with_parentheses { let lexemes = builder() .parenthesis_open() .identifier("name1") - .colon() + .type_sep() .identifier("type") .comma() .identifier("name2") - .colon() + .type_sep() .identifier("type") .comma() .parenthesis_close() @@ -213,11 +212,11 @@ mod error_cases { let lexemes = builder() .parenthesis_open() .identifier("name") - .colon() + .type_sep() .identifier("type1") .comma() .identifier("name") - .colon() + .type_sep() .identifier("type2") .comma() .parenthesis_close() @@ -230,7 +229,7 @@ mod error_cases { fn missing_open() { let lexemes = builder() .identifier("name") - .colon() + .type_sep() .identifier("type1") .comma() .parenthesis_close() @@ -244,7 +243,7 @@ mod error_cases { let lexemes = builder() .parenthesis_open() .identifier("name") - .colon() + .type_sep() .identifier("type1") .comma() .file(); @@ -257,10 +256,10 @@ mod error_cases { let lexemes = builder() .parenthesis_open() .identifier("name") - .colon() + .type_sep() .identifier("type1") .identifier("name") - .colon() + .type_sep() .identifier("type1") .parenthesis_close() .file(); @@ -293,7 +292,7 @@ mod without_parentheses { #[test] fn single() { - let lexemes = builder().identifier("name").colon().identifier("type").file(); + let lexemes = builder().identifier("name").type_sep().identifier("type").file(); let (cursor, params) = parse_parameters(lexemes.cursor()).unwrap(); assert_eq!(params.len(), 1); assert_eq!(params[0], TypedValueParselet::new_mocked("name", "type")); @@ -304,7 +303,7 @@ mod without_parentheses { fn single_trailing_comma() { let lexemes = builder() .identifier("name") - .colon() + .type_sep() .identifier("type") .comma() .parenthesis_close() @@ -319,7 +318,7 @@ mod without_parentheses { fn single_trailing_newline() { let lexemes = builder() .identifier("name") - .colon() + .type_sep() .identifier("type") .newline() .parenthesis_close() @@ -334,7 +333,7 @@ mod without_parentheses { fn single_trailing_comma_and_newline() { let lexemes = builder() .identifier("name") - .colon() + .type_sep() .identifier("type") .comma() .newline() @@ -350,11 +349,11 @@ mod without_parentheses { fn double() { let lexemes = builder() .identifier("name1") - .colon() + .type_sep() .identifier("type1") .comma() .identifier("name2") - .colon() + .type_sep() .identifier("type2") .comma() .parenthesis_close() @@ -370,19 +369,19 @@ mod without_parentheses { fn quadruple() { let lexemes = builder() .identifier("name1") - .colon() + .type_sep() .identifier("type1") .comma() .identifier("name2") - .colon() + .type_sep() .identifier("type2") .comma() .identifier("name3") - .colon() + .type_sep() .identifier("type3") .newline() .identifier("name4") - .colon() + .type_sep() .identifier("type4") .newline() .parenthesis_close() @@ -400,11 +399,11 @@ mod without_parentheses { fn next_lexeme_close() { let lexemes = builder() .identifier("name1") - .colon() + .type_sep() .identifier("type") .comma() .identifier("name2") - .colon() + .type_sep() .identifier("type") .comma() .parenthesis_close() @@ -419,11 +418,11 @@ mod without_parentheses { fn next_lexeme_random() { let lexemes = builder() .identifier("name1") - .colon() + .type_sep() .identifier("type") .comma() .identifier("name2") - .colon() + .type_sep() .identifier("type") .comma() .keyword("use") @@ -438,11 +437,11 @@ mod without_parentheses { fn next_lexeme_eof() { let lexemes = builder() .identifier("name1") - .colon() + .type_sep() .identifier("type") .comma() .identifier("name2") - .colon() + .type_sep() .identifier("type") .file(); let (cursor, params) = parse_parameters(lexemes.cursor()).unwrap(); diff --git a/src/parsing/signature/function.rs b/src/parsing/signature/function.rs index 2dad672c..8b89ded0 100644 --- a/src/parsing/signature/function.rs +++ b/src/parsing/signature/function.rs @@ -187,10 +187,10 @@ mod empty_with_eof { tests!( no_param_no_return: builder().build(), smallvec![], vec![], "None", - one_param_no_return: builder().identifier("x").colon().identifier("int").build(), smallvec![param("x", "int")], vec![], "None", - multi_param_no_return: builder().identifier("x").colon().identifier("int").comma().identifier("y").colon().identifier("double").build(), smallvec![param("x", "int"), param("y", "double")], vec![], "None", + one_param_no_return: builder().identifier("x").type_sep().identifier("int").build(), smallvec![param("x", "int")], vec![], "None", + multi_param_no_return: builder().identifier("x").type_sep().identifier("int").comma().identifier("y").type_sep().identifier("double").build(), smallvec![param("x", "int"), param("y", "double")], vec![], "None", no_param_simple_return: builder().build(), smallvec![], builder().operator("->").identifier("int").build(), "int", - multi_param_simple_return: builder().identifier("x").colon().identifier("int").comma().identifier("y").colon().identifier("double").build(), smallvec![param("x", "int"), param("y", "double")], builder().operator("->").identifier("int").build(), "int", + multi_param_simple_return: builder().identifier("x").type_sep().identifier("int").comma().identifier("y").type_sep().identifier("double").build(), smallvec![param("x", "int"), param("y", "double")], builder().operator("->").identifier("int").build(), "int", ); } @@ -255,9 +255,9 @@ mod simple_body { tests!( no_param_no_return: builder().build(), smallvec![], vec![], "None", - one_param_no_return: builder().identifier("x").colon().identifier("int").build(), smallvec![param("x", "int")], vec![], "None", - multi_param_no_return: builder().identifier("x").colon().identifier("int").comma().identifier("y").colon().identifier("double").build(), smallvec![param("x", "int"), param("y", "double")], vec![], "None", + one_param_no_return: builder().identifier("x").type_sep().identifier("int").build(), smallvec![param("x", "int")], vec![], "None", + multi_param_no_return: builder().identifier("x").type_sep().identifier("int").comma().identifier("y").type_sep().identifier("double").build(), smallvec![param("x", "int"), param("y", "double")], vec![], "None", no_param_simple_return: builder().build(), smallvec![], builder().operator("->").identifier("int").build(), "int", - multi_param_simple_return: builder().identifier("x").colon().identifier("int").comma().identifier("y").colon().identifier("double").build(), smallvec![param("x", "int"), param("y", "double")], builder().operator("->").identifier("int").build(), "int", + multi_param_simple_return: builder().identifier("x").type_sep().identifier("int").comma().identifier("y").type_sep().identifier("double").build(), smallvec![param("x", "int"), param("y", "double")], builder().operator("->").identifier("int").build(), "int", ); } From d528145efefba78425d11d4cc758d1f56ca5db83 Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 25 May 2021 23:37:31 +0200 Subject: [PATCH 3/3] Few more test fixes, and restyling --- src/parsing/partial/parameters.rs | 12 ++++++++++-- src/parsing/signature/function.rs | 6 +++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/parsing/partial/parameters.rs b/src/parsing/partial/parameters.rs index b5ecf9a8..2d394b6c 100644 --- a/src/parsing/partial/parameters.rs +++ b/src/parsing/partial/parameters.rs @@ -2,12 +2,12 @@ use std::collections::HashSet; use ::smallvec::smallvec; +use crate::ir::codeparts::Symbol; use crate::lexeme::{Lexeme, OperatorLexeme}; use crate::parselet::signature::parameters::{ParametersParselet, TypedValueParselet}; use crate::parsing::partial::typ::parse_type; use crate::parsing::util::cursor::ParseCursor; use crate::parsing::util::{NoMatch, ParseRes}; -use crate::ir::codeparts::Symbol; /// Parse a series of names with types, e.g. for function declarations, including the parentheses (). pub fn parse_parenthesised_parameters(mut cursor: ParseCursor) -> ParseRes { @@ -31,7 +31,11 @@ pub fn parse_parameters(mut cursor: ParseCursor) -> ParseRes Ok(Lexeme::Identifier(name)) => { if let Some(name) = name.to_simple() { let name = name.clone(); - if let Lexeme::Operator(OperatorLexeme { symbol: Symbol::LT, source: _ }) = iter_cursor.take()? { + if let Lexeme::Operator(OperatorLexeme { + symbol: Symbol::LT, + source: _, + }) = iter_cursor.take()? + { //TODO @mark: parse complex types like [int, double] or Vec[int] if let Ok((typ_cursor, typ)) = parse_type(iter_cursor) { if names_seen.contains(name.name.as_ustr()) { @@ -45,8 +49,12 @@ pub fn parse_parameters(mut cursor: ParseCursor) -> ParseRes continue; } break; + } else { + //TODO @mark: better error handling + panic!("parameter {} is missing a type", name.name); } } else { + //TODO @mark: better error handling panic!("parameter {} is missing a type", name.name); } } diff --git a/src/parsing/signature/function.rs b/src/parsing/signature/function.rs index 8b89ded0..7978471e 100644 --- a/src/parsing/signature/function.rs +++ b/src/parsing/signature/function.rs @@ -140,10 +140,10 @@ mod empty_with_endblock { tests!( no_param_no_return: builder().build(), smallvec![], vec![], "None", - one_param_no_return: builder().identifier("x").colon().identifier("int").build(), smallvec![param("x", "int")], vec![], "None", - multi_param_no_return: builder().identifier("x").colon().identifier("int").comma().identifier("y").colon().identifier("double").build(), smallvec![param("x", "int"), param("y", "double")], vec![], "None", + one_param_no_return: builder().identifier("x").type_sep().identifier("int").build(), smallvec![param("x", "int")], vec![], "None", + multi_param_no_return: builder().identifier("x").type_sep().identifier("int").comma().identifier("y").type_sep().identifier("double").build(), smallvec![param("x", "int"), param("y", "double")], vec![], "None", no_param_simple_return: builder().build(), smallvec![], builder().operator("->").identifier("int").build(), "int", - multi_param_simple_return: builder().identifier("x").colon().identifier("int").comma().identifier("y").colon().identifier("double").build(), smallvec![param("x", "int"), param("y", "double")], builder().operator("->").identifier("int").build(), "int", + multi_param_simple_return: builder().identifier("x").type_sep().identifier("int").comma().identifier("y").type_sep().identifier("double").build(), smallvec![param("x", "int"), param("y", "double")], builder().operator("->").identifier("int").build(), "int", ); }