Reviewers: dcarney,

Message:
Committed patchset #1 manually as r17677 (presubmit successful).

Description:
Experimental lexer generator: add a test for the code generator.

BUG=
[email protected]

Committed: https://code.google.com/p/v8/source/detail?r=17677

Please review this at https://codereview.chromium.org/71273003/

SVN Base: https://v8.googlecode.com/svn/branches/experimental/parser

Affected files (+19, -19 lines):
  M tools/lexer_generator/code_generator.py
  A + tools/lexer_generator/code_generator_test.py
  M tools/lexer_generator/test_suite.py


Index: tools/lexer_generator/code_generator.py
diff --git a/tools/lexer_generator/code_generator.py b/tools/lexer_generator/code_generator.py index cafa0841bdfd7cb40988e7fd5f49a4bb349cbd29..559b8d95442a666c9f8d858a0d4c8b5321accf43 100644
--- a/tools/lexer_generator/code_generator.py
+++ b/tools/lexer_generator/code_generator.py
@@ -63,10 +63,10 @@ code_%s:

     action = state.action()
     if action:
-      if action[1] == 'terminate':
+      if action.type() == 'terminate':
         code += 'return 0;'
         return code
-      elif action[1] == 'terminate_illegal':
+      elif action.type() == 'terminate_illegal':
         code += 'return 1;'
         return code

@@ -82,7 +82,7 @@ code_%s:
 ''' % s.node_number()

     if action:
- code += '%s\nyych = *(--cursor_);\ngoto code_%s;\n' % (state.action()[1],
+      code += '%s\nyych = *(--cursor_);\ngoto code_%s;\n' % (action.data(),
start_node_number)
     return code

Index: tools/lexer_generator/code_generator_test.py
diff --git a/WATCHLISTS b/tools/lexer_generator/code_generator_test.py
similarity index 77%
copy from WATCHLISTS
copy to tools/lexer_generator/code_generator_test.py
index 9c2bce9c5589c22649b4a2c94837f00c8d669be1..92ed6f971228b37e3baf0dd5842807c800f0d9ac 100644
--- a/WATCHLISTS
+++ b/tools/lexer_generator/code_generator_test.py
@@ -25,22 +25,20 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-# Watchlist Rules
-# Refer: http://dev.chromium.org/developers/contributing-code/watchlists
+import unittest
+from code_generator import CodeGenerator
+from rule_parser import RuleProcessor

-# IMPORTANT: The regular expression filepath is tested against each path using
-# re.search, so it is not usually necessary to add .*.
+class CodeGeneratorTestCase(unittest.TestCase):

-{
-  'WATCHLIST_DEFINITIONS': {
-    'public_api': {
-      'filepath': 'include/',
-    },
-  },
+  def test_simple(self):
+    rules = '''
+    <default>
+    "("           { LBRACE }
+    ")"           { RBRACE }

-  'WATCHLISTS': {
-    'public_api': [
-      '[email protected]',
-    ],
-  },
-}
+    "foo"         { FOO }
+    eof           <<terminate>>'''
+    rule_processor = RuleProcessor.parse(rules)
+    (nfa, dfa) = rule_processor.default_automata()
+    CodeGenerator.dfa_to_code(dfa)
Index: tools/lexer_generator/test_suite.py
diff --git a/tools/lexer_generator/test_suite.py b/tools/lexer_generator/test_suite.py index b51db6ac02ada6a342f78757ce3d114bf9487043..39ea037846fff201e0c6067ed7793c537d40bc88 100644
--- a/tools/lexer_generator/test_suite.py
+++ b/tools/lexer_generator/test_suite.py
@@ -29,6 +29,7 @@ from unittest import TestLoader, TextTestRunner, TestSuite

 from action_test import *
 from automata_test import *
+from code_generator_test import *
 from lexer_test import *
 from rule_parser_test import *
 from transition_key_test import *
@@ -41,6 +42,7 @@ if __name__ == "__main__":
     loader.loadTestsFromTestCase(RuleParserTestCase),
     loader.loadTestsFromTestCase(ActionTestCase),
     loader.loadTestsFromTestCase(LexerTestCase),
+    loader.loadTestsFromTestCase(CodeGeneratorTestCase),
   ))
   runner = TextTestRunner(verbosity = 2)
   runner.run(suite)


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to