Closed antimatter84 closed 2 years ago
This is cause DefaultParserNotice is constructed wrong, the offset should be from the whole string, but now it's a offset of the specific line where the error is. Probably simplest is to aggregate offsetted chars in the loop (not that this code is extremely untested):
String[] lines = input.split("\\n"); //simplify countin'
int agg = 0; //aggregated length
result.setParsedLines(0, lines.length - 1);
for (int i = 0; i < lines.length; i++)
{
String line = lines[i];
int pos = line.indexOf(ERROR);
if (pos >= 0)
{
System.out.printf("'err' found on line: %d, char [%d, %d]%n", i + 1, pos + agg, pos + agg + ERROR.length() - 1);
DefaultParserNotice notice = new DefaultParserNotice(this, "error here", i + 1, pos + agg, ERROR.length());
result.addNotice(notice);
}
agg += line.length() + 1; //Add newline and rest of the string length
}
Yeah, @siggemannen is right, the offset
parameter is from the start of the document, not the start of the line. IIRC this is done because the line
argument is required, but offsete
and length
are optional, to support parsers that only identify errors at the line level (I know Perl does this, at least it used to, as do some XML parsers). And I think the absolute offset was used to avoid having to calculate that value for e.g. rendering functions that need that value.
If you parse directly from an RSyntaxTextArea
instance, the Document
/Element
API can be used to quickly and efficiently get these values.
Description Errors (ParserNotice) on any line are always displayed with squiggly underline on the first line in the RSTA.
Steps to Reproduce Specific steps to reproduce the behavior:
Expected behavior An error in any line, from character position [a, b] will be rendered squiggly underlined in the correct line from [a, b].
Actual behavior An error in any line, from character position [a, b] will always be rendered squiggly underlined in line 1 from [a, b].
If the first line is not long enough, the squiggly underline will move into the next line. Example:
Here, 'moo' and the following blank will be squiggly underlined.
Screenshots
Java version Java 8u322
Additional context I do not know how or if the method DefaultParseResult::setParsedLines should be used after evaluating the RSyntaxDocument. However, it does not affect the outcome of my demo application in any observable way.
Code example