Variable reference from $VAR to @VAR to avoid object conflict

This commit is contained in:
Martino Ferrari
2026-01-30 01:01:47 +01:00
parent 0cbbf5939a
commit c3f4d8f465
17 changed files with 52 additions and 39 deletions

View File

@@ -15,8 +15,8 @@ func TestFormatterVariables(t *testing.T) {
#var MyStr: string | "A" = "default"
+Obj = {
Field1 = $MyInt
Field2 = $MyStr
Field1 = @MyInt
Field2 = @MyStr
}
`
p := parser.NewParser(content)
@@ -35,11 +35,10 @@ func TestFormatterVariables(t *testing.T) {
t.Errorf("Variable MyInt formatted incorrectly. Got:\n%s", output)
}
// Note: parser adds space after each token in TypeExpr
// string | "A" -> "string | \"A\""
// string | "A" -> "string | \"A\""
if !strings.Contains(output, "#var MyStr: string | \"A\" = \"default\"") {
t.Errorf("Variable MyStr formatted incorrectly. Got:\n%s", output)
}
if !strings.Contains(output, "Field1 = $MyInt") {
t.Errorf("Variable reference $MyInt formatted incorrectly. Got:\n%s", output)
}
}
if !strings.Contains(output, "Field1 = @MyInt") {
t.Errorf("Variable reference @MyInt formatted incorrectly. Got:\n%s", output)
}}

View File

@@ -38,7 +38,7 @@ func TestLSPAppTestRepro(t *testing.T) {
A = {
DataSource = DDB
Type = uint32
Value = $Value
Value = @Value
}
}
OutputSignals = {
@@ -75,7 +75,7 @@ func TestLSPAppTestRepro(t *testing.T) {
output := buf.String()
// Check Unresolved Variable
if !strings.Contains(output, "Unresolved variable reference: '$Value'") {
if !strings.Contains(output, "Unresolved variable reference: '@Value'") {
t.Error("LSP missing unresolved variable error")
}

View File

@@ -151,7 +151,7 @@ diags := params["diagnostics"].([]interface{})
foundOrdering = true
t.Log("Found Ordering error")
}
if strings.Contains(m, "Unresolved variable reference: '$Value'") {
if strings.Contains(m, "Unresolved variable reference: '@Value'") {
foundVariable = true
t.Log("Found Variable error")
}

View File

@@ -41,7 +41,7 @@ func TestLSPDiagnosticsAppTest(t *testing.T) {
A = {
DataSource = DDB
Type = uint32
Value = $Value
Value = @Value
}
}
OutputSignals = {
@@ -87,9 +87,9 @@ func TestLSPDiagnosticsAppTest(t *testing.T) {
t.Fatal("LSP did not publish diagnostics")
}
// 1. Check Unresolved Variable Error ($Value)
if !strings.Contains(output, "Unresolved variable reference: '$Value'") {
t.Error("Missing diagnostic for unresolved variable '$Value'")
// 1. Check Unresolved Variable Error (@Value)
if !strings.Contains(output, "Unresolved variable reference: '@Value'") {
t.Error("Missing diagnostic for unresolved variable '@Value'")
}
// 2. Check INOUT Ordering Error (Signal A consumed but not produced)

View File

@@ -16,7 +16,7 @@ func TestLSPHoverVariable(t *testing.T) {
content := `
#var MyInt: int = 123
+Obj = {
Field = $MyInt
Field = @MyInt
}
`
uri := "file://hover_var.marte"
@@ -47,8 +47,8 @@ func TestLSPHoverVariable(t *testing.T) {
t.Errorf("Hover def missing default value. Got: %s", contentDef)
}
// 2. Hover on Reference ($MyInt)
// Line 4 (index 3). $MyInt is at col 12.
// 2. Hover on Reference (@MyInt)
// Line 4 (index 3). @MyInt is at col 12.
paramsRef := lsp.HoverParams{
TextDocument: lsp.TextDocumentIdentifier{URI: uri},
Position: lsp.Position{Line: 3, Character: 12},

View File

@@ -15,7 +15,7 @@ func TestLSPVariableRefs(t *testing.T) {
content := `
#var MyVar: int = 1
+Obj = {
Field = $MyVar
Field = @MyVar
}
`
uri := "file://vars.marte"
@@ -29,11 +29,11 @@ func TestLSPVariableRefs(t *testing.T) {
lsp.Tree.ResolveReferences()
// 1. Definition from Usage
// Line 4: " Field = $MyVar"
// $ is at col 12 (0-based) ?
// Line 4: " Field = @MyVar"
// @ is at col 12 (0-based) ?
// " Field = " is 4 + 6 + 3 = 13 chars?
// 4 spaces. Field (5). " = " (3). 4+5+3 = 12.
// So $ is at 12.
// So @ is at 12.
paramsDef := lsp.DefinitionParams{
TextDocument: lsp.TextDocumentIdentifier{URI: uri},
Position: lsp.Position{Line: 3, Character: 12},

View File

@@ -17,9 +17,9 @@ func TestOperators(t *testing.T) {
#var S2: string = "World"
+Obj = {
Math = $A + $B
Precedence = $A + $B * 2
Concat = $S1 .. " " .. $S2
Math = @A + @B
Precedence = @A + @B * 2
Concat = @S1 .. " " .. @S2
}
`
// Check Parser

View File

@@ -15,7 +15,7 @@ func TestRegexVariable(t *testing.T) {
#var BadIP: string & =~"^[0-9.]+$" = "abc"
+Obj = {
IP = $IP
IP = @IP
}
`
// Test Validator

View File

@@ -44,7 +44,7 @@ func TestVariableValidation(t *testing.T) {
#var MyStr: string = "hello"
+MyPID = {
Class = PIDGAM
Kp = $MyStr
Kp = @MyStr
Ki = 0.0
Kd = 0.0
}
@@ -79,7 +79,7 @@ func TestVariableValidation(t *testing.T) {
#var MyGain: float = 1.5
+MyPID = {
Class = PIDGAM
Kp = $MyGain
Kp = @MyGain
Ki = 0.0
Kd = 0.0
}

View File

@@ -16,8 +16,8 @@ func TestVariables(t *testing.T) {
+Obj = {
Class = Test
Field1 = $MyInt
Field2 = $MyStr
Field1 = @MyInt
Field2 = @MyStr
}
`
// Test Parsing