Class PreprocessIssueMessageSimplifier.PriorTokenFinder
- Enclosing class:
- PreprocessIssueMessageSimplifier
When helping generate messages for the user, it is often useful to be able to locate the position of the first token immediately before another location in source. For example, consider error reporting when a semicolon is missing. The error is generated on the token after the line on which the semicolon was omitted so, while the error technically emerges on the next line, it is better for the user for it to appear earlier. Specifically, it is most sensible for it to appear on the "prior token" because this is where it was forgotten.
To that end, this finite state automaton can read backwards from a position in source to locate the first "non-skip token" preceding that location. Here a "skip" token means one that is ignored by the preprocessor and does not impact output code (this includes comments and whitespace). This automaton will read character by character from source until it knows it has seen a non-skip token, returning the location of that non-skip token.
A formalized FSA is useful here in order to traverse code which can have a complex grammar. As there are a number of ways in the Java / Processing grammar one can encounter skip tokens, this formalized implementation describes the state machine directly in order to provide hopefully more readability / transparency compared to a regex without requiring the use of something heavier like ANTLR.
-
Method Summary