diff --git a/trixy-parser/docs/grammar.ebnf b/trixy-parser/docs/grammar.ebnf index dc1ee47..3575787 100644 --- a/trixy-parser/docs/grammar.ebnf +++ b/trixy-parser/docs/grammar.ebnf @@ -30,9 +30,9 @@ CommandSpec = {Function | Namespace | Enumeration | Structure } ; Function = {DocComment} "fn" Identifier "(" [NamedType {"," NamedType }] ")" [ "->" Type ] ";" ; -Namespace = {DocComment} "nasp" Identifier "{" {Function | Namespace | Enumeration | Structure} "}" ; -Structure = {DocComment} "struct" Identifier "{" [DocNamedType {"," DocNamedType } [","]] "}" ";"; -Enumeration = {DocComment} "enum" Identifier "{" [DocIdentifier {"," DocIdentifier} [","]] "}" ";"; +Namespace = {DocComment} "mod" Identifier "{" {Function | Namespace | Enumeration | Structure} "}" ; +Structure = {DocComment} "struct" Identifier "{" [DocNamedType {"," DocNamedType } [","]] "}"; +Enumeration = {DocComment} "enum" Identifier "{" [DocIdentifier {"," DocIdentifier} [","]] "}"; Type = Identifier ["<" Type {"," Type} ">"]; diff --git a/trixy-parser/docs/grammar.pdf b/trixy-parser/docs/grammar.pdf index 716a39f..352726b 100644 Binary files a/trixy-parser/docs/grammar.pdf and b/trixy-parser/docs/grammar.pdf differ diff --git a/trixy-parser/src/command_spec/mod.rs b/trixy-parser/src/command_spec/mod.rs index a5ec343..cd39160 100644 --- a/trixy-parser/src/command_spec/mod.rs +++ b/trixy-parser/src/command_spec/mod.rs @@ -18,6 +18,9 @@ * If not, see . */ +//! This module provides the type definitions for the parser. +//! These types are split into type-checked ones [`checked`] and the raw types [`unchecked`] + pub mod checked; pub mod unchecked; diff --git a/trixy-parser/src/lexing/mod.rs b/trixy-parser/src/lexing/mod.rs index e1a30e8..515510c 100644 --- a/trixy-parser/src/lexing/mod.rs +++ b/trixy-parser/src/lexing/mod.rs @@ -221,7 +221,7 @@ impl Display for TokenKind { pub enum Keyword { /// Start a namespace declaration #[allow(non_camel_case_types)] - nasp, + r#mod, /// Start a function declaration #[allow(non_camel_case_types)] r#fn, @@ -236,7 +236,7 @@ pub enum Keyword { impl Display for Keyword { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Keyword::nasp => f.write_str("nasp"), + Keyword::mod => f.write_str("mod"), Keyword::r#fn => f.write_str("fn"), Keyword::r#struct => f.write_str("struct"), Keyword::r#enum => f.write_str("enum"), @@ -252,7 +252,7 @@ impl Display for Keyword { /// ``` /// use trixy_lang_parser::token; /// # fn main() { -/// token![nasp]; +/// token![mod]; /// token![;]; /// token![Arrow]; /// # } @@ -280,7 +280,7 @@ macro_rules! token { [ParenClose] => { $crate::lexing::TokenKind::ParenClose }; // [)] => { $crate::lexing::TokenKind::ParenthesisClose }; - [nasp] => { $crate::lexing::TokenKind::Keyword($crate::lexing::Keyword::nasp) }; + [mod] => { $crate::lexing::TokenKind::Keyword($crate::lexing::Keyword::mod) }; [fn] => { $crate::lexing::TokenKind::Keyword($crate::lexing::Keyword::r#fn) }; [struct] => { $crate::lexing::TokenKind::Keyword($crate::lexing::Keyword::r#struct) }; [enum] => { $crate::lexing::TokenKind::Keyword($crate::lexing::Keyword::r#enum) }; @@ -322,6 +322,6 @@ mod tests { token_macro_test!(tok_expands_to_arrow, ->, => TokenKind::Arrow); token_macro_test!(tok_expands_to_semicolon, Semicolon, => TokenKind::Semicolon); - token_macro_test!(tok_expands_to_nasp, nasp, => TokenKind::Keyword(crate::lexing::Keyword::nasp)); + token_macro_test!(tok_expands_to_mod, mod, => TokenKind::Keyword(crate::lexing::Keyword::mod)); token_macro_test!(tok_expands_to_fn, fn, => TokenKind::Keyword(crate::lexing::Keyword::r#fn)); } diff --git a/trixy-parser/src/lexing/test.rs b/trixy-parser/src/lexing/test.rs index 7eb32fe..4ae9d8c 100644 --- a/trixy-parser/src/lexing/test.rs +++ b/trixy-parser/src/lexing/test.rs @@ -27,7 +27,7 @@ use pretty_assertions::assert_eq; #[test] fn test_lexing_trixy() { let input = " -nasp commands { +mod commands { fn expect(event: String) -> String; } "; @@ -36,7 +36,7 @@ nasp commands { let tokens = vec![ Token { span: TokenSpan { start: 1, end: 5 }, - kind: TokenKind::Keyword(Keyword::nasp), + kind: TokenKind::Keyword(Keyword::mod), }, Token { span: TokenSpan { start: 6, end: 14 }, @@ -102,8 +102,8 @@ nasp commands { #[test] fn test_failing_lexing() { let input = " -nasp trinitrix { - nasp - commands { +mod trinitrix { + mod - commands { fn hi(strings: String) -> String; } } @@ -119,7 +119,7 @@ nasp trinitrix { #[test] fn test_multiple_tokens() { let input = " -nasp nasp {{ +mod mod {{ }} "; let token_stream = TokenStream::lex(input).unwrap(); @@ -127,11 +127,11 @@ nasp nasp {{ let tokens = vec![ Token { span: TokenSpan { start: 1, end: 5 }, - kind: TokenKind::Keyword(Keyword::nasp), + kind: TokenKind::Keyword(Keyword::mod), }, Token { span: TokenSpan { start: 6, end: 10 }, - kind: TokenKind::Keyword(Keyword::nasp), + kind: TokenKind::Keyword(Keyword::mod), }, Token { span: TokenSpan { start: 11, end: 12 }, @@ -162,7 +162,7 @@ nasp nasp {{ fn test_comments() { let input = " // Some comment - nasp nasp {{ + mod mod {{ }} // NOTE(@soispha): We do not support nested multi line comments <2023-12-16> @@ -182,11 +182,11 @@ fn test_comments() { let tokens = vec![ Token { span: TokenSpan { start: 33, end: 37 }, - kind: TokenKind::Keyword(Keyword::nasp), + kind: TokenKind::Keyword(Keyword::mod), }, Token { span: TokenSpan { start: 38, end: 42 }, - kind: TokenKind::Keyword(Keyword::nasp), + kind: TokenKind::Keyword(Keyword::mod), }, Token { span: TokenSpan { start: 43, end: 44 }, diff --git a/trixy-parser/src/lexing/tokenizer.rs b/trixy-parser/src/lexing/tokenizer.rs index be10db1..2c2a902 100644 --- a/trixy-parser/src/lexing/tokenizer.rs +++ b/trixy-parser/src/lexing/tokenizer.rs @@ -203,7 +203,7 @@ fn tokenize_ident(text: &str) -> Result<(TokenKind, usize), LexingError> { // Filter out keywords let tokenkind = match got { - "nasp" => TokenKind::Keyword(Keyword::nasp), + "mod" => TokenKind::Keyword(Keyword::mod), "fn" => TokenKind::Keyword(Keyword::r#fn), "struct" => TokenKind::Keyword(Keyword::r#struct), "enum" => TokenKind::Keyword(Keyword::r#enum), diff --git a/trixy-parser/src/parsing/unchecked/mod.rs b/trixy-parser/src/parsing/unchecked/mod.rs index 69781bb..65450b3 100644 --- a/trixy-parser/src/parsing/unchecked/mod.rs +++ b/trixy-parser/src/parsing/unchecked/mod.rs @@ -234,7 +234,6 @@ impl Parser { } } self.expect(token![BraceClose])?; - self.expect(token![;])?; Ok(Enumeration { identifier, states, @@ -261,7 +260,6 @@ impl Parser { } } self.expect(token![BraceClose])?; - self.expect(token![;])?; Ok(Structure { identifier: name,