@adrianhelvik/syntax

    1.3.0 • Public • Published

    @adrianhelvik/syntax

    Installation

    npm i --save @adrianhelvik/syntax
    yarn add @adrianhelvik/syntax

    Usage

    const syntax = {
      lex: [
        ['whitespace', /^\s+/, 'ignore'],
        ['keyword', /^(let)/],
        ['symbol', /^[()=]/],
        ['ident', /^[a-zA-Z][a-zA-Z0-9]*/],
        ['number', /^[0-9]+/],
      ],
      parse: {
        main: ['either', 'many', [
          'assignment',
          'funcCall',
          'varDecl',
        ]],
        funcCall: ['sequence', [
          'ident',
          'symbol:(',
          'symbol:)',
        ]],
        assignment: ['sequence', [
          'keyword:let',
          'symbol:=',
          'expression',
        ]],
        expression: ['either', [
          'number',
          'ident',
        ]]
      }
    }
    const source = `
    let i = 0
     
    while (i < 10)
      i = increment(i)
     
    console.log(i)
    `
     

    Keywords

    none

    Install

    npm i @adrianhelvik/syntax

    DownloadsWeekly Downloads

    1

    Version

    1.3.0

    License

    MIT

    Unpacked Size

    32.9 kB

    Total Files

    16

    Last publish

    Collaborators

    • adrianhelvik