File tree Expand file tree Collapse file tree 4 files changed +34
-4
lines changed
ownlang-parser/src/main/java/com/annimon/ownlang/parser Expand file tree Collapse file tree 4 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -147,7 +147,7 @@ private Statement statement() {
147
147
return useStatement ();
148
148
}
149
149
if (match (TokenType .INCLUDE )) {
150
- return new IncludeStatement ( expression () );
150
+ return includeStatement ( );
151
151
}
152
152
if (match (TokenType .FOR )) {
153
153
return forStatement ();
@@ -167,6 +167,13 @@ private Statement statement() {
167
167
return assignmentStatement ();
168
168
}
169
169
170
+ private IncludeStatement includeStatement () {
171
+ final var startTokenIndex = index - 1 ;
172
+ final var include = new IncludeStatement (expression ());
173
+ include .setRange (getRange (startTokenIndex , index ));
174
+ return include ;
175
+ }
176
+
170
177
private UseStatement useStatement () {
171
178
final var modules = new HashSet <String >();
172
179
do {
Original file line number Diff line number Diff line change 6
6
import com .annimon .ownlang .lib .Value ;
7
7
import com .annimon .ownlang .parser .error .ParseErrorsFormatterStage ;
8
8
import com .annimon .ownlang .stages .*;
9
+ import com .annimon .ownlang .util .Range ;
10
+ import com .annimon .ownlang .util .SourceLocation ;
9
11
import com .annimon .ownlang .util .input .InputSourceFile ;
10
12
import com .annimon .ownlang .util .input .SourceLoaderStage ;
11
13
12
14
/**
13
15
*
14
16
* @author aNNiMON
15
17
*/
16
- public final class IncludeStatement extends InterruptableNode implements Statement {
18
+ public final class IncludeStatement extends InterruptableNode implements Statement , SourceLocation {
17
19
18
20
public final Node expression ;
21
+ private Range range ;
19
22
20
23
public IncludeStatement (Node expression ) {
21
24
this .expression = expression ;
22
25
}
23
26
27
+ public void setRange (Range range ) {
28
+ this .range = range ;
29
+ }
30
+
31
+ @ Override
32
+ public Range getRange () {
33
+ return range ;
34
+ }
35
+
24
36
@ Override
25
37
public Value eval () {
26
38
super .interruptionCheck ();
@@ -31,6 +43,7 @@ public Value eval() {
31
43
new SourceLoaderStage ()
32
44
.then (new LexerStage ())
33
45
.then (new ParserStage ())
46
+ // TODO LinterStage based on main context
34
47
.then (new FunctionAddingStage ())
35
48
.then (new ExecutionStage ())
36
49
.perform (stagesData , new InputSourceFile (path ));
Original file line number Diff line number Diff line change @@ -23,11 +23,13 @@ public void visit(IncludeStatement s) {
23
23
final String path = expr .eval ().asString ();
24
24
if (!detector .isReadable (path )) {
25
25
results .add (LinterResult .error (
26
- "Include statement path \" %s\" is not readable" .formatted (path )));
26
+ "Include statement path \" %s\" is not readable" .formatted (path ),
27
+ s .getRange ()));
27
28
}
28
29
} else {
29
30
results .add (LinterResult .warning (
30
- "Include statement path \" %s\" is not a constant string" .formatted (s .expression )));
31
+ "Include statement path \" %s\" is not a constant string" .formatted (s .expression ),
32
+ s .getRange ()));
31
33
}
32
34
}
33
35
}
Original file line number Diff line number Diff line change @@ -11,10 +11,18 @@ static LinterResult warning(String message) {
11
11
return new LinterResult (Severity .WARNING , message );
12
12
}
13
13
14
+ static LinterResult warning (String message , Range range ) {
15
+ return new LinterResult (Severity .WARNING , message , range );
16
+ }
17
+
14
18
static LinterResult error (String message ) {
15
19
return new LinterResult (Severity .ERROR , message );
16
20
}
17
21
22
+ static LinterResult error (String message , Range range ) {
23
+ return new LinterResult (Severity .ERROR , message , range );
24
+ }
25
+
18
26
LinterResult (Severity severity , String message ) {
19
27
this (severity , message , null );
20
28
}
You can’t perform that action at this time.
0 commit comments