Reputation: 5638
I am trying to generate AST
after parsing a HTML file.
grammar XHTML2CSV;
options {
output=AST;
ASTLabelType=CommonTree;
}
tokens {
CELLULE;
LIGNE;
CELLULEG = '<td>';
CELLULED = '</td>';
DEBUTCOL = '<tr>';
FINCOL = '</tr>';
DTAB = '<table';
STAB = ' align=\"center\"';
FTAB = ' border=\"1\">';
FINTAB ='</table>';
ligne
: DEBUTCOL cellule+ FINCOL -> ^(LIGNE cellule);
cellule : CELLULEG CHAINE CELLULED
-> ^(CELLULE CHAINE);
And when I parse somthing like :
<tr>
<td>"Cellule 1"</td>
<td>"Cellule 2"</td>
<td>"Cellule 3"</td>
</tr>
I just get the tree : nil ---> LIGNE ---> CELLULE ---> "Cellule 1"
How can I do to get all the children of LIGNE in the AST ?
Thanks
Upvotes: 0
Views: 492
Reputation: 170128
It seems you forgot a +
in your rewrite rule:
ligne
: DEBUTCOL cellule+ FINCOL -> ^(LIGNE cellule+)
; // ^
// |
// +--- ici!
FYI: there's an HTML grammar on the ANTLR website: http://www.antlr.org/grammar/HTML
Upvotes: 1