# lex-parser

> A parser for lexical grammars used by jison

Latest version **0.1.4** (published 2013-08-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install lex-parser
pnpm add lex-parser
yarn add lex-parser
bun add lex-parser
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2013-08-04 |
| First published | 2013-01-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Zach Carter |
| Maintainers | zaach |
| Keywords | lexical, grammar, parser, jison |

## Links

- npm: https://www.npmjs.com/package/lex-parser
- npm.io page: https://npm.io/package/lex-parser

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.1.4 (latest) — 2013-08-04
- 0.1.3 — 2013-07-27
- 0.1.2 — 2013-06-22
- 0.1.1 — 2013-06-22
- 0.1.0 — 2013-01-28
- 0.0.1 — 2013-01-27

## README

# lex-parser

A parser for lexical grammars used by [jison](http://jison.org) and jison-lex.

## install

    npm install lex-parser

## build

To build the parser yourself, clone the git repo then run:

    make

This will generate `lex-parser.js`.

## usage

    var lexParser = require("lex-parser");

    // parse a lexical grammar and return JSON
    lexParser.parse("%% ... ");

## example

The parser can parse its own lexical grammar, shown below:

    NAME              [a-zA-Z_][a-zA-Z0-9_-]*

    %s indented trail rules
    %x code start_condition options conditions action

    %%

    <action>[^{}]+          return 'ACTION_BODY'
    <action>"{"             yy.depth++; return '{'
    <action>"}"             yy.depth == 0 ? this.begin('trail') : yy.depth--; return '}'

    <conditions>{NAME}      return 'NAME'
    <conditions>">"         this.popState(); return '>'
    <conditions>","         return ','
    <conditions>"*"         return '*'

    <rules>\n+              /* */
    <rules>\s+              this.begin('indented')
    <rules>"%%"             this.begin('code'); return '%%'
    <rules>[a-zA-Z0-9_]+    return 'CHARACTER_LIT'

    <options>{NAME}         yy.options[yytext] = true
    <options>\n+            this.begin('INITIAL')
    <options>\s+\n+         this.begin('INITIAL')
    <options>\s+            /* empty */

    <start_condition>{NAME}         return 'START_COND'
    <start_condition>\n+            this.begin('INITIAL')
    <start_condition>\s+\n+         this.begin('INITIAL')
    <start_condition>\s+            /* empty */

    <trail>.*\n+                    this.begin('rules')

    <indented>"{"                   yy.depth = 0; this.begin('action'); return '{'
    <indented>"%{"(.|\n)*?"%}"      this.begin('trail'); yytext = yytext.substr(2, yytext.length-4);return 'ACTION'
    "%{"(.|\n)*?"%}"                yytext = yytext.substr(2, yytext.length-4); return 'ACTION'
    <indented>.+                    this.begin('rules'); return 'ACTION'

    "/*"(.|\n|\r)*?"*/"             /* ignore */
    "//".*                          /* ignore */

    \n+                             /* */
    \s+                             /* */
    {NAME}                          return 'NAME'
    \"("\\\\"|'\"'|[^"])*\"         yytext = yytext.replace(/\\"/g,'"');return 'STRING_LIT'
    "'"("\\\\"|"\'"|[^'])*"'"       yytext = yytext.replace(/\\'/g,"'");return 'STRING_LIT'
    "|"                             return '|'
    "["("\\\\"|"\]"|[^\]])*"]"      return 'ANY_GROUP_REGEX'
    "(?:"                           return 'SPECIAL_GROUP'
    "(?="                           return 'SPECIAL_GROUP'
    "(?!"                           return 'SPECIAL_GROUP'
    "("                             return '('
    ")"                             return ')'
    "+"                             return '+'
    "*"                             return '*'
    "?"                             return '?'
    "^"                             return '^'
    ","                             return ','
    "<<EOF>>"                       return '$'
    "<"                             this.begin('conditions'); return '<'
    "/!"                            return '/!'
    "/"                             return '/'
    "\\"([0-7]{1,3}|[rfntvsSbBwWdD\\*+()${}|[\]\/.^?]|"c"[A-Z]|"x"[0-9A-F]{2}|"u"[a-fA-F0-9]{4}) return 'ESCAPE_CHAR'
    "\\".                           yytext = yytext.replace(/^\\/g,''); return 'ESCAPE_CHAR'
    "$"                             return '$'
    "."                             return '.'
    "%options"                      yy.options = {}; this.begin('options')
    "%s"                            this.begin('start_condition');return 'START_INC'
    "%x"                            this.begin('start_condition');return 'START_EXC'
    "%%"                            this.begin('rules'); return '%%'
    "{"\d+(","\s?\d+|",")?"}"       return 'RANGE_REGEX'
    "{"{NAME}"}"                    return 'NAME_BRACE'
    "{"                             return '{'
    "}"                             return '}'
    .                               /* ignore bad characters */
    <*><<EOF>>                      return 'EOF'

    <code>(.|\n)+                   return 'CODE'

    %%

## license

MIT

---
_Source: https://npm.io/package/lex-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
