aboutsummaryrefslogtreecommitdiff
path: root/third_party/ply/test
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-07-03 23:51:38 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-07-03 23:51:38 -0700
commit7653c3b900216a31fd3b6d64afff486bd597111e (patch)
tree3b5a9a3f34009e54c69685d02439cb4dae9e4308 /third_party/ply/test
parent15db95111555a911e295725141ddd10323a85373 (diff)
initial work on bindings generator, using CppHeaderParser and ply. llvm-gcc only for now
Diffstat (limited to 'third_party/ply/test')
-rw-r--r--third_party/ply/test/README7
-rw-r--r--third_party/ply/test/calclex.py49
-rwxr-xr-xthird_party/ply/test/cleanup.sh4
-rw-r--r--third_party/ply/test/lex_closure.py54
-rw-r--r--third_party/ply/test/lex_doc1.py26
-rw-r--r--third_party/ply/test/lex_dup1.py29
-rw-r--r--third_party/ply/test/lex_dup2.py33
-rw-r--r--third_party/ply/test/lex_dup3.py31
-rw-r--r--third_party/ply/test/lex_empty.py20
-rw-r--r--third_party/ply/test/lex_error1.py24
-rw-r--r--third_party/ply/test/lex_error2.py26
-rw-r--r--third_party/ply/test/lex_error3.py27
-rw-r--r--third_party/ply/test/lex_error4.py27
-rw-r--r--third_party/ply/test/lex_hedit.py47
-rw-r--r--third_party/ply/test/lex_ignore.py31
-rw-r--r--third_party/ply/test/lex_ignore2.py29
-rw-r--r--third_party/ply/test/lex_literal1.py25
-rw-r--r--third_party/ply/test/lex_literal2.py25
-rw-r--r--third_party/ply/test/lex_many_tokens.py27
-rw-r--r--third_party/ply/test/lex_module.py10
-rw-r--r--third_party/ply/test/lex_module_import.py42
-rw-r--r--third_party/ply/test/lex_object.py55
-rw-r--r--third_party/ply/test/lex_opt_alias.py54
-rw-r--r--third_party/ply/test/lex_optimize.py50
-rw-r--r--third_party/ply/test/lex_optimize2.py50
-rw-r--r--third_party/ply/test/lex_optimize3.py52
-rw-r--r--third_party/ply/test/lex_re1.py27
-rw-r--r--third_party/ply/test/lex_re2.py27
-rw-r--r--third_party/ply/test/lex_re3.py29
-rw-r--r--third_party/ply/test/lex_rule1.py27
-rw-r--r--third_party/ply/test/lex_rule2.py29
-rw-r--r--third_party/ply/test/lex_rule3.py27
-rw-r--r--third_party/ply/test/lex_state1.py40
-rw-r--r--third_party/ply/test/lex_state2.py40
-rw-r--r--third_party/ply/test/lex_state3.py42
-rw-r--r--third_party/ply/test/lex_state4.py41
-rw-r--r--third_party/ply/test/lex_state5.py40
-rw-r--r--third_party/ply/test/lex_state_noerror.py39
-rw-r--r--third_party/ply/test/lex_state_norule.py40
-rw-r--r--third_party/ply/test/lex_state_try.py45
-rw-r--r--third_party/ply/test/lex_token1.py19
-rw-r--r--third_party/ply/test/lex_token2.py22
-rw-r--r--third_party/ply/test/lex_token3.py24
-rw-r--r--third_party/ply/test/lex_token4.py26
-rw-r--r--third_party/ply/test/lex_token5.py31
-rw-r--r--third_party/ply/test/lex_token_dup.py29
-rwxr-xr-xthird_party/ply/test/testlex.py606
-rw-r--r--third_party/ply/test/testyacc.py347
-rw-r--r--third_party/ply/test/yacc_badargs.py68
-rw-r--r--third_party/ply/test/yacc_badid.py77
-rw-r--r--third_party/ply/test/yacc_badprec.py64
-rw-r--r--third_party/ply/test/yacc_badprec2.py68
-rw-r--r--third_party/ply/test/yacc_badprec3.py68
-rw-r--r--third_party/ply/test/yacc_badrule.py68
-rw-r--r--third_party/ply/test/yacc_badtok.py68
-rw-r--r--third_party/ply/test/yacc_dup.py68
-rw-r--r--third_party/ply/test/yacc_error1.py68
-rw-r--r--third_party/ply/test/yacc_error2.py68
-rw-r--r--third_party/ply/test/yacc_error3.py67
-rw-r--r--third_party/ply/test/yacc_error4.py72
-rw-r--r--third_party/ply/test/yacc_inf.py56
-rw-r--r--third_party/ply/test/yacc_literal.py69
-rw-r--r--third_party/ply/test/yacc_misplaced.py68
-rw-r--r--third_party/ply/test/yacc_missing1.py68
-rw-r--r--third_party/ply/test/yacc_nested.py33
-rw-r--r--third_party/ply/test/yacc_nodoc.py67
-rw-r--r--third_party/ply/test/yacc_noerror.py66
-rw-r--r--third_party/ply/test/yacc_nop.py68
-rw-r--r--third_party/ply/test/yacc_notfunc.py66
-rw-r--r--third_party/ply/test/yacc_notok.py67
-rw-r--r--third_party/ply/test/yacc_prec1.py68
-rw-r--r--third_party/ply/test/yacc_rr.py72
-rw-r--r--third_party/ply/test/yacc_rr_unused.py30
-rw-r--r--third_party/ply/test/yacc_simple.py68
-rw-r--r--third_party/ply/test/yacc_sr.py63
-rw-r--r--third_party/ply/test/yacc_term1.py68
-rw-r--r--third_party/ply/test/yacc_unused.py77
-rw-r--r--third_party/ply/test/yacc_unused_rule.py72
-rw-r--r--third_party/ply/test/yacc_uprec.py63
-rw-r--r--third_party/ply/test/yacc_uprec2.py63
80 files changed, 4547 insertions, 0 deletions
diff --git a/third_party/ply/test/README b/third_party/ply/test/README
new file mode 100644
index 00000000..dc74ba3e
--- /dev/null
+++ b/third_party/ply/test/README
@@ -0,0 +1,7 @@
+This directory mostly contains tests for various types of error
+conditions. To run:
+
+ $ python testlex.py .
+ $ python testyacc.py .
+
+The script 'cleanup.sh' cleans up this directory to its original state.
diff --git a/third_party/ply/test/calclex.py b/third_party/ply/test/calclex.py
new file mode 100644
index 00000000..67d245f1
--- /dev/null
+++ b/third_party/ply/test/calclex.py
@@ -0,0 +1,49 @@
+# -----------------------------------------------------------------------------
+# calclex.py
+# -----------------------------------------------------------------------------
+import sys
+
+if ".." not in sys.path: sys.path.insert(0,"..")
+import ply.lex as lex
+
+tokens = (
+ 'NAME','NUMBER',
+ 'PLUS','MINUS','TIMES','DIVIDE','EQUALS',
+ 'LPAREN','RPAREN',
+ )
+
+# Tokens
+
+t_PLUS = r'\+'
+t_MINUS = r'-'
+t_TIMES = r'\*'
+t_DIVIDE = r'/'
+t_EQUALS = r'='
+t_LPAREN = r'\('
+t_RPAREN = r'\)'
+t_NAME = r'[a-zA-Z_][a-zA-Z0-9_]*'
+
+def t_NUMBER(t):
+ r'\d+'
+ try:
+ t.value = int(t.value)
+ except ValueError:
+ print("Integer value too large %s" % t.value)
+ t.value = 0
+ return t
+
+t_ignore = " \t"
+
+def t_newline(t):
+ r'\n+'
+ t.lineno += t.value.count("\n")
+
+def t_error(t):
+ print("Illegal character '%s'" % t.value[0])
+ t.lexer.skip(1)
+
+# Build the lexer
+lex.lex()
+
+
+
diff --git a/third_party/ply/test/cleanup.sh b/third_party/ply/test/cleanup.sh
new file mode 100755
index 00000000..9374f2c6
--- /dev/null
+++ b/third_party/ply/test/cleanup.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+rm -rf *~ *.pyc *.pyo *.dif *.out __pycache__
+
diff --git a/third_party/ply/test/lex_closure.py b/third_party/ply/test/lex_closure.py
new file mode 100644
index 00000000..30ee6791
--- /dev/null
+++ b/third_party/ply/test/lex_closure.py
@@ -0,0 +1,54 @@
+# -----------------------------------------------------------------------------
+# lex_closure.py
+# -----------------------------------------------------------------------------
+import sys
+
+if ".." not in sys.path: sys.path.insert(0,"..")
+import ply.lex as lex
+
+tokens = (
+ 'NAME','NUMBER',
+ 'PLUS','MINUS','TIMES','DIVIDE','EQUALS',
+ 'LPAREN','RPAREN',
+ )
+
+def make_calc():
+
+ # Tokens
+
+ t_PLUS = r'\+'
+ t_MINUS = r'-'
+ t_TIMES = r'\*'
+ t_DIVIDE = r'/'
+ t_EQUALS = r'='
+ t_LPAREN = r'\('
+ t_RPAREN = r'\)'
+ t_NAME = r'[a-zA-Z_][a-zA-Z0-9_]*'
+
+ def t_NUMBER(t):
+ r'\d+'
+ try:
+ t.value = int(t.value)
+ except ValueError:
+ print("Integer value too large %s" % t.value)
+ t.value = 0
+ return t
+
+ t_ignore = " \t"
+
+ def t_newline(t):
+ r'\n+'
+ t.lineno += t.value.count("\n")
+
+ def t_error(t):
+ print("Illegal character '%s'" % t.value[0])
+ t.lexer.skip(1)
+
+ # Build the lexer
+ return lex.lex()
+
+make_calc()
+lex.runmain(data="3+4")
+
+
+
diff --git a/third_party/ply/test/lex_doc1.py b/third_party/ply/test/lex_doc1.py
new file mode 100644
index 00000000..8a2bfcce
--- /dev/null
+++ b/third_party/ply/test/lex_doc1.py
@@ -0,0 +1,26 @@
+# lex_doc1.py
+#
+# Missing documentation string
+
+import sys
+if ".." not in sys.path: sys.path.insert(0,"..")
+
+import ply.lex as lex
+
+tokens = [
+ "PLUS",
+ "MINUS",
+ "NUMBER",
+ ]
+
+t_PLUS = r'\+'
+t_MINUS = r'-'
+def t_NUMBER(t):
+ pass
+
+def t_error(t):
+ pass
+
+lex.lex()
+
+
diff --git a/third_party/ply/test/lex_dup1.py b/third_party/ply/test/lex_dup1.py
new file mode 100644
index 00000000..fd04cdb7
--- /dev/null
+++ b/third_party/ply/test/lex_dup1.py
@@ -0,0 +1,29 @@
+# lex_dup1.py
+#
+# Duplicated rule specifiers
+
+import sys
+if ".." not in sys.path: sys.path.insert(0,"..")
+
+import ply.lex as lex
+
+tokens = [
+ "PLUS",
+ "MINUS",
+ "NUMBER",
+ ]
+
+t_PLUS = r'\+'
+t_MINUS = r'-'
+t_NUMBER = r'\d+'
+
+t_NUMBER = r'\d+'
+
+def t_error(t):
+ pass
+
+
+
+lex.lex()
+
+
diff --git a/third_party/ply/test/lex_dup2.py b/third_party/ply/test/lex_dup2.py
new file mode 100644
index 00000000..870e5e7d
--- /dev/null
+++ b/third_party/ply/test/lex_dup2.py
@@ -0,0 +1,33 @@
+# lex_dup2.py
+#
+# Duplicated rule specifiers
+
+import sys
+if ".." not in sys.path: sys.path.insert(0,"..")
+
+import ply.lex as lex
+
+tokens = [
+ "PLUS",
+ "MINUS",
+ "NUMBER",
+ ]
+
+t_PLUS = r'\+'
+t_MINUS = r'-'
+def t_NUMBER(t):
+ r'\d+'
+ pass
+
+def t_NUMBER(t):
+ r'\d+'
+ pass
+
+def t_error(t):
+ pass
+
+
+
+lex.lex()
+
+
diff --git a/third_party/ply/test/lex_dup3.py b/third_party/ply/test/lex_dup3.py
new file mode 100644
index 00000000..94b5592e
--- /dev/null
+++ b/third_party/ply/test/lex_dup3.py
@@ -0,0 +1,31 @@
+# lex_dup3.py
+#
+# Duplicated rule specifiers
+
+import sys
+if ".." not in sys.path: sys.path.insert(0,"..")
+
+import ply.lex as lex
+
+tokens = [
+ "PLUS",
+ "MINUS",
+ "NUMBER",
+ ]
+
+t_PLUS = r'\+'
+t_MINUS = r'-'
+t_NUMBER = r'\d+'
+
+def t_NUMBER(t):
+ r'\d+'
+ pass
+
+def t_error(t):
+ pass
+
+
+
+lex.lex()
+
+
diff --git a/third_party/ply/test/lex_empty.py b/third_party/ply/test/lex_empty.py
new file mode 100644
index 00000000..e0368bfa
--- /dev/null
+++ b/third_party/ply/test/lex_empty.py
@@ -0,0 +1,20 @@
+# lex_empty.py
+#
+# No rules defined
+
+import sys
+if ".." not in sys.path: sys.path.insert(0,"..")
+
+import ply.lex as lex
+
+tokens = [
+ "PLUS",
+ "MINUS",
+ "NUMBER",
+ ]
+
+
+
+lex.lex()
+
+
diff --git a/third_party/ply/test/lex_error1.py b/third_party/ply/test/lex_error1.py
new file mode 100644
index 00000000..4508a808
--- /dev/null
+++ b/third_party/ply/test/lex_error1.py
@@ -0,0 +1,24 @@
+# lex_error1.py
+#
+# Missing t_error() rule
+
+import sys
+if ".." not in sys.path: sys.path.insert(0,"..")
+
+import ply.lex as lex
+
+tokens = [
+ "PLUS",
+ "MINUS",
+ "NUMBER",
+ ]
+
+t_PLUS = r'\+'
+t_MINUS = r'-'
+t_NUMBER = r'\d+'
+
+
+
+lex.lex()
+
+
diff --git a/third_party/ply/test/lex_error2.py b/third_party/ply/test/lex_error2.py
new file mode 100644
index 00000000..8040d390
--- /dev/null
+++ b/third_party/ply/test/lex_error2.py
@@ -0,0 +1,26 @@
+# lex_error2.py
+#
+# t_error defined, but not function
+
+import sys
+if ".." not in sys.path: sys.path.insert(0,"..")
+
+import ply.lex as lex
+
+tokens = [
+ "PLUS",
+ "MINUS",
+ "NUMBER",
+ ]
+
+t_PLUS = r'\+'
+t_MINUS = r'-'
+t_NUMBER = r'\d+'
+
+t_error = "foo"
+
+
+
+lex.lex()
+
+
diff --git a/third_party/ply/test/lex_error3.py b/third_party/ply/test/lex_error3.py
new file mode 100644
index 00000000..1feefb64
--- /dev/null
+++ b/third_party/ply/test/lex_error3.py
@@ -0,0 +1,27 @@
+# lex_error3.py
+#
+# t_error defined as function, but with wrong # args
+
+import sys
+if ".." not in sys.path: sys.path.insert(0,"..")
+
+import ply.lex as lex
+
+tokens = [
+ "PLUS",
+ "MINUS",
+ "NUMBER",
+ ]
+
+t_PLUS = r'\+'
+t_MINUS = r'-'
+t_NUMBER = r'\d+'
+
+def t_error():
+ pass
+
+
+
+lex.lex()
+
+
diff --git a/third_party/ply/test/lex_error4.py b/third_party/ply/test/lex_error4.py
new file mode 100644
index 00000000..f4f48db1
--- /dev/null
+++ b/third_party/ply/test/lex_error4.py
@@ -0,0 +1,27 @@
+# lex_error4.py
+#
+# t_error defined as function, but too many args
+
+import sys
+if ".." not in sys.path: sys.path.insert(0,"..")
+
+import ply.lex as lex
+
+tokens = [
+ "PLUS",
+ "MINUS",
+ "NUMBER",
+ ]
+
+t_PLUS = r'\+'
+t_MINUS = r'-'
+t_NUMBER = r'\d+'
+
+def t_error(t,s):
+ pass
+
+
+
+lex.lex()
+
+
diff --git a/third_party/ply/test/lex_hedit.py b/third_party/ply/test/lex_hedit.py
new file mode 100644
index 00000000..34f15a17
--- /dev/null
+++ b/third_party/ply/test/lex_hedit.py
@@ -0,0 +1,47 @@
+# -----------------------------------------------------------------------------
+# hedit.py
+#
+# Paring of Fortran H Edit descriptions (Contributed by Pearu Peterson)
+#
+# These tokens can't be easily tokenized because they are of the following
+# form:
+#
+# nHc1...cn
+#
+# where n is a positive integer and c1 ... cn are characters.
+#
+# This example shows how to modify the state of the lexer to parse
+# such tokens
+# -----------------------------------------------------------------------------
+import sys
+if ".." not in sys.path: sys.path.insert(0,"..")
+
+import ply.lex as lex
+
+tokens = (
+ 'H_EDIT_DESCRIPTOR',
+ )
+
+# Tokens
+t_ignore = " \t\n"
+
+def t_H_EDIT_DESCRIPTOR(t):
+ r"\d+H.*" # This grabs all of the remaining text
+ i = t.value.index('H')
+ n = eval(t.value[:i])
+
+ # Adjust the tokenizing position
+ t.lexer.lexpos -= len(t.value) - (i+1+n)
+ t.value = t.value[i+1:i+1+n]
+ return t
+
+def t_error(t):
+ print("Illegal character '%s'" % t.value[0])
+ t.lexer.skip(1)
+
+# Build the lexer
+lex.lex()
+lex.runmain(data="3Habc 10Habcdefghij 2Hxy")
+
+
+
diff --git a/third_party/ply/test/lex_ignore.py b/third_party/ply/test/lex_ignore.py
new file mode 100644
index 00000000..6c43b4cf
--- /dev/null
+++ b/third_party/ply/test/lex_ignore.py
@@ -0,0 +1,31 @@
+# lex_ignore.py
+#
+# Improperly specific ignore declaration
+
+import sys
+if ".." not in sys.path: sys.path.insert(0,"..")
+
+import ply.lex as lex
+
+tokens = [
+ "PLUS",
+ "MINUS",
+ "NUMBER",
+ ]
+
+t_PLUS = r'\+'
+t_MINUS = r'-'
+t_NUMBER = r'\d+'
+
+def t_ignore(t):
+ ' \t'
+ pass
+
+def t_error(t):
+ pass
+
+import sys
+
+lex.lex()
+
+
diff --git a/third_party/ply/test/lex_ignore2.py b/third_party/ply/test/lex_ignore2.py
new file mode 100644
index 00000000..f60987a6
--- /dev/null
+++ b/third_party/ply/test/lex_ignore2.py
@@ -0,0 +1,29 @@
+# lex_ignore2.py
+#