From 2afafd2bf9ae0390ce1ce6b0577701afe1a73d64 Mon Sep 17 00:00:00 2001 From: Alain Zscheile Date: Sat, 20 May 2023 23:33:24 +0200 Subject: [PATCH] get rid of the special keyword syntax --- README.md | 8 ++++---- crates/wafl-parser/src/lex.rs | 24 ++++++++---------------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 3855c40..ce3682e 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ ## Syntax ``` -[@pub] [@final] name ["{" args... "}"] = [@cfe] { +[pub] [final] name ["{" args... "}"] = [cfe] { content; content; etc; @@ -19,8 +19,8 @@ ## Attributes of Code Objects -- `@final` prevents overwriting and basically marks a root -- `@cfe` allows an object to access the continuation and omits the default return +- `final` prevents overwriting and basically marks a root +- `cfe` allows an object to access the continuation and omits the default return ## Early vs late binding @@ -60,7 +60,7 @@ with package-lock files or such. Packages (packaged module trees) would then be ``` # 1. - @final main { args env } = { + final main { args env } = { std.io.writeln "Hello World!"; 0 }; diff --git a/crates/wafl-parser/src/lex.rs b/crates/wafl-parser/src/lex.rs index 31c64e8..ecf370c 100644 --- a/crates/wafl-parser/src/lex.rs +++ b/crates/wafl-parser/src/lex.rs @@ -131,21 +131,6 @@ impl<'a> Iterator for Lexer<'a> { } } } - '@' => { - // keyword - let ident = self.select_text(1, |i| !i.is_alphanumeric()); - return Some(( - loc, - match &ident[1..] { - "cfe" => Token::CtrlFlowEdit, - "defer" => Token::Defer, - "final" => Token::Final, - "module" => Token::Module, - "pub" => Token::Public, - _ => Token::Unknown(ident), - }, - )); - } '0'..='9' => { // integer, unknown base up to 36 let start = self.s; @@ -191,7 +176,14 @@ impl<'a> Iterator for Lexer<'a> { } _ if unicode_ident::is_xid_start(x) => { let ident = self.select_text(0, |i| !unicode_ident::is_xid_continue(i)); - return Some((loc, Token::Identifier(ident))); + return Some((loc, match ident { + "cfe" => Token::CtrlFlowEdit, + "defer" => Token::Defer, + "final" => Token::Final, + "module" => Token::Module, + "pub" => Token::Public, + _ => Token::Identifier(ident), + })); } _ if x.is_whitespace() => { self.eat(x.len_utf8());