[antlr-interest] RewriteEmptyStreamException
Manu
manunews at gmail.com
Fri May 16 04:47:02 PDT 2008
I'm using ANTLR v3.0.1 with C# templates.
The following grammar:
grammar Orders;
options
{
language=CSharp;
output=AST;
ASTLabelType=CommonTree;
}
tokens
{
CABECERA;
DETALLE;
RESUMEN;
RESTO;
}
@header {
using System.Text;
}
@rulecatch {
}
s: mensajeORDER EOF -> mensajeORDER;
mensajeORDER: HEADER_ID CR LF linea* (CR | LF)* -> ^(HEADER_ID linea*);
linea: lineasCabecera;
restoLinea: ('|' an+=AN)* CR LF -> {($an != null) && ($an.Count > 0)}?
^(RESTO AN*)
-> ;
lineasCabecera: lineaORD -> ^(CABECERA lineaORD);
lineaORD: 'ORD' '|' numPedido=AN '|' tipoPedido=AN '|' funcion=AN
restoLinea -> ^('ORD' $numPedido $tipoPedido $funcion restoLinea);
HEADER_ID: 'ORDERS';
CR: '\r';
LF: '\n';
fragment CARACTER
: 'a'..'z'
| 'A'..'Z'
;
fragment NUMERO: ('0'..'9');
AN: (CARACTER | NUMERO)+;
N: NUMERO+ ('.' NUMERO+)?;
Doesn't work when restoLinea is just CR LF. It gives me the exception:
Antlr.Runtime.Tree.RewriteEmptyStreamException was unhandled
Message="rule restoLinea"
Source="Antlr3.Runtime"
StackTrace:
en Antlr.Runtime.Tree.RewriteRuleElementStream._Next()
en Antlr.Runtime.Tree.RewriteRuleElementStream.Next()
....
However, if I change restoLinea to:
restoLinea: ('|' an+=AN)* CR LF -> {($an != null) && ($an.Count > 0)}?
^(RESTO AN*)
-> {(CommonTree)adaptor.GetNilNode()};
It works as expected.
I thought that using an empty rewrite rule (-> ;) returned an empty
AST. Am I wrong? If so, how can I do the same with a rewrite rule that
doesn't use custom code?
Thanks
More information about the antlr-interest
mailing list