我有以下类代表不同类型的数据:
class A { ... }
class S { ... }
class F { ... }
然后我构造输入数组:
var input = [new F(), new A([11,22]), new S([33,44]), new F([55,66]), new A([77,88])]
然后我为PEG.js构建了一个语法:
start = (F A*)+
A = 'a' / S
S = 's'+ (A|F)
F = 'f'
我知道我可以使用带有字符串的PEG.js作为输入(例如 fasfa )。但我认为无法使用我自己的令牌输入流。它有可能吗?
更新
原始问题可以总结为"我需要一种构建工具栏的方法 一次一个街区"。目前我有3种类型的块:追加, 壁球和决赛。
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
几个例子:
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]
我认为可以将此问题视为某种语言问题。那就是我有一个令牌输入流,我需要转换成其他东西(例如某个对象)。