From 370aac43951873468393ce08bd98948b2096921a Mon Sep 17 00:00:00 2001 From: Soispha Date: Tue, 19 Dec 2023 17:27:13 +0100 Subject: [PATCH] feat(trixy-lang_parser): Add support for Type This includes rust like generic types like: ``` Option Result ``` --- trixy/trixy-lang_parser/docs/grammar.ebnf | 3 +- trixy/trixy-lang_parser/docs/grammar.pdf | Bin 45979 -> 49162 bytes trixy/trixy-lang_parser/example/full.tri | 2 +- .../trixy-lang_parser/src/command_spec/mod.rs | 2 +- .../src/command_spec/unchecked.rs | 10 +++++-- trixy/trixy-lang_parser/src/error.rs | 2 +- trixy/trixy-lang_parser/src/lexing/mod.rs | 8 ++++++ .../trixy-lang_parser/src/lexing/tokenizer.rs | 8 +++++- .../src/parsing/unchecked.rs | 26 ++++++++++++++++-- 9 files changed, 51 insertions(+), 10 deletions(-) diff --git a/trixy/trixy-lang_parser/docs/grammar.ebnf b/trixy/trixy-lang_parser/docs/grammar.ebnf index 05ffca8..abe1be8 100644 --- a/trixy/trixy-lang_parser/docs/grammar.ebnf +++ b/trixy/trixy-lang_parser/docs/grammar.ebnf @@ -11,8 +11,9 @@ Function = "fn" Identifier "(" [NamedType {"," NamedType }] ")" [ "->" Type ] "; Namespace = "nasp" Identifier "{" {Function | Namespace | Enumeration | Structure} "}" ; Structure = "struct" Identifier "{" [NamedType {"," NamedType } [","]] "}" ";"; Enumeration = "enum" Identifier "{" [Identifier {"," Identifier} [","]] "}" ";"; -Identifier = CHARACTER { NUMBER | CHARACTER } ; +Identifier = (CHARACTER | "_") { NUMBER | CHARACTER | "_" } ; NamedType = Identifier ":" Type; +Type = Identifier ["<" Type {"," Type} ">"]; # (* # vim: ft=ebnf diff --git a/trixy/trixy-lang_parser/docs/grammar.pdf b/trixy/trixy-lang_parser/docs/grammar.pdf index bf84bb08e785d71833d7fc4ccb2b30ba7b287bfd..97ec4e93d5743ec1bc11a37659b8ab94bc120a87 100644 GIT binary patch delta 8022 zcmZvhbx<6&RQqPtRkN4cyOWu8Q0Ma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#5Y4^bebr!OQJ9shW- zwqa6B@@v^ot>ud`(gEGUk6({*ty^N#TldrseXp4#o;>l}F$(bY^3%`@i70ayP5wn- zSGJz<*jA|>R*NeVI@`j3n_WMN7(KtA5BvOwv%`gxPucFwlptktFS;{%4b6r?07;!r zE+r*+uk8bOw9gD(7his~RqxZtl}r5L%p){bG~qqPEm&ANlXOo}d(HU>6*fR}XuZFk zl61_;cQH=A10;;fW;8DC1q>~O3-UD27~{~e<)~a(@?=~R^pRJF{i||!O(5+SMgf=+ zF+|hujTKnnuH5K?4Pan6_}`v}i;D*sA^5MELkv-Hwsrv{Q2)D-1{+{TT9`1yExZ5$ z%ykPl8bt;G(03jFj;t7=AJFR&O0cKOla_l%6{(n=^BPE}CipJYj=fqa^4U9!O>dLK z0pE*=Uh*T#Dd8Y5T3m;3n;ePGcmvN#DioP1, - pub output: Option, // Will later become an Type + pub output: Option, } #[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] @@ -73,5 +73,11 @@ pub struct Enumeration { #[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] pub struct NamedType { pub name: Token, // Will later become an Identifier - pub r#type: Token, // Will later become an Type + pub r#type: Type, +} + +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] +pub struct Type { + pub identifier: Token, // Will later become an Identifier + pub generic_args: Vec, } diff --git a/trixy/trixy-lang_parser/src/error.rs b/trixy/trixy-lang_parser/src/error.rs index fcf441d..3211a78 100644 --- a/trixy/trixy-lang_parser/src/error.rs +++ b/trixy/trixy-lang_parser/src/error.rs @@ -89,7 +89,7 @@ impl ErrorContext { pub fn from_index(start: usize, orginal_file: &str) -> Self { let span = TokenSpan { start, - end: start, + end: start + 1, }; Self::from_span(span, orginal_file) } diff --git a/trixy/trixy-lang_parser/src/lexing/mod.rs b/trixy/trixy-lang_parser/src/lexing/mod.rs index a8ecd6c..d77962a 100644 --- a/trixy/trixy-lang_parser/src/lexing/mod.rs +++ b/trixy/trixy-lang_parser/src/lexing/mod.rs @@ -121,6 +121,8 @@ pub enum TokenKind { BraceClose, ParenOpen, ParenClose, + SquareOpen, + SquareClose, /// This is not a real TokenKind, but only used for error handling Dummy, } @@ -156,6 +158,8 @@ impl Display for TokenKind { TokenKind::ParenOpen => f.write_str("PARENOPEN"), TokenKind::ParenClose => f.write_str("PARENCLOSE"), TokenKind::Dummy => f.write_str("DUMMY"), + TokenKind::SquareOpen => f.write_str("SQUAREOPEN"), + TokenKind::SquareClose => f.write_str("SQUARECLOSE"), } } } @@ -211,6 +215,10 @@ macro_rules! token { [,] => { $crate::lexing::TokenKind::Comma }; [Arrow] => { $crate::lexing::TokenKind::Arrow }; [->] => { $crate::lexing::TokenKind::Arrow }; + [SquareOpen] => { $crate::lexing::TokenKind::SquareOpen }; + [<] => { $crate::lexing::TokenKind::SquareOpen }; + [SquareClose] => { $crate::lexing::TokenKind::SquareClose }; + [>] => { $crate::lexing::TokenKind::SquareClose}; [BraceOpen] => { $crate::lexing::TokenKind::BraceOpen }; // [{] => { $crate::lexing::TokenKind::BraceOpen }; [BraceClose] => { $crate::lexing::TokenKind::BraceClose }; diff --git a/trixy/trixy-lang_parser/src/lexing/tokenizer.rs b/trixy/trixy-lang_parser/src/lexing/tokenizer.rs index 3e78ed7..a4eb885 100644 --- a/trixy/trixy-lang_parser/src/lexing/tokenizer.rs +++ b/trixy/trixy-lang_parser/src/lexing/tokenizer.rs @@ -60,8 +60,14 @@ impl<'a> Tokenizer<'a> { ':' => (TokenKind::Colon, 1), ';' => (TokenKind::Semicolon, 1), ',' => (TokenKind::Comma, 1), + '<' => (TokenKind::SquareOpen, 1), + '>' => (TokenKind::SquareClose, 1), '-' => tokenize_arrow(self.remaining_text)?, - c @ '_' | c if c.is_alphanumeric() => tokenize_ident(self.remaining_text)?, + + // can't use a OR (`|`) here, as the guard takes precedence + c if c.is_alphabetic() => tokenize_ident(self.remaining_text)?, + '_' => tokenize_ident(self.remaining_text)?, + other => return Err(LexingError::UnknownCharacter(other)), }; diff --git a/trixy/trixy-lang_parser/src/parsing/unchecked.rs b/trixy/trixy-lang_parser/src/parsing/unchecked.rs index 07f9423..a477696 100644 --- a/trixy/trixy-lang_parser/src/parsing/unchecked.rs +++ b/trixy/trixy-lang_parser/src/parsing/unchecked.rs @@ -1,6 +1,6 @@ use crate::{ command_spec::unchecked::{ - CommandSpec, Declaration, Enumeration, Function, NamedType, Structure, + CommandSpec, Declaration, Enumeration, Function, NamedType, Structure, Type, }, error::ErrorContext, lexing::{Token, TokenKind, TokenStream}, @@ -73,6 +73,26 @@ impl Parser { } } + fn parse_type(&mut self) -> Result { + let identifier = self.expect(token![Ident])?; + + let mut generic_args = vec![]; + if self.expect_peek(token![<]) { + self.expect(token![<])?; + if self.expect_peek(token![Ident]) { + generic_args.push(self.parse_type()?); + } + while self.expect_peek(token![Comma]) { + generic_args.push(self.parse_type()?); + } + self.expect(token![>])?; + } + Ok(Type { + identifier, + generic_args, + }) + } + fn parse_namespace(&mut self) -> Result, ParsingError> { self.expect(token![nasp])?; let namespace_name = self.expect(token![Ident])?; @@ -140,7 +160,7 @@ impl Parser { fn parse_named_type(&mut self) -> Result { let name = self.expect(token![Ident])?; self.expect(token![Colon])?; - let r#type = self.expect(token![Ident])?; + let r#type = self.parse_type()?; Ok(NamedType { name, r#type }) } @@ -162,7 +182,7 @@ impl Parser { let mut output_type = None; if self.expect_peek(token![->]) { self.expect(token![->])?; - output_type = Some(self.expect(token![Ident])?); + output_type = Some(self.parse_type()?); } self.expect(token![;])?; Ok(Function {