Releases: dev-kas/virtlang-go
v4.0.1
VirtLang v4.0.0
VirtLang-Go v4.0.0 Release Notes: Rich Error Objects, Robust Environments, and String Refinements
We are proud to announce the release of VirtLang-Go v4.0.0! This major version introduces significant enhancements to userland error handling, refines core internal data structures for robustness and thread-safety, and improves the representation of string literals for consumers of the engine's token stream.
This release includes several breaking changes aimed at improving the developer experience, API consistency, and language capabilities. Please review the "Breaking Changes & Migration Guide" carefully.
🚀 Major Userland Enhancement
- Structured Error Objects in
try...catch
:- Benefit: Error handling in VirtLang scripts is now far more powerful and informative.
- Details: The variable bound in a
catch (e)
block is no longer a simple string. It is now a VirtLang object with the following properties:e.message
: (String) The textual description of the error.e.stack
: (Array) An array of stack frame objects, where each frame is an object like{ name: string, file: string, line: number }
, representing the call stack at the point the error was thrown. This leverages the debugger engine's snapshot capabilities.
- Impact (Userland Breaking Change): Scripts using
try...catch
must be updated to accesse.message
for the error string, and can now programmatically inspecte.stack
for detailed diagnostics. - Example:
// Old (v3.x) // try { foo() } catch e { print(e) /* e is a string */ } // New (v4.0.0) try { foo() } catch e { print("Error:", e.message) print("Stack Trace:") for (let frame in e.stack) { print(strings.format(" at %s (%s:%v)", frame.name, frame.file, frame.line)) } }
⚙️ Core Engine & API Enhancements (Go Consumers)
-
Refined String Token Literals (Lexer):
- Benefit: Consumers of the token stream (e.g., tools built on VirtLang-Go, or direct Go API users) now receive string content without surrounding delimiters, simplifying processing.
- Details: The
Literal
field oflexer.Token
for string types (lexer.String
) now contains the raw, unescaped string content itself. The surrounding quotes ("
or'
) are no longer part of theToken.Literal
value. (String unescaping itself was introduced in v3.4.0). - Impact (Go API Breaking Change): Go code that directly consumes tokens from
lexer.Tokenize()
and expected string literals to include their original quotes will need to be adjusted.
-
Environment Package Refactoring (
environment
):- Benefit: Improved internal consistency and a step towards thread-safety for environment operations.
- Details:
environment.NewEnvironment()
now returns*Environment
(a pointer) instead ofEnvironment
(a value).- All methods on
Environment
now have*Environment
as their receiver type. - The internal
Environment.Variables
map now stores*shared.RuntimeValue
(pointers to runtime values). - A
sync.RWMutex
has been added to theEnvironment
struct, and its methods now use this mutex to protect concurrent access to variables and constants.
- Impact (Go API Breaking Change): Go code directly using the
environment
package must be updated:- Calls to
environment.NewEnvironment()
will now receive a pointer. - Functions or struct fields expecting
environment.Environment
will need to be changed to*environment.Environment
. - Direct access to
env.Variables
will yield*shared.RuntimeValue
.
- Calls to
🐛 Bug Fixes & Other Refinements
- Correct String Concatenation (
+
operator):- Fixed an issue where string concatenation could incorrectly include quote characters from the internal representation. It now correctly concatenates the actual string content.
- Improved Internal
environment.DeepCopy
:- The deep copy logic for environments has been updated to correctly handle the new pointer-based storage in
Environment.Variables
, ensuring true isolation for debugger snapshots.
- The deep copy logic for environments has been updated to correctly handle the new pointer-based storage in
- Enhanced
helpers.IsTruthy
for Strings:- Now correctly determines truthiness based on the raw string content (empty string is falsy, non-empty is truthy), consistent with the new string token literal representation.
- Corrected Member Expression Key Handling:
- Minor refinements in
evalMemberExpr
for handling string keys in computed member access, aligning with the raw string content from tokens.
- Minor refinements in
⚠️ Breaking Changes & Migration Guide Summary
-
Userland:
try...catch
Error Variable:- Change: Error variable
e
incatch(e)
is now an object ({message: string, stack: array[]}
). - Migration: Update
catch
blocks to usee.message
to access the error string ande.stack
for stack trace information.
- Change: Error variable
-
Go API:
environment.NewEnvironment
&Environment
Type:- Change:
environment.NewEnvironment()
returns*Environment
.Environment
methods use*Environment
receivers. - Migration: Update Go code to use
*environment.Environment
whereenvironment.Environment
(value type) was previously used.
- Change:
-
Go API: Lexer String Token Literals:
- Change:
lexer.Token.Literal
for strings no longer includes outer quotes. - Migration: Adjust Go code consuming tokens to work with raw string content.
- Change:
-
Prerequisite Breaking Changes from v3.4.0 (Assumed):
- String literals now interpret standard escape sequences (e.g.,
\n
,\t
). Literal backslashes need to be\\
. - The AST constant for "greater than or equal to" is
ast.GreaterThanEqual
(>="
).
- String literals now interpret standard escape sequences (e.g.,
Testing
- Existing test suites have been updated to reflect the new string literal representation, environment API, and the structure of caught error objects.
- Tests for string concatenation and other affected evaluator logic have been verified.
Upgrade Notes
- This is a MAJOR version update due to the significant userland and Go API breaking changes.
- All users and Go API consumers are strongly encouraged to upgrade and adapt their code according to the migration guide. These changes lay a foundation for a more robust, predictable, and developer-friendly engine.
Acknowledgements
Continued dedication from @dev-kas has brought VirtLang-Go to this pivotal v4.0.0 release. These core improvements significantly enhance the language engine's capabilities and the experience for both scriptwriters and Go developers integrating with VirtLang-Go!
VirtLang v3.4.0
VirtLang v3.4.0 Release Notes: Enhanced String Literal Processing with Escape Sequence Support
We are pleased to announce the release of VirtLang v3.4.0! This version significantly enhances the capabilities of string literals within the VirtLang language by introducing comprehensive support for escape sequences.
This much-anticipated update allows developers to embed special characters like newlines, tabs, carriage returns, and even Unicode characters directly within their string literals, making string manipulation more intuitive and powerful.
Major Features & Enhancements
- Full Escape Sequence Support in String Literals (Lexer):
-
Benefit: Developers can now define strings containing special characters (e.g., newlines, tabs, quotes) using standard escape sequences, leading to more readable and expressive code.
-
Details: The VirtLang-Go lexer has been upgraded to correctly parse and unescape the following sequences within string literals (both single-quoted
'...'
and double-quoted"..."
):\n
: Newline\t
: Tab\r
: Carriage Return\b
: Backspace (Note: actual behavior in output might depend on terminal/display)\f
: Form Feed (Note: actual behavior in output might depend on terminal/display)\\
: Backslash\"
: Double Quote (within a double-quoted string)\'
: Single Quote (within a single-quoted string)\uXXXX
: Unicode character specified by 4 hexadecimal digits (e.g.,"\u2388"
for Helm symbol Helm symbol).- (Note: Octal escapes like
\033
are not currently part of this update but may be considered in the future.)
-
Implementation:
- A new internal helper function
lexer.UnescapeString(s string)
has been introduced, utilizingstrconv.Unquote
for robust unescaping. - The lexer's string tokenization logic now correctly identifies and processes these escape sequences, ensuring the
Token.Literal
for string tokens contains the actual unescaped characters (while still being wrapped in its original quotes for consistency if it was originally quoted). - Multi-line strings are also correctly handled, with escape sequences processed per line before rejoining.
- A new internal helper function
-
Example:
let greeting = "Hello,\n\tWorld! \"Welcome\" to VirtLang \u2728."; // The 'greeting' variable will now actually contain a newline, a tab, // an embedded double quote, and the sparkles Unicode character. let singleQuotes = 'It\'s a \u263A day!'; // 'singleQuotes' will contain an embedded single quote and a smiley face.
-
Core Lexer Enhancements
- String Tokenization Logic (
lexer/lexer.go
):- The loop for consuming string content now correctly handles escaped quote characters (
\"
,\'
) to prevent premature termination of the string token. - After collecting the raw string content (between the opening and closing quotes), it now processes this content line-by-line (handling
\r\n
and\r
as\n
), unescaping each line using the newUnescapeString
helper before constructing the final token literal. This ensures correct unescaping even in multi-line raw strings. - Improved error reporting for invalid escape sequences within strings, leveraging errors from
strconv.Unquote
.
- The loop for consuming string content now correctly handles escaped quote characters (
Testing
- New Lexer Tests (
lexer/lexer_test.go
):- Added a dedicated test suite
TestUnescapeString
to validate the behavior of the newlexer.UnescapeString
helper function with various inputs, including simple strings, direct unquotes, multiple escape sequences, empty strings, and invalid sequences. - Expanded
TestTokenize
with new test cases specifically covering:- Basic escape sequences (
\n
,\t
,\r
). - Strings with multiple mixed escape sequences.
- Strings containing all supported escape sequences (
\n
,\t
,\r
,\b
,\f
,\\
,\"
,\'
). - Unicode escape sequences (
\uXXXX
). - Previously problematic cases like strings containing literal newlines (CRLF) are now also correctly tokenized with their content unescaped (newlines preserved).
- Basic escape sequences (
- Added a dedicated test suite
Known Issues and Limitations
- Octal Escapes: Standard octal escape sequences (e.g.,
\033
) are not currently supported. - Backspace/Formfeed Display: The actual rendering of
\b
(backspace) and\f
(form feed) is terminal/environment dependent and might not always produce a visible effect as expected in all output contexts.
Upgrade Notes
- This release significantly changes how string literals are processed by the lexer.
- Potential Behavior Change: If your existing VirtLang-Go code contained string literals with character sequences that happen to look like escape sequences (e.g., a literal
\
followed by ann
like"\\n"
) but were intended to be literal backslashes and 'n's, these will now be interpreted as actual newline characters.- To represent a literal backslash, you must now use
\\
. For example, to get the string\n
, you would write"\\n"
.
- To represent a literal backslash, you must now use
- It is highly recommended to review any string literals in your existing code that use backslashes to ensure they behave as intended with the new unescaping logic.
- This change makes VirtLang-Go strings more aligned with conventions in many other programming languages.
Getting Started
- Update to VirtLang-Go v3.4.0.
- You can now freely use standard escape sequences in your string literals.
Acknowledgements
A significant thank you to @dev-kas for implementing this crucial enhancement to string handling in VirtLang-Go, greatly improving its expressiveness and usability!
v3.3.7
v3.3.6
Full Changelog: v3.3.5...v3.3.6
v3.3.5
Full Changelog: v3.3.4...v3.3.5
v3.3.4
Full Changelog: v3.3.3...v3.3.4
v3.3.3
Full Changelog: v3.3.2...v3.3.3
v3.3.2
Full Changelog: v3.3.1...v3.3.2
VirtLang v3.3.1
Full Changelog: v3.3.0...v3.3.1