Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Unified Diff: Source/bindings/scripts/blink_idl_parser_test.py

Issue 15801003: IDL parser rewrite in Python (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: [WIP] Full parser Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/bindings/scripts/blink_idl_parser_test.py
diff --git a/Source/bindings/scripts/blink_idl_parser_test.py b/Source/bindings/scripts/blink_idl_parser_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..b007ceff6b14949bf6c4dd35941bcedb59318e41
--- /dev/null
+++ b/Source/bindings/scripts/blink_idl_parser_test.py
@@ -0,0 +1,100 @@
+#!/usr/bin/env python
+# Copyright (C) 2013 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import glob
+import fnmatch
+import os
+import sys
+import unittest
+
+from blink_idl_lexer import BlinkIDLLexer
+from blink_idl_parser import BlinkIDLParser
+
+# Base parser is in Chromium src/tools/idl_parser
+module_path, module_name = os.path.split(__file__)
+tools_dir = os.path.join(module_path, os.pardir, os.pardir, os.pardir, os.pardir, os.pardir, 'tools')
+sys.path.append(tools_dir)
+
+from idl_parser.idl_parser import ParseFile
+
+
+def has_preprocessor_directives(filename):
+ with open(filename) as idl_file:
+ for line in idl_file:
+ if line.startswith('#'):
+ return True
+ return False
+
+
+def parse_files(parser, file_list):
+ nodes = []
+ errors = 0
+ failed_to_tokenize = 0
+ for filename in file_list:
+ if filename == './../../../Source/core/inspector/InspectorInstrumentation.idl':
+ # intentionally invalid IDL (w/ pointers etc.)
+ continue
+
+ # Can't process preprocessor directives
+ if has_preprocessor_directives(filename):
+ continue
+
+ filenode = ParseFile(parser, filename)
+ if filenode is not None:
+ errors += filenode.GetProperty('ERRORS')
+ nodes.append(filenode)
+ else:
+ failed_to_tokenize += 1
+
+ if errors or failed_to_tokenize:
+ print '\nFound %d errors.' % errors
+ print 'Failed to tokenize %d files.\n' % failed_to_tokenize
+
+
+class BlinkIDLParserTest(unittest.TestCase):
+ def setUp(self):
+ self.parser = BlinkIDLParser(BlinkIDLLexer())
+ # self.parser = BlinkIDLParser(BlinkIDLLexer(), debug=True)
+
+ def testParseTestIDLFiles(self):
+ test_idl_dir = os.path.join(module_path, os.pardir, 'tests', 'idls')
+ test_idl_glob = os.path.join(test_idl_dir, '*.idl')
+ idl_list = glob.glob(test_idl_glob)
+ parse_files(self.parser, idl_list)
+
+ def testParseRealIDLFiles(self):
+ idl_list = []
+ source_dir = os.path.join(module_path, os.pardir, os.pardir, os.pardir, 'Source')
+ for root, _, filenames in os.walk(source_dir):
+ for filename in fnmatch.filter(filenames, '*.idl'):
+ idl_list.append(os.path.join(root, filename))
+ parse_files(self.parser, idl_list)
+
+if __name__ == '__main__':
+ unittest.main()

Powered by Google App Engine
This is Rietveld 408576698