2018-06-13 00:39:33 +00:00
|
|
|
package io.github.applecommander.bastools.api.model;
|
2018-05-06 19:31:36 +00:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2018-05-21 00:54:11 +00:00
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.Optional;
|
2018-05-06 19:31:36 +00:00
|
|
|
|
2018-06-13 00:39:33 +00:00
|
|
|
import io.github.applecommander.bastools.api.Visitor;
|
2018-05-29 03:33:41 +00:00
|
|
|
|
2018-05-09 01:25:09 +00:00
|
|
|
/** An AppleSoft BASIC Line representation. */
|
2018-05-14 03:27:56 +00:00
|
|
|
public class Line {
|
2018-05-21 00:54:11 +00:00
|
|
|
public final Program program;
|
2018-05-06 19:31:36 +00:00
|
|
|
public final int lineNumber;
|
|
|
|
public final List<Statement> statements = new ArrayList<>();
|
|
|
|
|
2018-05-21 00:54:11 +00:00
|
|
|
public Line(int lineNumber, Program program) {
|
|
|
|
Objects.requireNonNull(program);
|
2018-05-06 19:31:36 +00:00
|
|
|
this.lineNumber = lineNumber;
|
2018-05-21 00:54:11 +00:00
|
|
|
this.program = program;
|
|
|
|
}
|
|
|
|
|
2018-06-10 15:39:14 +00:00
|
|
|
public int getLineNumber() {
|
|
|
|
return lineNumber;
|
|
|
|
}
|
|
|
|
|
2018-05-21 00:54:11 +00:00
|
|
|
public Optional<Line> nextLine() {
|
|
|
|
int i = program.lines.indexOf(this);
|
|
|
|
if (i == -1 || i+1 >= program.lines.size()) {
|
|
|
|
return Optional.empty();
|
|
|
|
}
|
|
|
|
return Optional.of(program.lines.get(i+1));
|
2018-05-06 19:31:36 +00:00
|
|
|
}
|
|
|
|
|
2018-05-14 03:27:56 +00:00
|
|
|
public Line accept(Visitor t) {
|
|
|
|
return t.visit(this);
|
2018-05-08 04:21:29 +00:00
|
|
|
}
|
2018-05-06 19:31:36 +00:00
|
|
|
}
|