I have the following classes which will represent different kinds of data:
class A { ... }
class S { ... }
class F { ... }
Then I construct input array:
var input = [new F(), new A([11,22]), new S([33,44]), new F([55,66]), new A([77,88])]
Then I build a grammar for PEG.js:
start = (F A*)+
A = 'a' / S
S = 's'+ (A|F)
F = 'f'
I know that I may use PEG.js with a string as input (e.g. fasfa). But I see no way to use my own input stream of tokens. Is it possible at all?
Updated
The original problem can be summarizes as "I need a way to build toolbar one block at a time". Currently I have 3 types of blocks: Append, Squash, and Final.
Append - just appends current buttons into the resulting array
Squash - behaves like Append only if next block is Append (several
Squash block melded into one)
Final - just like Append, but if there is something next to it,
it will start from the empty resulting array
Several examples:
Append([11,22])
[11,22]
Append([11,22])
Squash([33,44])
[11,22]
Append([11,22])
Squash([33,44])
Append([55,66])
[11,22,33,44,55,66]
Append([11,22])
Squash([33,44])
Final([55,66])
[11,22,33,44,55,66]
Append([11,22])
Squash([33,44])
Final([55,66])
Append([77,88])
[77,88]
I thought that it is possible to think of this problem as of some language problem. That is I have an input stream of tokens which I need to convert to something other (e.g. some object).