bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Python support: patch for code lexer error


From: Dennis Heimbigner
Subject: Python support: patch for code lexer error
Date: Thu, 05 Sep 2013 20:17:47 -0600
User-agent: Thunderbird 2.0.0.24 (Windows/20100228)

>From f486d5adf9ba5cfd572362503024f8e2e01eead2 Mon Sep 17 00:00:00 2001
From: dmh <address@hidden>
Date: Thu, 5 Sep 2013 20:13:58 -0600
Subject: [PATCH] Python: code lexer error

Modify previous python patches as follows:

* data/lalr1.py: allow %code lexer even if %lex-param is not specified
* tests/python.at: add test for %code lexer without %lex-param
---
 data/lalr1.py   | 14 ++++++--------
 tests/python.at | 24 ++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/data/lalr1.py b/data/lalr1.py
index 09fb4fb..a98d88a 100644
--- a/data/lalr1.py
+++ b/data/lalr1.py
@@ -377,10 +377,8 @@ class Lexer :
 
 # If the user specifies %code lexer ...
 # Then insert it here
-]b4_lex_param_if([[class YYLexer (Lexer) :
-]b4_python_indent([b4_percent_code_get([[lexer]])],2)[
-]])[
-
+]b4_percent_code_ifdef([lexer],[[class YYLexer (Lexer) :
+]b4_python_indent([b4_percent_code_get([lexer])],2)[]])[
 
 ##################################################
 # Primary Parser Class
@@ -432,16 +430,16 @@ class 
]b4_parser_class_name[]b4_percent_define_get3([extends], [(], [)])[ :
   ##################################################
 
   # Instantiates the Bison-generated parser.
-  # ]b4_lex_param_if([],[[@@param yylexer The scanner class
+  # ]b4_percent_code_ifdef([lexer],[],[[@@param yylexer The scanner class
   # instance that will supply tokens to the parser.]])[
 
-  def __init__  (self]b4_lex_param_if([],
+  def __init__  (self]b4_percent_code_ifdef([lexer],[],
                  [, yylexer])[]b4_lex_param_if(
                  [, b4_lex_param_decl])[]b4_parse_param_if(
                  [, b4_parse_param_decl])[):
 ]b4_percent_code_get([[init]])[
-]b4_lex_param_if([],[    self.yylexer = yylexer])[
-]b4_lex_param_if([[    self.yylexer = YYLexer(]b4_lex_param_call[)]])[
+]b4_percent_code_ifdef([lexer],[],[    self.yylexer = yylexer])[
+]b4_percent_code_ifdef([lexer],[[    self.yylexer = 
YYLexer(]b4_lex_param_call[)]])[
 ]b4_parse_param_if([[]b4_parse_param_cons[]])[
     self.yyDebugStream = sys.stderr
     self.yydebug = 0
diff --git a/tests/python.at b/tests/python.at
index 8b33ab6..6a08bce 100644
--- a/tests/python.at
+++ b/tests/python.at
@@ -997,6 +997,29 @@ AT_CHECK([grep '^pass' 
YYParser.py],[ignore],[expout],[ignore-nolog])
 AT_BISON_OPTION_POPDEFS
 AT_CLEANUP
 
+# Add a test for defining %code lexer without
+# also defining %lex-param
+
+AT_SETUP([Python test defining %code lexer but not %lex-param])
+
+AT_BISON_OPTION_PUSHDEFS
+
+AT_DATA([YYParser.y],
+[[%language "Python"
+%code lexer {
+]AT_MIN_LEXER_BODY[
+}
+%token END "end"
+%%
+start: END {pass};
+]])
+
+AT_BISON_CHECK([-o YYParser.py YYParser.y])
+
+AT_BISON_OPTION_POPDEFS
+AT_CLEANUP
+
+
 ##################################################
 # Push Parsing tests
 ##################################################
@@ -1636,3 +1659,4 @@ AT_CHECK([[rm -f ./expout; cp -f ./output ./expout]],
     [ignore],[ignore-nolog],[ignore-nolog])
 AT_CHECK([[cat ./stdout]],[ignore],[expout],[ignore-nolog])
 AT_CLEANUP
+
-- 
1.8.4.rc0.1.g8f6a3e5



reply via email to

[Prev in Thread] Current Thread [Next in Thread]