Skip to documentation
SLOP

tiny.smg.tree.scanner.typescript

Reference tiny.smg tree scanner typescript

Defined in tree.scanner.

API (3)

Types and contracts

Public types and contracts.

No direct callersNo direct callstree.scannertypescript
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Source: tools/smg/src/tree/scanner/root.zig:3

zig
pub const typescript = @import("typescript.zig");

Source: tools/smg/src/tree/scanner/typescript.zig

zig
const std = @import("std");const ecma = @import("ecma/root.zig");pub const Token = enum(u16) {    automatic_semicolon,    template_chars,    ternary_qmark,    html_comment,    logical_or,    escape_sequence,    regex_pattern,    jsx_text,    function_signature_automatic_semicolon,    error_recovery,};pub const Valid = packed struct(u16) {    automatic_semicolon: bool = false,    template_chars: bool = false,    ternary_qmark: bool = false,    html_comment: bool = false,    logical_or: bool = false,    escape_sequence: bool = false,    regex_pattern: bool = false,    jsx_text: bool = false,    function_signature_automatic_semicolon: bool = false,    error_recovery: bool = false,    _: u6 = 0,};pub const Scanner = struct {    pub fn scan(_: *Scanner, lexer: anytype, valid: Valid) bool {        if (valid.template_chars) {            if (valid.automatic_semicolon) return false;            return ecma.scanTemplateChars(lexer, @backingInt(Token.template_chars));        }        if (valid.jsx_text and ecma.scanJsxText(lexer, @backingInt(Token.jsx_text))) return true;        if (valid.automatic_semicolon or valid.function_signature_automatic_semicolon) {            var scanned_comment = false;            const result = scanAutomaticSemicolon(lexer, valid, &scanned_comment);            if (!result and !scanned_comment and valid.ternary_qmark and lexer.lookahead() == '?') {                return scanTernaryQmark(lexer);            }            return result;        }        if (valid.ternary_qmark) return scanTernaryQmark(lexer);        if (valid.html_comment and !valid.logical_or and !valid.escape_sequence and !valid.regex_pattern) {            return ecma.scanHtmlComment(lexer, @backingInt(Token.html_comment));        }        return false;    }    pub fn serialize(_: Scanner, _: []u8) usize {        return 0;    }    pub fn deserialize(_: *Scanner, serialized: []const u8) void {        std.debug.assert(serialized.len == 0);    }};fn scanWhitespaceAndComments(lexer: anytype, scanned_comment: *bool) bool {    while (true) {        while (ecma.isSpace(lexer.lookahead())) lexer.advance(true);        if (lexer.lookahead() != '/') return true;        lexer.advance(true);        if (lexer.lookahead() == '/') {            lexer.advance(true);            while (lexer.lookahead() != 0 and lexer.lookahead() != '\n') lexer.advance(true);            scanned_comment.* = true;        } else if (lexer.lookahead() == '*') {            lexer.advance(true);            while (lexer.lookahead() != 0) {                if (lexer.lookahead() == '*') {                    lexer.advance(true);                    if (lexer.lookahead() == '/') {                        lexer.advance(true);                        break;                    }                } else {                    lexer.advance(true);                }            }        } else {            return false;        }    }}fn scanAutomaticSemicolon(lexer: anytype, valid: Valid, scanned_comment: *bool) bool {    lexer.setResult(@backingInt(Token.automatic_semicolon));    lexer.markEnd();    while (true) {        if (lexer.lookahead() == 0) return true;        if (lexer.lookahead() == '}') {            while (true) {                lexer.advance(true);                if (!ecma.isSpace(lexer.lookahead())) break;            }            if (lexer.lookahead() == ':') return valid.logical_or;            return true;        }        if (!ecma.isSpace(lexer.lookahead())) return false;        if (lexer.lookahead() == '\n') break;        lexer.advance(true);    }    lexer.advance(true);    if (!scanWhitespaceAndComments(lexer, scanned_comment)) return false;    switch (lexer.lookahead()) {        '`', ',', '.', ';', '*', '%', '>', '<', '=', '?', '^', '|', '&', '/', ':' => return false,        '{' => {            if (valid.function_signature_automatic_semicolon) return false;        },        '(', '[' => {            if (valid.logical_or) return false;        },        '+' => {            lexer.advance(true);            return lexer.lookahead() == '+';        },        '-' => {            lexer.advance(true);            return lexer.lookahead() == '-';        },        '!' => {            lexer.advance(true);            return lexer.lookahead() != '=';        },        'i' => {            lexer.advance(true);            if (lexer.lookahead() != 'n') return true;            lexer.advance(true);            if (!ecma.isAlpha(lexer.lookahead())) return false;            for ("stanceof") |letter| {                if (lexer.lookahead() != letter) return true;                lexer.advance(true);            }            if (!ecma.isAlpha(lexer.lookahead())) return false;        },        else => {},    }    return true;}fn scanTernaryQmark(lexer: anytype) bool {    while (ecma.isSpace(lexer.lookahead())) lexer.advance(true);    if (lexer.lookahead() != '?') return false;    lexer.advance(false);    if (lexer.lookahead() == '?' or lexer.lookahead() == '.') return false;    lexer.markEnd();    lexer.setResult(@backingInt(Token.ternary_qmark));    while (ecma.isSpace(lexer.lookahead())) lexer.advance(false);    if (lexer.lookahead() == ':' or lexer.lookahead() == ')' or lexer.lookahead() == ',') return false;    if (lexer.lookahead() == '.') {        lexer.advance(false);        return ecma.isDigit(lexer.lookahead());    }    return true;}

Audit

Definitions3
Public names3
Members21
Version26.7.0
Revisiondaab053ee433