changeset 13249:7861a5fd3479

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.
author John W. Eaton <jwe@octave.org>
date Thu, 29 Sep 2011 14:11:39 -0400
parents e36c2f4ea8f5
children f6bbdea030b2
files src/lex.ll src/oct-parse.yy src/octave.gperf src/token.h
diffstat 4 files changed, 44 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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 <tok_val> TRY CATCH
 %token <tok_val> GLOBAL STATIC
 %token <tok_val> FCN_HANDLE
-%token <tok_val> PROPERTIES
-%token <tok_val> METHODS
-%token <tok_val> EVENTS
+%token <tok_val> PROPERTIES METHODS EVENTS ENUMERATION
 %token <tok_val> METAQUERY
 %token <tok_val> SUPERCLASSREF
 %token <tok_val> GET SET
@@ -463,7 +461,7 @@
 
 // Nonterminals we construct.
 %type <comment_type> stash_comment function_beg classdef_beg
-%type <comment_type> properties_beg methods_beg events_beg
+%type <comment_type> properties_beg methods_beg events_beg enum_beg
 %type <sep_type> sep_no_nl opt_sep_no_nl sep opt_sep
 %type <tree_type> input
 %type <tree_constant_type> string constant magic_colon
@@ -503,6 +501,7 @@
 // These types need to be specified.
 %type <dummy_type> attr
 %type <dummy_type> class_event
+%type <dummy_type> class_enum
 %type <dummy_type> class_property
 %type <dummy_type> properties_list
 %type <dummy_type> properties_block
@@ -512,6 +511,8 @@
 %type <dummy_type> attr_list
 %type <dummy_type> events_list
 %type <dummy_type> events_block
+%type <dummy_type> enum_list
+%type <dummy_type> enum_block
 %type <dummy_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;
--- 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
--- 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,