Parser skips the as keyword for @use and @forward #3

Closed
opened 2024-03-08 21:25:04 +01:00 by wkillerud · 1 comment
wkillerud commented 2024-03-08 21:25:04 +01:00 (Migrated from github.com)

Hello 👋

I've been testing @lezer/sass and ran into a limitation with @use and @forward (otherwise it's worked swimmingly so far – love the support for both dialects). Both @use and @forward have the optional as keyword, where @use has a special case *.

I don't have any prior experience with grammars or parsers, but I've attached a patch. It seemed to work for me locally if you want to take a look. I can open a PR if you prefer.

From 25fe2cffaf7224be4056ef25437d3a6c9ef95488 Mon Sep 17 00:00:00 2001
From: William Killerud <1223410+wkillerud@users.noreply.github.com>
Date: Fri, 8 Mar 2024 21:12:20 +0100
Subject: [PATCH] Add ForwardPrefix and UseAs tokens

---
 src/sass.grammar | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/sass.grammar b/src/sass.grammar
index 680bce8..7566bf7 100644
--- a/src/sass.grammar
+++ b/src/sass.grammar
@@ -48,7 +48,7 @@ IncludeStatement {
 }
 
 UseStatement {
-  @specialize[@name=use]<AtKeyword, "@use"> value (ckw<"with"> callArgList)? semi
+  @specialize[@name=use]<AtKeyword, "@use"> value (ckw<"as"> UseAs)? (ckw<"with"> callArgList)? semi
 }
 
 ExtendStatement {
@@ -60,7 +60,7 @@ RootStatement {
 }
 
 ForwardStatement {
-  @specialize[@name=forward]<AtKeyword, "@forward"> value (ckw<"hide" | "show"> commaSep<value>)* semi
+  @specialize[@name=forward]<AtKeyword, "@forward"> value (ckw<"as"> ForwardPrefix)? (ckw<"hide" | "show"> commaSep<value>)* semi
 }
 
 MixinStatement {
@@ -243,6 +243,10 @@ semi { ";" | newline | eof }
 @external tokens indentedMixins from "./tokens" { IndentedMixin, IndentedInclude }
 
 @tokens {
+	ForwardPrefix { $[a-zA-Z_-]+ "-*" }
+
+	UseAs { $[a-zA-Z_-]+  | "*" }
+
   UniversalSelector { "*" }
 
   NestingSelector { "&" }
-- 
2.39.3 (Apple Git-146)
Hello 👋 I've been testing `@lezer/sass` and ran into a limitation with `@use` and `@forward` (otherwise it's worked swimmingly so far – love the support for both dialects). Both `@use` and `@forward` have the optional `as` keyword, where `@use` has a special case `*`. - [`@use "module" as m`](https://sass-lang.com/documentation/at-rules/use/#choosing-a-namespace) - `@use "module" as *` - [`@forward "module" as m-*`](https://sass-lang.com/documentation/at-rules/forward/#adding-a-prefix) I don't have any prior experience with grammars or parsers, but I've attached a patch. It seemed to work for me locally if you want to take a look. I can open a PR if you prefer. ```diff From 25fe2cffaf7224be4056ef25437d3a6c9ef95488 Mon Sep 17 00:00:00 2001 From: William Killerud <1223410+wkillerud@users.noreply.github.com> Date: Fri, 8 Mar 2024 21:12:20 +0100 Subject: [PATCH] Add ForwardPrefix and UseAs tokens --- src/sass.grammar | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/sass.grammar b/src/sass.grammar index 680bce8..7566bf7 100644 --- a/src/sass.grammar +++ b/src/sass.grammar @@ -48,7 +48,7 @@ IncludeStatement { } UseStatement { - @specialize[@name=use]<AtKeyword, "@use"> value (ckw<"with"> callArgList)? semi + @specialize[@name=use]<AtKeyword, "@use"> value (ckw<"as"> UseAs)? (ckw<"with"> callArgList)? semi } ExtendStatement { @@ -60,7 +60,7 @@ RootStatement { } ForwardStatement { - @specialize[@name=forward]<AtKeyword, "@forward"> value (ckw<"hide" | "show"> commaSep<value>)* semi + @specialize[@name=forward]<AtKeyword, "@forward"> value (ckw<"as"> ForwardPrefix)? (ckw<"hide" | "show"> commaSep<value>)* semi } MixinStatement { @@ -243,6 +243,10 @@ semi { ";" | newline | eof } @external tokens indentedMixins from "./tokens" { IndentedMixin, IndentedInclude } @tokens { + ForwardPrefix { $[a-zA-Z_-]+ "-*" } + + UseAs { $[a-zA-Z_-]+ | "*" } + UniversalSelector { "*" } NestingSelector { "&" } -- 2.39.3 (Apple Git-146) ```
marijnh commented 2024-03-09 14:13:59 +01:00 (Migrated from github.com)

Attached patch adds support for this.

Attached patch adds support for this.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lezer/sass#3
No description provided.