From 1b8bdc0f4fb899bfb99d12c64ff24bbdf5538ef3 Mon Sep 17 00:00:00 2001 From: cinder Date: Sun, 13 Jul 2025 09:35:45 -0500 Subject: [PATCH] Improvements LslSyntax --- .../{LslSyntaxId.cs => LslSyntax.cs} | 28 ++++++++++++++----- .../Commands/Land/SyntaxIdCommand.cs | 5 ++-- 2 files changed, 24 insertions(+), 9 deletions(-) rename LibreMetaverse/{LslSyntaxId.cs => LslSyntax.cs} (95%) diff --git a/LibreMetaverse/LslSyntaxId.cs b/LibreMetaverse/LslSyntax.cs similarity index 95% rename from LibreMetaverse/LslSyntaxId.cs rename to LibreMetaverse/LslSyntax.cs index 9935596a..f7c0c959 100644 --- a/LibreMetaverse/LslSyntaxId.cs +++ b/LibreMetaverse/LslSyntax.cs @@ -38,7 +38,7 @@ using Logger = OpenMetaverse.Logger; namespace LibreMetaverse { - public class LslSyntaxId + public class LslSyntax { public enum LslCategory { @@ -65,10 +65,10 @@ namespace LibreMetaverse private const string SYNTAX_FEATURE_IDENTIFIER = "LSLSyntaxId"; private const string SYNTAX_CAPABILITY_IDENTIFIER = "LSLSyntax"; - private Dictionary _keywords = new Dictionary(); - public FrozenDictionary Keywords => _keywords.ToFrozenDictionary(); + private static Dictionary _keywords = new Dictionary(); + public static FrozenDictionary Keywords => _keywords.ToFrozenDictionary(); - private readonly GridClient _client; + private GridClient _client; private UUID _syntaxId; #region EVENTS @@ -94,8 +94,22 @@ namespace LibreMetaverse } #endregion EVENTS - - public LslSyntaxId(GridClient client) + + public LslSyntax() + { + var keywordFile = Path.Combine(Settings.RESOURCE_DIR, KEYWORDS_DEFAULT); + using (FileStream fs = new FileStream(keywordFile, FileMode.Open, FileAccess.Read)) + { + ParseFile(fs); + } + } + + public LslSyntax(GridClient client) + { + Register(client); + } + + public void Register(GridClient client) { _client = client; @@ -309,7 +323,7 @@ namespace LibreMetaverse Logger.Log($"Syntax parser exception: {e.Message}", Helpers.LogLevel.Warning); } Logger.Log($"Parsed Syntax file, added {added}/{tokens} tokens.", Helpers.LogLevel.Debug); - _keywords = keywords; + lock(_keywords) { _keywords = keywords; } OnSyntaxChanged(); } diff --git a/Programs/examples/TestClient/Commands/Land/SyntaxIdCommand.cs b/Programs/examples/TestClient/Commands/Land/SyntaxIdCommand.cs index b479a32d..7506ec85 100644 --- a/Programs/examples/TestClient/Commands/Land/SyntaxIdCommand.cs +++ b/Programs/examples/TestClient/Commands/Land/SyntaxIdCommand.cs @@ -1,4 +1,5 @@ using System.Text; +using LibreMetaverse; namespace OpenMetaverse.TestClient { @@ -13,11 +14,11 @@ namespace OpenMetaverse.TestClient public override string Execute(string[] args, UUID fromAgentID) { - var syntax = new LibreMetaverse.LslSyntaxId(Client); + var syntax = new LibreMetaverse.LslSyntax(Client); var output = new StringBuilder("LSL Tokens:"); output.AppendLine(); - foreach (var token in syntax.Keywords.Keys) + foreach (var token in LslSyntax.Keywords.Keys) { output.AppendLine(token); }