@heeheehee thought on where to go next.
I just made Token extend Range, and exposed the Location-related methods, so the next step would intuitively be to move on with giving a Location to the various parsetree classes.
However, as it has been pointed out, testing for these Locations was asked.
Now, while it "would" be possible to make those tests inside ParserTest.java, doing so would result in an *enormous, chaotic mess*.
The logical conclusion would be that it would be preferable to first split Parser's parsing methods between textui/parsetree's classes.
Now, since Parser is in a different package from textui/parsetree, doing so will inevitably lead to methods being made public.
Obviously, this means that adding tests will be required, which, let me say... My god, I will cling to any hope there is, however small it is, that there's a way to not have to do that.
So, what *could* we do to not have to do that? (given that it needs to be more than "because I asked gently")
An idea I had was to give two flags to Parser instances.
The flags would go along the lines of "contentParsed" and "parsingInProgress". The latter would be set to true once Parser.parse is called (unless contentParsed is true, in which case it throws an IllegalStateException), and to false before exiting that same method (while also setting contentParsed to true), with no way of modifying them anywhere else.
Then, every method that is forced to be public because of this change, but we don't actually want to be publicly available, would start with
with that method reading
Since parsing is done all in one go, this would effectively allow us to deny access to those methods from outside the parsing logic, making them safe.
Thoughts?
I just made Token extend Range, and exposed the Location-related methods, so the next step would intuitively be to move on with giving a Location to the various parsetree classes.
However, as it has been pointed out, testing for these Locations was asked.
Now, while it "would" be possible to make those tests inside ParserTest.java, doing so would result in an *enormous, chaotic mess*.
The logical conclusion would be that it would be preferable to first split Parser's parsing methods between textui/parsetree's classes.
Now, since Parser is in a different package from textui/parsetree, doing so will inevitably lead to methods being made public.
Obviously, this means that adding tests will be required, which, let me say... My god, I will cling to any hope there is, however small it is, that there's a way to not have to do that.
So, what *could* we do to not have to do that? (given that it needs to be more than "because I asked gently")
An idea I had was to give two flags to Parser instances.
The flags would go along the lines of "contentParsed" and "parsingInProgress". The latter would be set to true once Parser.parse is called (unless contentParsed is true, in which case it throws an IllegalStateException), and to false before exiting that same method (while also setting contentParsed to true), with no way of modifying them anywhere else.
Then, every method that is forced to be public because of this change, but we don't actually want to be publicly available, would start with
Java:
public Expression parse(final Parser parser, <other parameters>) {
Parser.checkState(parser);
[...]
}
Java:
class Parser {
private boolean contentParsed = false;
private boolean parsingInProgress = false;
[...]
private boolean isParsing() {
return this.parsingInProgress;
}
public void checkState(final Parser parser) {
if (parser == null || !parser.isParsing()) {
throw new IllegalStateException("Parsing method accessed outside parsing logic");
}
}
[...]
}
Since parsing is done all in one go, this would effectively allow us to deny access to those methods from outside the parsing logic, making them safe.
Thoughts?