From 287f0019d2de5e9494ee8852de2f4ee5cb634ddc Mon Sep 17 00:00:00 2001 From: Vurv <56230599+Vurv78@users.noreply.github.com> Date: Thu, 9 Nov 2023 12:38:33 -0800 Subject: [PATCH] Add `let` keyword as an alternative to `local` --- .../gmod_wire_expression2/base/parser.lua | 2 +- .../gmod_wire_expression2/core/e2lib.lua | 34 ++++++++++--------- lua/wire/client/text_editor/modes/e2.lua | 1 + 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/base/parser.lua b/lua/entities/gmod_wire_expression2/base/parser.lua index 8d15fb017e..3e041e3a77 100644 --- a/lua/entities/gmod_wire_expression2/base/parser.lua +++ b/lua/entities/gmod_wire_expression2/base/parser.lua @@ -359,7 +359,7 @@ function Parser:Stmt() return Node.new(NodeVariant.Const, { name, value }, trace:stitch(self:Prev().trace)) end - local is_local, var = self:Consume(TokenVariant.Keyword, Keyword.Local), self:Consume(TokenVariant.Ident) + local is_local, var = self:Consume(TokenVariant.Keyword, Keyword.Local) or self:Consume(TokenVariant.Keyword, Keyword.Let), self:Consume(TokenVariant.Ident) if not var then self:Assert(not is_local, "Invalid operator (local) must be used for variable declaration.") else diff --git a/lua/entities/gmod_wire_expression2/core/e2lib.lua b/lua/entities/gmod_wire_expression2/core/e2lib.lua index 64864fbc50..de809a1951 100644 --- a/lua/entities/gmod_wire_expression2/core/e2lib.lua +++ b/lua/entities/gmod_wire_expression2/core/e2lib.lua @@ -374,38 +374,40 @@ local Keyword = { Else = 3, -- ``local`` Local = 4, + -- ``let`` + Let = 5, -- ``const`` - Const = 5, + Const = 6, -- ``while`` - While = 6, + While = 7, -- ``for`` - For = 7, + For = 8, -- ``break`` - Break = 8, + Break = 9, -- ``continue`` - Continue = 9, + Continue = 10, -- ``switch`` - Switch = 10, + Switch = 11, -- ``case`` - Case = 11, + Case = 12, -- ``default`` - Default = 12, + Default = 13, -- ``foreach`` - Foreach = 13, + Foreach = 14, -- ``function`` - Function = 14, + Function = 15, -- ``return`` - Return = 15, + Return = 16, -- ``#include`` - ["#Include"] = 16, + ["#Include"] = 17, -- ``try`` - Try = 17, + Try = 18, -- ``catch`` - Catch = 18, + Catch = 19, -- ``do`` - Do = 19, + Do = 20, -- ``event`` - Event = 20 + Event = 21 } E2Lib.Keyword = Keyword diff --git a/lua/wire/client/text_editor/modes/e2.lua b/lua/wire/client/text_editor/modes/e2.lua index 8f48c702e1..20cd0da029 100644 --- a/lua/wire/client/text_editor/modes/e2.lua +++ b/lua/wire/client/text_editor/modes/e2.lua @@ -29,6 +29,7 @@ local keywords = { ["function"] = { [true] = true }, ["return"] = { [true] = true }, ["local"] = { [true] = true }, + ["let"] = { [true] = true }, ["const"] = { [true] = true }, ["try"] = { [true] = true }, ["do"] = { [true] = true },