FAfterOpenSquareBracket: Boolean;
FAfterSquareBracketTEXT: Boolean;
Those 2 variables must be fields of the object. So there state is kept, across several calls to "Next".
You have to see the "Next" method (and the entire parsing) as a "state" driven parser.
"Next" is called over and over again. Each time, it only sees a small bit of the text. In order to know, how to treat this small bit, it needs to know what state it is in.
- So if it is in "normal" state, and it encounters a "[", then it changes to "after [" state (FAfterOpenSquareBracket:=True)
- If it is in "after [" state, then it needs to find the "]" and the text inbetween is a chord token.
Or better yet, it should test, if that text inbetween is any of the know chords (e.g. DM)
** Important: Since Next advances to the end of the token, it must also change the state, it is no longer "after [".
It goes to "after [ text" (changing the 2 fields)
- if state = "after [ text" then the "]" is to be highlighted
The last state ensures that if you encounter a "]" that is not the end of a chord, then it is not highlighted.
- The state must be kept in a field of the object, so it can be used across several calls to Next.
- You may want to clear it, in SetLine, or Get/SetRange
((( If you need it across lines, then you must store it as part of the "range". Lines can be scanned out of order, but the range will be restored correctly. )))
- It is your choice how to store it: 2 booleans, an enum, a set .....