[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Python support: Add extra test and fix automatic indent bug
From: |
Dennis Heimbigner |
Subject: |
Python support: Add extra test and fix automatic indent bug |
Date: |
Sat, 07 Sep 2013 10:08:43 -0600 |
User-agent: |
Thunderbird 2.0.0.24 (Windows/20100228) |
>From 3101ff4dfb99192ac29d309c86971457741fe707 Mon Sep 17 00:00:00 2001
From: dmh <address@hidden>
Date: Sat, 7 Sep 2013 10:06:00 -0600
Subject: [PATCH] Python: Extra tests and bug fixes
1. Add extra test to the %code lexer w/o %lex-param tests.
2. Fix bug in the automatic indenting.
3. Remove some unused macros.
---
data/lalr1.py | 19 +++++++++----------
data/python.m4 | 28 +---------------------------
tests/python.at | 12 ++++++++----
3 files changed, 18 insertions(+), 41 deletions(-)
diff --git a/data/lalr1.py b/data/lalr1.py
index a98d88a..5b14e23 100644
--- a/data/lalr1.py
+++ b/data/lalr1.py
@@ -31,9 +31,6 @@
m4_include(b4_pkgdatadir/[python.m4])
-# Adding text location lines to Python must be suppressed because it
-# causes python compilation errors
-
b4_defines_if([b4_fatal([%s: %%defines does not make sense in Python],
[b4_skeleton])])
@@ -46,13 +43,12 @@
m4_define([b4_parse_param_if],[m4_ifset([b4_parse_param],[$1],[$2])])
# non-used flags.
b4_parse_trace_if([0], [0])
-# Destructors are not supported
+# Destructors are not supported (yet)
m4_define([b4_symbol_no_destructor_assert],
-
[b4_symbol_if([$1], [has_destructor],
- [b4_fatal([%s: %s: %%destructor not supporte in Python],
- [b4_skeleton],
- [b4_symbol_action_location([$1], [destructor])])])])
+ [b4_fatal([%s: %s: %%destructor not supported in Python (yet)],
+ [b4_skeleton],
+ [b4_symbol_action_location([$1], [destructor])])])])
b4_symbol_foreach([b4_symbol_no_destructor_assert])
# Define a macro to encapsulate the parse state variables.
@@ -375,10 +371,13 @@ class Lexer :
]b4_locations_if([[s = str(location) + ": " + s]])[
sys.stderr.write(s+'\n')
+
# If the user specifies %code lexer ...
# Then insert it here
-]b4_percent_code_ifdef([lexer],[[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
diff --git a/data/python.m4 b/data/python.m4
index 518dd05..2c64a56 100644
--- a/data/python.m4
+++ b/data/python.m4
@@ -120,26 +120,6 @@ m4_define([b4_lex_param], b4_lex_param)
m4_define([b4_parse_param], b4_parse_param)
########################
-# Since python is untyped, %lex-param and %parse-param
-# deliver the following format to the skeleton.
-# So it is necessary to untangle this (Ugh!).
-# [[lex_param1]], [[lex_param1]],
-# [[lex_param2]], [[lex_param2]]
-# and
-# |[[parse_param1]], [[parse_param1]],
-# [[parse_param2]], [[parse_param2]]
-# to
-# [lex_param1, lex_param2]
-# and
-# [parse_param1, parse_param2]
-#
-
-m4_define([b4_param_fix],
- [m4_bpatsubst(m4_normalize(m4_foreach([x],[$1],[ x])),[[ ]],[, ])])
-
-########################
-
-
# b4_lex_param_decl
# -----------------
# Extra formal arguments of the Lexer constructor.
@@ -208,12 +188,6 @@ m4_define([b4_identification],
# -------
m4_define([b4_null], [None])
-# b4_lexer_if(TRUE, FALSE)
-# ------------------------
-# True if parser contains %code lexer {...} else false
-m4_define([b4_lexer_if],
-[b4_percent_code_ifdef([[lexer]], [$1], [$2])])
-
# b4_typed_parser_table_define(TYPE, NAME, DATA, COMMENT)
# -------------------------------------------------------
m4_define([b4_typed_parser_table_define],
@@ -250,7 +224,7 @@ m4_define([b4_python_nblanks],[m4_substr([ ],1,$1)])
m4_define([b4_integral_parser_table_define],
[b4_typed_parser_table_define(None, [$1], [$2], [$3])])
-# b4-case(ID, CODE)
+# b4_case(ID, CODE)
# -----------------
# This is complicated for python because
# each line of the body of the action
diff --git a/tests/python.at b/tests/python.at
index 6a08bce..1c98dd1 100644
--- a/tests/python.at
+++ b/tests/python.at
@@ -386,6 +386,7 @@ import string
# Run minimal parser with specified directives and lex params
m4_define([AT_MIN_LEXER_BODY],[[
+ # Minimal lexer
def __init__(self]AT_LEXPARAM_IF([, AT_COMMIFY(AT_NORMALIZE($1))])[):
self.count=0
def getStartPos(self) : return Position(0,0)
@@ -745,7 +746,7 @@ AT_DIRECTIVES_TEST1([
[lexparam1]
)
AT_CHECK_PYTHON_GREP([YYParser.py],
- [^ def __init__[[ ]]*(self,[[ ]]*lexparam1)],[2])
+ [^ *def __init__[[ ]]*(self,[[ ]]*lexparam1)],[2])
AT_CHECK_PYTHON_GREP([YYParser.py],
[^[[ ]]*self.yylexer[[ ]]*=[[ ]]*YYLexer(lexparam1)])
@@ -756,9 +757,9 @@ AT_DIRECTIVES_TEST1([
[lexparam1 lexparam2]
)
AT_CHECK_PYTHON_GREP([YYParser.py],
- [^ def __init__[[ ]]*(self,[[ ]]*lexparam1,[[ ]*]lexparam2)],[2])
+ [^ *def __init__[[ ]]*(self,[[ ]]*lexparam1,[[ ]*]lexparam2)],[2])
AT_CHECK_PYTHON_GREP([YYParser.py],
- [^[[ ]]*self.yylexer[[ ]]*=[[ ]]*YYLexer(lexparam1,[[ ]*]lexparam2)])
+ [^ *self.yylexer[[ ]]*=[[ ]]*YYLexer(lexparam1,[[ ]*]lexparam2)])
AT_DIRECTIVES_TEST1([
@@ -771,7 +772,7 @@ AT_DIRECTIVES_TEST1([
[parseparam1 parseparam2]
)
AT_CHECK_PYTHON_GREP([YYParser.py],
- [^ def __init__[[ ]]*(self,[[ ]]*lexparam1,[[ ]]*lexparam2[[ ]]*)])
+ [^ *def __init__[[ ]]*(self,[[ ]]*lexparam1,[[ ]]*lexparam2[[ ]]*)])
AT_CHECK_PYTHON_GREP([YYParser.py],
[^ self.yylexer[[ ]]*=[[ ]]*YYLexer(lexparam1,[[ ]]*lexparam2)])
AT_CHECK_PYTHON_GREP([YYParser.py],
@@ -1015,6 +1016,7 @@ start: END {pass};
]])
AT_BISON_CHECK([-o YYParser.py YYParser.y])
+AT_CHECK_PYTHON_GREP([YYParser.py],[^ *# Minimal lexer *$])
AT_BISON_OPTION_POPDEFS
AT_CLEANUP
@@ -1658,5 +1660,7 @@ AT_CHECK([[sed -e '/^Next token.*$/p' -e d ./stderr]],
AT_CHECK([[rm -f ./expout; cp -f ./output ./expout]],
[ignore],[ignore-nolog],[ignore-nolog])
AT_CHECK([[cat ./stdout]],[ignore],[expout],[ignore-nolog])
+
+AT_BISON_OPTION_POPDEFS
AT_CLEANUP
--
1.8.4.rc0.1.g8f6a3e5
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Python support: Add extra test and fix automatic indent bug,
Dennis Heimbigner <=