regular-stream

streaming regular parser

regular-stream

streaming acceptor for regular languages

[http://en.wikipedia.org/wiki/Regular_language]

WORK IN PROGRESS

var r = require('regular-stream')
  , and = r.and, start = r.star, plus = r.plus
  , or = r.or, r.maybe = r.maybe, empty = r.empty
 
and('A', 'B', star('C')) //ABCCCCCCCC 
 
and('A', star('A'))      //A | AAAAAA 
 
plus('A')               //same as ^ 
 
star(or(A, B)) //ABBABABABBABABABBBABAA 
 
and(A, or(B, empty()), C) //AB?C 
 
and(A, maybe(B), C) //ABC | AC 

Each expression can also be drawn as state transition graphs. Would be cool to generate this automatically.

events must occur in order

and (A, B, C)
 
* --> A --> B --> C
or (A, B)
---> A ---> y
  \          /^
   \        /
    `-> B -`
star (A)
        &
---> A ---> y
 \           /^
  `---------`
plus (A)
        &
---> A --->y
maybe (A)
---> A --->y
 \          /^
  `--------`

And then we can draw a big graph, and show a program's execution path on it!

but maybe using canvas instead of ansi.

MIT