klyn.code.klyn.KlynTokenizer.scanRegexLiteralEnd
method
public scanRegexLiteralEnd(
line as String,
index as Long,
previousKind as TokenKind,
previousWord as String
) as Long
Description

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).

Parameters
ParameterDescription
lineSource line text.
indexIndex of the opening /.
previousKindKind of the last non-whitespace token on the line.
previousWordText of the last identifier/keyword token on the line.
Returns

Exclusive end index of the regex literal, or -1.

Example
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