File tree Expand file tree Collapse file tree 5 files changed +34
-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 5 files changed +34
-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 UnknownClassException extends OwnLangRuntimeException {
4
6
5
7
private final String className ;
@@ -9,6 +11,11 @@ public UnknownClassException(String name) {
9
11
this .className = name ;
10
12
}
11
13
14
+ public UnknownClassException (String name , Range range ) {
15
+ super ("Unknown class " + name , range );
16
+ this .className = name ;
17
+ }
18
+
12
19
public String getClassName () {
13
20
return className ;
14
21
}
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 UnknownFunctionException extends OwnLangRuntimeException {
4
6
5
7
private final String functionName ;
@@ -9,6 +11,11 @@ public UnknownFunctionException(String name) {
9
11
this .functionName = name ;
10
12
}
11
13
14
+ public UnknownFunctionException (String name , Range range ) {
15
+ super ("Unknown function " + name , range );
16
+ this .functionName = name ;
17
+ }
18
+
12
19
public String getFunctionName () {
13
20
return functionName ;
14
21
}
Original file line number Diff line number Diff line change @@ -746,15 +746,18 @@ private Expression multiplicative() {
746
746
}
747
747
748
748
private Expression objectCreation () {
749
- if (match (TokenType .NEW )) {
749
+ if (match (TokenType .NEW )) {
750
+ final var startTokenIndex = index - 1 ;
750
751
final String className = consume (TokenType .WORD ).text ();
751
752
final List <Expression > args = new ArrayList <>();
752
753
consume (TokenType .LPAREN );
753
754
while (!match (TokenType .RPAREN )) {
754
755
args .add (expression ());
755
756
match (TokenType .COMMA );
756
757
}
757
- return new ObjectCreationExpression (className , args );
758
+ final var expr = new ObjectCreationExpression (className , args );
759
+ expr .setRange (getRange (startTokenIndex , index - 1 ));
760
+ return expr ;
758
761
}
759
762
760
763
return unary ();
Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ private Function getFunction(String key) {
75
75
return ((FunctionValue )variable ).getValue ();
76
76
}
77
77
}
78
- throw new UnknownFunctionException (key );
78
+ throw new UnknownFunctionException (key , getRange () );
79
79
}
80
80
81
81
@ Override
Original file line number Diff line number Diff line change 2
2
3
3
import com .annimon .ownlang .exceptions .UnknownClassException ;
4
4
import com .annimon .ownlang .lib .*;
5
+ import com .annimon .ownlang .util .Range ;
6
+ import com .annimon .ownlang .util .SourceLocation ;
5
7
import java .util .Iterator ;
6
8
import java .util .List ;
7
9
8
- public final class ObjectCreationExpression implements Expression {
10
+ public final class ObjectCreationExpression implements Expression , SourceLocation {
9
11
10
12
public final String className ;
11
13
public final List <Expression > constructorArguments ;
14
+ private Range range ;
12
15
13
16
public ObjectCreationExpression (String className , List <Expression > constructorArguments ) {
14
17
this .className = className ;
15
18
this .constructorArguments = constructorArguments ;
16
19
}
20
+
21
+ public void setRange (Range range ) {
22
+ this .range = range ;
23
+ }
24
+
25
+ @ Override
26
+ public Range getRange () {
27
+ return range ;
28
+ }
17
29
18
30
@ Override
19
31
public Value eval () {
@@ -26,7 +38,7 @@ public Value eval() {
26
38
return instantiable .newInstance (ctorArgs ());
27
39
}
28
40
}
29
- throw new UnknownClassException (className );
41
+ throw new UnknownClassException (className , getRange () );
30
42
}
31
43
32
44
// Create an instance and put evaluated fields with method declarations
You can’t perform that action at this time.
0 commit comments