Skip to content

@bablr/cli

This is the CLI runner for BABLR. If you have a BABLR grammar for a computer language, this tool allows you to use it to do streaming parsing. Parse results are presented in CSTML.

Usage

This package has no built-in language support, but rather expects you to supply a valid import specifier referring to a BABLR language. This likely means that you will likely need to start by installing both the parser and the language you wish to use.

Usage: bablr [options]

Options:
  -l, --language [URL]     The URL of the top BABLR language
  -p, --production [type]  The name of the top production type
  -f, --format             Pretty-format CSTML output (default: true)
  -F, --no-format
  -v, --verbose            Prints debugging information to stderr
  -c, --color [WHEN]       When to use ANSI escape colors
    WHEN: "auto" | "always" | "never" (default: "auto")
  -e, --embedded           Requires quoted input but enables gap parsing
  -h, --help               display help for command

Example

bablr -l @bablr/language-en-json -p Expression -f << 'EOF'
[
  1,
  true,
  "3"
]
EOF

Running the above command produces the following output. Note that this is a stream parse so lines of output will appear one by one as fast as the input can be read and parsed.

<_>
  _:
  <Expression>
    .:
    <Array>
      openToken*: <* '[' />
      #:
      :Space:
      <*Newline '\n' />
      #:
      :Space:
      <*Space '  ' />
      elements[]$:
      <Number>
        sign*: null
        wholePart$: <*UnsignedInteger '1' />
        decimalSeparatorToken*: null
        exponentSeparatorToken*: null
      </>
      #separatorTokens: <* ',' />
      #:
      :Space:
      <*Newline '\n' />
      #:
      :Space:
      <*Space '  ' />
      elements[]$:
      <Boolean>
        sigilToken*: <*Keyword 'true' />
      </>
      #separatorTokens: <* ',' />
      #:
      :Space:
      <*Newline '\n' />
      #:
      :Space:
      <*Space '  ' />
      elements[]$:
      <String>
        openToken*: <* '"' />
        content$: <*StringContent '3' />
        closeToken*: <* '"' />
      </>
      #:
      :Space:
      <*Newline '\n' />
      closeToken*: <* ']' />
    </>
  </>
</>