changeset 16265:71ee3afedb69

5/10 commits reworking the lexer
author John W. Eaton <jwe@octave.org>
date Mon, 11 Mar 2013 14:29:19 -0400
parents 9acb86e6ac90
children 36e01847694f 15f55df088e7
files libinterp/parse-tree/lex.h libinterp/parse-tree/lex.ll libinterp/parse-tree/oct-parse.in.yy
diffstat 3 files changed, 32 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.h	Mon Mar 11 14:28:11 2013 -0400
+++ b/libinterp/parse-tree/lex.h	Mon Mar 11 14:29:19 2013 -0400
@@ -73,7 +73,8 @@
       {
         BRACKET = 1,
         BRACE = 2,
-        PAREN = 3
+        PAREN = 3,
+        ANON_FCN_BODY = 4
       };
 
   public:
@@ -119,6 +120,13 @@
       return ! context.empty () && context.top () == PAREN;
     }
 
+    void anon_fcn_body (void) { context.push (ANON_FCN_BODY); }
+
+    bool is_anon_fcn_body (void)
+    {
+      return ! context.empty () && context.top () == ANON_FCN_BODY;
+    }
+
     bool is_bracket_or_brace (void)
     {
       return (! context.empty ()
@@ -385,8 +393,8 @@
   // set of identifiers that might be local variable names.
   std::set<std::string> pending_local_variables;
 
-  // is the closest nesting level a square bracket, squiggly brace or
-  // a paren?
+  // is the closest nesting level a square bracket, squiggly brace,
+  // a paren, or an anonymous function body?
   bbp_nesting_level nesting_level;
 
   // Tokens generated by the lexer.
--- a/libinterp/parse-tree/lex.ll	Mon Mar 11 14:28:11 2013 -0400
+++ b/libinterp/parse-tree/lex.ll	Mon Mar 11 14:29:19 2013 -0400
@@ -821,7 +821,14 @@
 "||"    { return curr_lexer->handle_op ("||", EXPR_OR_OR); }
 "<<"    { return curr_lexer->handle_incompatible_op ("<<", LSHIFT); }
 ">>"    { return curr_lexer->handle_incompatible_op (">>", RSHIFT); }
-";"     { return curr_lexer->handle_op (";", ';', true, true); }
+
+";" {
+    bool at_beginning_of_statement
+      = (! (curr_lexer->whitespace_is_significant ()
+            || curr_lexer->looking_at_object_index.front ()));
+
+    return curr_lexer->handle_op (";", ';', true, at_beginning_of_statement);
+  }
 
 "+" {
    int tok = curr_lexer->handle_unary_op ("+", '+');
@@ -887,8 +894,12 @@
   }
 
 "," {
+    bool at_beginning_of_statement
+      = (! (curr_lexer->whitespace_is_significant ()
+            || curr_lexer->looking_at_object_index.front ()));
+
     return curr_lexer->handle_op
-      (",", ',', true, ! curr_lexer->looking_at_object_index.front ());
+      (",", ',', true, at_beginning_of_statement);
   }
 
 ".'" {
@@ -974,7 +985,10 @@
     curr_lexer->at_beginning_of_statement = false;
 
     if (curr_lexer->looking_at_anon_fcn_args)
-      curr_lexer->looking_at_anon_fcn_args = false;
+      {
+        curr_lexer->looking_at_anon_fcn_args = false;
+        curr_lexer->nesting_level.anon_fcn_body ();
+      }
 
     return curr_lexer->count_token (')');
   }
--- a/libinterp/parse-tree/oct-parse.in.yy	Mon Mar 11 14:28:11 2013 -0400
+++ b/libinterp/parse-tree/oct-parse.in.yy	Mon Mar 11 14:29:19 2013 -0400
@@ -502,7 +502,10 @@
                 ;
 
 anon_fcn_handle : '@' param_list statement
-                  { $$ = curr_parser.make_anon_fcn_handle ($2, $3); }
+                  {
+                    $$ = curr_parser.make_anon_fcn_handle ($2, $3);
+                    curr_lexer->nesting_level.remove ();
+                  }
                 ;
 
 primary_expr    : identifier