@photon-terminal/lexer
TypeScript icon, indicating that this package has built-in type declarations

0.1.0-alpha.1 • Public • Published

Photon Terminal Lexer

The lexical analysis tool made for Photon Terminal.

Install

npm i @photon-terminal/lexer

Usage

import { Token, Tokenizer } from '@photon-terminal/lexer'

// Initialize the lexer with some code
const lexer = new Tokenizer().init('1 + 2;')

const tokens: Token[] = [lexer.getNextToken()]
let nextToken: Token | null = lexer.getNextToken()

while (nextToken) {
  tokens.push(nextToken)
  nextToken = lexer.getNextToken()
}

console.log(tokens)
// [
//   { type: 'NUMBER', value: '1' },
//   { type: 'ADDITIVE_OPERATOR', value: '+' },
//   { type: 'NUMBER', value: '2' },
//   { type: 'SEMICOLON', value: ';' },
// ]

The code above shows how you can perform your own lexical analysis on JavaScript code.

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @photon-terminal/lexer

      Weekly Downloads

      2

      Version

      0.1.0-alpha.1

      License

      MIT

      Unpacked Size

      9.7 kB

      Total Files

      13

      Last publish

      Collaborators

      • caspersocio