Skip to content
/ lexer Public

Fast lexer for converting text and source code into a stream of tokens for parsing.

License

Notifications You must be signed in to change notification settings

je-es/lexer

Repository files navigation


lexer

A fast, robust lexer designed to perform lexical analysis
efficiently converting raw text input or source code into a clean, digestible stream of tokens for parsing.

line
  • Install

    npm install @je-es/lexer
    import * as Lexer from "@je-es/lexer";

    line
  • Usage

    // [1] create lexer rules
    const lexer_rules : Lexer.Rules = {
        // ═══ Whitespace ═══
        ws              : /\s+/,
    
        // ═══ Literals ═══
        bin             : /0b[01]+/,
        oct             : /0o[0-7]+/,
        ...
    
        // ═══ Keywords ═══
        try             : 'try',
        catch           : 'catch',
        ...
    
        // ═══ Types ═══
        f_type          : ['f16', 'f32', 'f64', 'f80', 'f128'],
        ...
    
        // ═══ Operators ═══
        '=='            : '==',
        '!='            : '!=',
        ...
    
        // ═══ Identifier ═══
        ident           : /[a-zA-Z_][a-zA-Z0-9_]*/,
    };
    // [2] tokenize input using your rules
    const tokens = Lexer.tokenize('<input>', rules);

    line
  • Related


line

About

Fast lexer for converting text and source code into a stream of tokens for parsing.

Topics

Resources

License

Stars

Watchers

Forks