public scanRegexLiteralEnd( line as String, index as Long, previousKind as TokenKind, previousWord as String ) as Long
Checks whether a / at index in line can start a /pattern/flags regular expression literal rather than a division operator, and returns the exclusive end index of the regex literal (or -1 if it is not a regex literal).
| Parameter | Description |
|---|---|
line | Source line text. |
index | Index of the opening /. |
previousKind | Kind of the last non-whitespace token on the line. |
previousWord | Text of the last identifier/keyword token on the line. |
Exclusive end index of the regex literal, or -1.
import klyn.code
import klyn.code.klyn
t = KlynTokenizer()
assert t.scanRegexLiteralEnd("re = /[a-z]+/i", 5, TokenKind.OPERATOR, "") == 14
assert t.scanRegexLiteralEnd("x = a / b", 6, TokenKind.IDENTIFIER, "a") == -1