gizlang:jslex
import * as Jslex from "gizlang:jslex";Types
JsToken
type JsToken = { k: i64; s: i64; e: i64; line: i64; nl: bool; tail: bool; }A token: its kind K (JS_*), its bytes S to E, its LINE, whether a line break comes before it (NL), and for a template part whether it ends the template (TAIL).
k:i64s:i64e:i64line:i64nl:booltail:bool
JsTokens
type JsTokens = { tokens: Vec<JsToken>; error: string; errorLine: i64; }The tokens of a source, ending with JS_EOF, and its first error ("" for none) with its line.
tokens:Vec<gizlang_jslex.JsToken>error:stringerrorLine:i64
Functions
jsTokens
function jsTokens(src: bytes): JsTokensThe tokens of JavaScript source SRC, in order, ending with JS_EOF. The bytes between two tokens are white space and
comments only: a reader of comments (a minifier that keeps license comments) finds them there. It reads strings, templates
(${ } nests), regular expressions and comments as JavaScript does; it stops at the first error, so the tokens then
end there with no JS_EOF.
Effects: fail.
Constants
JS_EOF
const JS_EOF = 0A token kind: the end of the source (its bytes are empty).
JS_NAME
const JS_NAME = 1A token kind: a name or a keyword.
JS_NUM
const JS_NUM = 2A token kind: a number.
JS_STR
const JS_STR = 3A token kind: a string literal, quotes included.
JS_PUNCT
const JS_PUNCT = 4A token kind: a punctuator.
JS_TEMPLATE
const JS_TEMPLATE = 5A token kind: a template part: from or } to ${ or.
JS_REGEX
const JS_REGEX = 6A token kind: a regular expression literal with its flags.
JS_PRIVATE
const JS_PRIVATE = 7A token kind: a private name (#x).