# HG changeset patch # User John W. Eaton # Date 1443803139 14400 # Node ID e3c0fee87493caaf70eadc049a41e67686f7872b # Parent 72cd24aa5f7abeb98d4de9abef51488190f7996b style fixes for tex lexer and parser * oct-tex-lexer.in.ll, oct-tex-parser.in.yy: Eliminate tabs and reindent. diff -r 72cd24aa5f7a -r e3c0fee87493 libinterp/corefcn/oct-tex-lexer.in.ll --- a/libinterp/corefcn/oct-tex-lexer.in.ll Fri Oct 02 17:48:58 2015 +0200 +++ b/libinterp/corefcn/oct-tex-lexer.in.ll Fri Oct 02 12:25:39 2015 -0400 @@ -36,8 +36,8 @@ } -%x NUM_MODE -%x MAYBE_NUM_MODE +%x NUM_MODE +%x MAYBE_NUM_MODE %{ @@ -53,19 +53,19 @@ // FIXME: with bison 3.x, OCTAVE_TEX_STYPE appears in the generated // oct-parse.h file, but there is no definition for YYSTYPE, which is -// needed by the code that is generated by flex. I can't seem to find a -// way to tell flex to use OCTAVE_TEX_STYPE instead of YYSTYPE in the code -// it generates, or to tell bison to provide the definition of YYSTYPE -// in the generated oct-parse.h file. +// needed by the code that is generated by flex. I can't seem to find +// a way to tell flex to use OCTAVE_TEX_STYPE instead of YYSTYPE in +// the code it generates, or to tell bison to provide the definition +// of YYSTYPE in the generated oct-parse.h file. #if defined (OCTAVE_TEX_STYPE_IS_DECLARED) && ! defined YYSTYPE #define YYSTYPE OCTAVE_TEX_STYPE #endif #if defined (GNULIB_NAMESPACE) -// Calls to the following functions appear in the generated output from -// flex without the namespace tag. Redefine them so we will use them -// via the gnulib namespace. +// Calls to the following functions appear in the generated output +// from flex without the namespace tag. Redefine them so we will use +// them via the gnulib namespace. #define fprintf GNULIB_NAMESPACE::fprintf #define fread GNULIB_NAMESPACE::fread #define fwrite GNULIB_NAMESPACE::fwrite @@ -77,73 +77,99 @@ %} -D [0-9] -NUM (({D}+\.?{D}*)|(\.{D}+)) +D [0-9] +NUM (({D}+\.?{D}*)|(\.{D}+)) %% %{ -// Numeric values +// Numeric values. %} -{NUM} { - int nread; +{NUM} { + int nread = sscanf (yytext, "%lf", &(yylval->num)); - nread = sscanf (yytext, "%lf", &(yylval->num)); if (nread == 1) return NUM; } -[ \t]+ { } -"\n"|. { yyless (0); BEGIN (INITIAL); } + +[ \t]+ { } + +"\n"|. { + yyless (0); + BEGIN (INITIAL); + } -"{" { BEGIN (NUM_MODE); return START; } -"\n"|. { yyless (0); BEGIN (INITIAL); } +"{" { + BEGIN (NUM_MODE); + return START; + } + +"\n"|. { + yyless (0); + BEGIN (INITIAL); + } %{ -// Simple commands +// Simple commands. %} -"\\bf" { return BF; } -"\\it" { return IT; } -"\\sl" { return SL; } -"\\rm" { return RM; } +"\\bf" { return BF; } +"\\it" { return IT; } +"\\sl" { return SL; } +"\\rm" { return RM; } %{ -// Generic font commands +// Generic font commands. %} -"\\fontname" { return FONTNAME; } -"\\fontsize" { BEGIN (MAYBE_NUM_MODE); return FONTSIZE; } -"\\color[rgb]" { BEGIN (MAYBE_NUM_MODE); return COLOR_RGB; } -"\\color" { return COLOR; } +"\\fontname" { return FONTNAME; } + +"\\fontsize" { + BEGIN (MAYBE_NUM_MODE); + return FONTSIZE; + } + +"\\color[rgb]" { + BEGIN (MAYBE_NUM_MODE); + return COLOR_RGB; + } + +"\\color" { return COLOR; } %{ -// Special characters +// Special characters. %} -"{" { return START; } -"}" { return END; } -"^" { return SUPER; } -"_" { return SUB; } +"{" { return START; } +"}" { return END; } +"^" { return SUPER; } +"_" { return SUB; } -"\\{" | -"\\}" | -"\\^" | -"\\_" | -"\\\\" { yylval->ch = yytext[1]; return CH; } +"\\{" | +"\\}" | +"\\^" | +"\\_" | +"\\\\" { + yylval->ch = yytext[1]; + return CH; + } %{ -// Symbols +// Symbols. %} @SYMBOL_RULES@ %{ -// Generic character +// Generic character. %} -"\n" | -. { yylval->ch = yytext[0]; return CH; } +"\n" | +. { + yylval->ch = yytext[0]; + return CH; + } %% diff -r 72cd24aa5f7a -r e3c0fee87493 libinterp/corefcn/oct-tex-parser.in.yy --- a/libinterp/corefcn/oct-tex-parser.in.yy Fri Oct 02 17:48:58 2015 +0200 +++ b/libinterp/corefcn/oct-tex-parser.in.yy Fri Oct 02 12:25:39 2015 -0400 @@ -21,6 +21,7 @@ */ %{ + #define YYDEBUG 1 #ifdef HAVE_CONFIG_H @@ -34,15 +35,16 @@ static void yyerror (text_parser_tex& parser, const char *s); #if defined (GNULIB_NAMESPACE) -// Calls to the following functions appear in the generated output from -// Bison without the namespace tag. Redefine them so we will use them -// via the gnulib namespace. +// Calls to the following functions appear in the generated output +// from Bison without the namespace tag. Redefine them so we will use +// them via the gnulib namespace. #define fclose GNULIB_NAMESPACE::fclose #define fprintf GNULIB_NAMESPACE::fprintf #define malloc GNULIB_NAMESPACE::malloc #endif #define scanner parser.get_scanner () + %} %API_PREFIX_DECL% @@ -53,16 +55,17 @@ %code requires {#include } -%union { - /* Leaf symbols produced by the scanner */ +%union +{ + // Leaf symbols produced by the scanner. char ch; double num; int sym; - /* Used for string buffering */ + // Used for string buffering. std::string* str; - /* Objects produced by the parser */ + // Objects produced by the parser. text_element* e_base; text_element_list* e_list; } @@ -78,10 +81,11 @@ %type simple_string %type string_element symbol_element %type superscript_element subscript_element combined_script_element -%type font_modifier_element fontname_element fontsize_element color_element +%type font_modifier_element fontname_element fontsize_element +%type color_element %type string_element_list scoped_string_element_list -/* Make sure there's no memory leak on parse error. */ +// Make sure there's no memory leak on parse error. %destructor { } %destructor { delete $$; } <*> @@ -95,105 +99,104 @@ %% -simple_string : CH - { $$ = new std::string (1, $1); } - | simple_string CH - { $1->append (1, $2); $$ = $1; } - ; +simple_string : CH + { $$ = new std::string (1, $1); } + | simple_string CH + { $1->append (1, $2); $$ = $1; } + ; -symbol_element : SYM - { $$ = new text_element_symbol ($1); } - ; +symbol_element : SYM + { $$ = new text_element_symbol ($1); } + ; -font_modifier_element : BF - { $$ = new text_element_fontstyle (text_element_fontstyle::bold); } - | IT - { $$ = new text_element_fontstyle (text_element_fontstyle::italic); } - | SL - { $$ = new text_element_fontstyle (text_element_fontstyle::oblique); } - | RM - { $$ = new text_element_fontstyle (text_element_fontstyle::normal); } - ; +font_modifier_element : BF + { $$ = new text_element_fontstyle (text_element_fontstyle::bold); } + | IT + { $$ = new text_element_fontstyle (text_element_fontstyle::italic); } + | SL + { $$ = new text_element_fontstyle (text_element_fontstyle::oblique); } + | RM + { $$ = new text_element_fontstyle (text_element_fontstyle::normal); } + ; -fontsize_element : FONTSIZE START NUM END - { $$ = new text_element_fontsize ($3); } - ; +fontsize_element : FONTSIZE START NUM END + { $$ = new text_element_fontsize ($3); } + ; -fontname_element : FONTNAME START simple_string END - { - $$ = new text_element_fontname (*$3); - delete $3; - } - ; +fontname_element : FONTNAME START simple_string END + { + $$ = new text_element_fontname (*$3); + delete $3; + } + ; -color_element : COLOR START simple_string END - { - $$ = new text_element_color (*$3); - delete $3; - } - | COLOR_RGB START NUM NUM NUM END - { - $$ = new text_element_color ($3, $4, $5); - } - ; +color_element : COLOR START simple_string END + { + $$ = new text_element_color (*$3); + delete $3; + } + | COLOR_RGB START NUM NUM NUM END + { + $$ = new text_element_color ($3, $4, $5); + } + ; -string_element : simple_string %prec STR - { - $$ = new text_element_string (*$1); - delete $1; - } - | scoped_string_element_list - /* This is just to avoid a warning in bison. */ - { $$ = $1; } - | symbol_element - | font_modifier_element - | fontsize_element - | fontname_element - | color_element - | superscript_element %prec SCRIPT - | subscript_element %prec SCRIPT - | combined_script_element - ; +string_element : simple_string %prec STR + { + $$ = new text_element_string (*$1); + delete $1; + } + | scoped_string_element_list + { $$ = $1; } + | symbol_element + | font_modifier_element + | fontsize_element + | fontname_element + | color_element + | superscript_element %prec SCRIPT + | subscript_element %prec SCRIPT + | combined_script_element + ; -superscript_element : SUPER CH - { $$ = new text_element_superscript ($2); } - | SUPER scoped_string_element_list - { $$ = new text_element_superscript ($2); } - | SUPER symbol_element - { $$ = new text_element_superscript ($2); } - ; +superscript_element : SUPER CH + { $$ = new text_element_superscript ($2); } + | SUPER scoped_string_element_list + { $$ = new text_element_superscript ($2); } + | SUPER symbol_element + { $$ = new text_element_superscript ($2); } + ; -subscript_element : SUB CH - { $$ = new text_element_subscript ($2); } - | SUB scoped_string_element_list - { $$ = new text_element_subscript ($2); } - | SUB symbol_element - { $$ = new text_element_subscript ($2); } - ; +subscript_element : SUB CH + { $$ = new text_element_subscript ($2); } + | SUB scoped_string_element_list + { $$ = new text_element_subscript ($2); } + | SUB symbol_element + { $$ = new text_element_subscript ($2); } + ; -combined_script_element : subscript_element superscript_element - { $$ = new text_element_combined ($1, $2); } - | superscript_element subscript_element - { $$ = new text_element_combined ($1, $2); } - ; +combined_script_element : subscript_element superscript_element + { $$ = new text_element_combined ($1, $2); } + | superscript_element subscript_element + { $$ = new text_element_combined ($1, $2); } + ; -string_element_list : string_element - { $$ = new text_element_list ($1); } - | string_element_list string_element - { $1->push_back ($2); $$ = $1; } - ; +string_element_list : string_element + { $$ = new text_element_list ($1); } + | string_element_list string_element + { $1->push_back ($2); $$ = $1; } + ; -scoped_string_element_list : START string_element_list END - { $$ = $2; } - | START END - { $$ = new text_element_list (); } - ; +scoped_string_element_list : START string_element_list END + { $$ = $2; } + | START END + { $$ = new text_element_list (); } + ; -string : /* empty */ - { parser.set_parse_result (new text_element_string ("")); } - | string_element_list - { parser.set_parse_result ($1); } - ; +string : // empty + { parser.set_parse_result (new text_element_string ("")); } + | string_element_list + { parser.set_parse_result ($1); } + ; %%