# HG changeset patch # User John W. Eaton # Date 1317319899 14400 # Node ID 7861a5fd3479c40892161cb48ed1c37079bb2309 # Parent e36c2f4ea8f554771386c04228af81071681ca73 accept enumeration keyword * octave.gperf (octave_kw_id): New keyword ids, enumeration_kw and endenumeration_kw. (octave_kw): Add enumeration and endenumeration to the struct. * lex.ll (is_keyword_token): Handle enumeration and endenumeration. * oct-parse.yy (ENUMERATION): New token. (enum_beg, enum_block, enum_list, class_enum): New non-terminals. (class_body): Accept enum_block. * token.h (token::enumeration_end): New end_tok_type enum value. diff -r e36c2f4ea8f5 -r 7861a5fd3479 src/lex.ll --- a/src/lex.ll Thu Sep 29 12:31:39 2011 +0200 +++ b/src/lex.ll Thu Sep 29 14:11:39 2011 -0400 @@ -1541,6 +1541,11 @@ lexer_flags.at_beginning_of_statement = true; break; + case endenumeration_kw: + yylval.tok_val = new token (token::enumeration_end, l, c); + lexer_flags.at_beginning_of_statement = true; + break; + case endevents_kw: yylval.tok_val = new token (token::events_end, l, c); lexer_flags.at_beginning_of_statement = true; @@ -1589,9 +1594,10 @@ return 0; break; - case properties_kw: + case enumeration_kw: + case events_kw: case methods_kw: - case events_kw: + case properties_kw: // 'properties', 'methods' and 'events' are keywords for // classdef blocks. if (! lexer_flags.parsing_classdef) diff -r e36c2f4ea8f5 -r 7861a5fd3479 src/oct-parse.yy --- a/src/oct-parse.yy Thu Sep 29 12:31:39 2011 +0200 +++ b/src/oct-parse.yy Thu Sep 29 14:11:39 2011 -0400 @@ -448,9 +448,7 @@ %token TRY CATCH %token GLOBAL STATIC %token FCN_HANDLE -%token PROPERTIES -%token METHODS -%token EVENTS +%token PROPERTIES METHODS EVENTS ENUMERATION %token METAQUERY %token SUPERCLASSREF %token GET SET @@ -463,7 +461,7 @@ // Nonterminals we construct. %type stash_comment function_beg classdef_beg -%type properties_beg methods_beg events_beg +%type properties_beg methods_beg events_beg enum_beg %type sep_no_nl opt_sep_no_nl sep opt_sep %type input %type string constant magic_colon @@ -503,6 +501,7 @@ // These types need to be specified. %type attr %type class_event +%type class_enum %type class_property %type properties_list %type properties_block @@ -512,6 +511,8 @@ %type attr_list %type events_list %type events_block +%type enum_list +%type enum_block %type class_body // Precedence and associativity. @@ -1537,12 +1538,16 @@ { $$ = 0; } | events_block { $$ = 0; } + | enum_block + { $$ = 0; } | class_body '\n' properties_block { $$ = 0; } | class_body '\n' methods_block { $$ = 0; } | class_body '\n' events_block { $$ = 0; } + | class_body '\n' enum_block + { $$ = 0; } ; properties_beg : PROPERTIES stash_comment @@ -1599,6 +1604,24 @@ { $$ = 0; } ; +enum_beg : ENUMERATION stash_comment + { $$ = 0; } + ; + +enum_block : enum_beg opt_attr_list '\n' enum_list '\n' END + { $$ = 0; } + ; + +enum_list : class_enum + { $$ = 0; } + | enum_list '\n' class_enum + { $$ = 0; } + ; + +class_enum : identifier '(' expression ')' + { $$ = 0; } + ; + // ============= // Miscellaneous // ============= @@ -1777,6 +1800,10 @@ end_error ("for", ettype, l, c); break; + case token::enumeration_end: + end_error ("enumeration", ettype, l, c); + break; + case token::function_end: end_error ("function", ettype, l, c); break; diff -r e36c2f4ea8f5 -r 7861a5fd3479 src/octave.gperf --- a/src/octave.gperf Thu Sep 29 12:31:39 2011 +0200 +++ b/src/octave.gperf Thu Sep 29 14:11:39 2011 -0400 @@ -38,6 +38,7 @@ end_try_catch_kw, end_unwind_protect_kw, endclassdef_kw, + endenumeration_kw, endevents_kw, endfor_kw, endfunction_kw, @@ -47,6 +48,7 @@ endproperties_kw, endswitch_kw, endwhile_kw, + enumeration_kw, events_kw, for_kw, function_kw, @@ -84,6 +86,7 @@ end_try_catch, END, end_try_catch_kw end_unwind_protect, END, end_unwind_protect_kw endclassdef, END, endclassdef_kw +endenumeration, END, endenumeration_kw endevents, END, endevents_kw endfor, END, endfor_kw endfunction, END, endfunction_kw @@ -93,6 +96,7 @@ endproperties, END, endproperties_kw endswitch, END, endswitch_kw endwhile, END, endwhile_kw +enumeration, ENUMERATION, enumeration_kw events, EVENTS, events_kw for, FOR, for_kw function, FCN, function_kw diff -r e36c2f4ea8f5 -r 7861a5fd3479 src/token.h --- a/src/token.h Thu Sep 29 12:31:39 2011 +0200 +++ b/src/token.h Thu Sep 29 14:11:39 2011 -0400 @@ -45,6 +45,7 @@ { simple_end, classdef_end, + enumeration_end, events_end, for_end, function_end,