File tree Expand file tree Collapse file tree 3 files changed +22
-5
lines changed
ownlang-core/src/main/java/com/annimon/ownlang/exceptions
ownlang-parser/src/main/java/com/annimon/ownlang/parser Expand file tree Collapse file tree 3 files changed +22
-5
lines changed Original file line number Diff line number Diff line change 1
1
package com .annimon .ownlang .exceptions ;
2
2
3
+ import com .annimon .ownlang .util .Range ;
4
+
3
5
public final class VariableDoesNotExistsException extends OwnLangRuntimeException {
4
6
5
7
private final String variable ;
6
8
7
- public VariableDoesNotExistsException (String variable ) {
8
- super ("Variable " + variable + " does not exists" );
9
+ public VariableDoesNotExistsException (String variable , Range range ) {
10
+ super ("Variable " + variable + " does not exists" , range );
9
11
this .variable = variable ;
10
12
}
11
13
Original file line number Diff line number Diff line change @@ -853,12 +853,15 @@ private Node variable() {
853
853
854
854
private Node qualifiedName () {
855
855
// var || var.key[index].key2
856
+ final var startTokenIndex = index ;
856
857
final Token current = get (0 );
857
858
if (!match (TokenType .WORD )) return null ;
858
859
859
860
final List <Node > indices = variableSuffix ();
860
861
if (indices == null || indices .isEmpty ()) {
861
- return new VariableExpression (current .text ());
862
+ final var variable = new VariableExpression (current .text ());
863
+ variable .setRange (getRange (startTokenIndex , index - 1 ));
864
+ return variable ;
862
865
}
863
866
return new ContainerAccessExpression (current .text (), indices );
864
867
}
Original file line number Diff line number Diff line change 3
3
import com .annimon .ownlang .exceptions .VariableDoesNotExistsException ;
4
4
import com .annimon .ownlang .lib .ScopeHandler ;
5
5
import com .annimon .ownlang .lib .Value ;
6
+ import com .annimon .ownlang .util .Range ;
7
+ import com .annimon .ownlang .util .SourceLocation ;
6
8
7
9
/**
8
10
*
9
11
* @author aNNiMON
10
12
*/
11
- public final class VariableExpression extends InterruptableNode implements Accessible {
13
+ public final class VariableExpression extends InterruptableNode implements Accessible , SourceLocation {
12
14
13
15
public final String name ;
16
+ private Range range ;
14
17
15
18
public VariableExpression (String name ) {
16
19
this .name = name ;
17
20
}
18
21
22
+ public void setRange (Range range ) {
23
+ this .range = range ;
24
+ }
25
+
26
+ @ Override
27
+ public Range getRange () {
28
+ return range ;
29
+ }
30
+
19
31
@ Override
20
32
public Value eval () {
21
33
super .interruptionCheck ();
@@ -25,7 +37,7 @@ public Value eval() {
25
37
@ Override
26
38
public Value get () {
27
39
if (!ScopeHandler .isVariableOrConstantExists (name )) {
28
- throw new VariableDoesNotExistsException (name );
40
+ throw new VariableDoesNotExistsException (name , getRange () );
29
41
}
30
42
return ScopeHandler .getVariableOrConstant (name );
31
43
}
You can’t perform that action at this time.
0 commit comments