1

I want to parse latex file so that i can convert it into html. I started with basic minimum text file. But the tree created by "grun Tex_grammar start -gui" is showing errors. I think there is some error in the code which i am not able to figure out Below is my Grammar code: ///////////////////////////////////////////////////////

grammar Tex_grammar;
r : START BEGINDOC  body_text ENDDOC EOF ; // 



 body_text:  body_text body_parts
          |  body_parts

         ;

 body_parts: section
         |   subsection

         ;

 section:    section (SECTION'{' name'}') text ('\r\n')*
         |(SECTION'{' name'}') text ('\r\n')*
         ;

 subsection:    subsection (SUBSECTION'{' name'}') text ('\r\n')*
         |(SUBSECTION'{' name'}') text ('\r\n')*
         ;
name :  WORD ' ' WORD*;
 text:   text name* '\r|\n'
     |name '\r|\n'
     |' '+
     ;

\\Lexer
START:  '\\documentclass{article}';
BEGINDOC:   '\\begin{document}';
ENDDOC:     '\\end{document}';

SECTION : '\\section';
SUBSECTION  :   '\\subsection';
INTEGER :   [0-9]+ ;
WORD        :   (((PUNCTUATION)|[a-zA-Z0-9]|(GREEK_LETTERS))+|'('|')');
GREEK_LETTERS   :    '\\alpha'             
                     |'\\beta'|'\\gamma'|'\\delta'|'\\epsilon';




fragment LETTERS   :        [a-zA-Z];
fragment PUNCTUATION  :            ('.'|'\'|!|'?'|:|;|');

enter image description here

  • It's hard to see where the error are (but I am not expert in parsers). You should had the text that you are using in this test. Please try to explain the error: on which word is it occurring ? – Gabriel Devillers Aug 19 '18 at 18:07

0 Answers0