Whitespace syntax is not self-synchronizing, so syntax errors in the middle of a Whitespace document change the meaning of the following instructions. Programs often have missing or or extra line feeds at the end when copied from webpages, but this only affects the final instruction. When editing a document, however, insertions and deletions outside of numbers, labels, and comments will invalidate later instructions. To improve the editing experience, error-recovery heuristics are needed to invalidate the smallest ranges possible.
A long line is usually a control flow instruction with a UTF-8 label or has a
large push
at the end.
To detect a labeled instruction:
label
call
jz
jn
jmp
:
jmp
label
call
jmp
:
jmp
jz
jn
Otherwise, the line likely ends with a push
. There may be zero or more add
,
sub
, div
, mod
, store
, or retrieve
instructions before the push. Since
the start of the push
cannot be determined by scanning backwards, skip this
line and resume parsing on the next line.
Collect all labels defined up until the syntax error and attempt to resume
parsing at any position that would be a valid call
, jmp
, jz
, or jn
to
that label.
Collect all call and jump targets for which a label has not been defined up until the syntax error and attempt to resume parsing at any position that would be a valid label.
Since the Whitespace instruction prefix tree is not full, there are some sequences that an instruction can not start with: STT, TSTL, TSL, TTL, TLSL, TLTL, TLL, LLS, and LLT. Assume then, that any occurrences of these sequences are valid and occur elsewhere in an instruction. Those contain L can not occur within numbers or labels, so some combinations are unambiguous.