I'm trying to make a tool like ANTLR from scratch in Swift (just for fun). But I don't understand how grammar knows that there should be no whitespaces (identifier example: "_myIdentifier123"):
Identifier
: Identifier_head Identifier_characters?
And there should be whitespaces (example "is String"):
type_casting_operator
: 'is' type
| 'as' type
| 'as' '?' type
| 'as' '!' type
;
I've searched for WS in ANTLR's source code, but found nothing. There is no "WS" string in java code: https://github.com/antlr/antlr4
Can anyone explain the algorithm behind this? How it decides whether tokens are separated with whitespaces or not?