AST構築時の注意とか

添削する機械。

ツリーは、ちゃんと出来ている。ASTに変換しようとしてコケている。
...

...
ifcomment :
	(C_ST IF expression C_ED txt
		(elseifcomment txt)* (elsecomment txt)? endcomment)
	-> ^(IFNODE ^(EXPRESSIONNODE expression) txt
			^(ELSEIFNODE elseifcomment txt)*
			^(ELSENODE txt)?
		)
	;
...
RewriteCardinalityExceptionってなんなんだぜ? - 設計と実装の狭間で。

リライト演算子 -> は表現力が妙に低いので、適切にルールくくりだしのリファクタリングが必要です。

ifcomment :
	(C_ST IF expression C_ED txt
		elseifnode* elsenode? endcomment)
	-> ^(IFNODE ^(EXPRESSIONNODE expression) txt
			elseifnode*
			elsenode?
		)
	;

elseifnode :
	elseifcomment txt -> ^(ELSEIFNODE elseifcomment txt)
	;

elsenode :
	elsecomment txt -> ^(ELSENODE txt)
	;

おそらく、txtの個数とelseifcommentの個数のミスマッチだと思います。