simpleparse 3.0.0a3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. simpleparse-3.0.0a3/MANIFEST.in +18 -0
  2. simpleparse-3.0.0a3/PKG-INFO +70 -0
  3. simpleparse-3.0.0a3/README.md +38 -0
  4. simpleparse-3.0.0a3/license.txt +31 -0
  5. simpleparse-3.0.0a3/pyproject.toml +74 -0
  6. simpleparse-3.0.0a3/setup.cfg +4 -0
  7. simpleparse-3.0.0a3/setup.py +77 -0
  8. simpleparse-3.0.0a3/simpleparse/__init__.py +8 -0
  9. simpleparse-3.0.0a3/simpleparse/baseparser.py +90 -0
  10. simpleparse-3.0.0a3/simpleparse/common/__init__.py +19 -0
  11. simpleparse-3.0.0a3/simpleparse/common/calendar_names.py +103 -0
  12. simpleparse-3.0.0a3/simpleparse/common/chartypes.py +89 -0
  13. simpleparse-3.0.0a3/simpleparse/common/comments.py +72 -0
  14. simpleparse-3.0.0a3/simpleparse/common/escapeutils.py +21 -0
  15. simpleparse-3.0.0a3/simpleparse/common/iso_date.py +153 -0
  16. simpleparse-3.0.0a3/simpleparse/common/iso_date_loose.py +141 -0
  17. simpleparse-3.0.0a3/simpleparse/common/numbers.py +166 -0
  18. simpleparse-3.0.0a3/simpleparse/common/phonetics.py +76 -0
  19. simpleparse-3.0.0a3/simpleparse/common/strings.py +158 -0
  20. simpleparse-3.0.0a3/simpleparse/common/timezone_names.py +218 -0
  21. simpleparse-3.0.0a3/simpleparse/dispatchprocessor.py +107 -0
  22. simpleparse-3.0.0a3/simpleparse/error.py +55 -0
  23. simpleparse-3.0.0a3/simpleparse/generator.py +151 -0
  24. simpleparse-3.0.0a3/simpleparse/objectgenerator.py +780 -0
  25. simpleparse-3.0.0a3/simpleparse/parser.py +49 -0
  26. simpleparse-3.0.0a3/simpleparse/printers.py +58 -0
  27. simpleparse-3.0.0a3/simpleparse/processor.py +49 -0
  28. simpleparse-3.0.0a3/simpleparse/simpleparsegrammar.py +755 -0
  29. simpleparse-3.0.0a3/simpleparse/stt/COPYRIGHT +11 -0
  30. simpleparse-3.0.0a3/simpleparse/stt/Doc/eGenix-mx-Extensions.html +1708 -0
  31. simpleparse-3.0.0a3/simpleparse/stt/Doc/mxLicense.html +868 -0
  32. simpleparse-3.0.0a3/simpleparse/stt/Doc/mxTextTools.html +2677 -0
  33. simpleparse-3.0.0a3/simpleparse/stt/LICENSE +16 -0
  34. simpleparse-3.0.0a3/simpleparse/stt/TextTools/COPYRIGHT +19 -0
  35. simpleparse-3.0.0a3/simpleparse/stt/TextTools/Constants/Sets.py +58 -0
  36. simpleparse-3.0.0a3/simpleparse/stt/TextTools/Constants/TagTables.py +32 -0
  37. simpleparse-3.0.0a3/simpleparse/stt/TextTools/Constants/__init__.py +0 -0
  38. simpleparse-3.0.0a3/simpleparse/stt/TextTools/LICENSE +106 -0
  39. simpleparse-3.0.0a3/simpleparse/stt/TextTools/TextTools.py +818 -0
  40. simpleparse-3.0.0a3/simpleparse/stt/TextTools/__init__.py +63 -0
  41. simpleparse-3.0.0a3/simpleparse/stt/TextTools/mxTextTools/__init__.py +23 -0
  42. simpleparse-3.0.0a3/simpleparse/stt/TextTools/mxTextTools/highcommands.h +266 -0
  43. simpleparse-3.0.0a3/simpleparse/stt/TextTools/mxTextTools/lowlevelcommands.h +814 -0
  44. simpleparse-3.0.0a3/simpleparse/stt/TextTools/mxTextTools/mx.h +721 -0
  45. simpleparse-3.0.0a3/simpleparse/stt/TextTools/mxTextTools/mxTextTools.c +5364 -0
  46. simpleparse-3.0.0a3/simpleparse/stt/TextTools/mxTextTools/mxTextTools.def +2 -0
  47. simpleparse-3.0.0a3/simpleparse/stt/TextTools/mxTextTools/mxTextTools.h +327 -0
  48. simpleparse-3.0.0a3/simpleparse/stt/TextTools/mxTextTools/mxbm_modern.c +581 -0
  49. simpleparse-3.0.0a3/simpleparse/stt/TextTools/mxTextTools/mxbm_modern.h +160 -0
  50. simpleparse-3.0.0a3/simpleparse/stt/TextTools/mxTextTools/mxbmse.c +218 -0
  51. simpleparse-3.0.0a3/simpleparse/stt/TextTools/mxTextTools/mxbmse.h +65 -0
  52. simpleparse-3.0.0a3/simpleparse/stt/TextTools/mxTextTools/mxh.h +60 -0
  53. simpleparse-3.0.0a3/simpleparse/stt/TextTools/mxTextTools/mxpyapi.h +35 -0
  54. simpleparse-3.0.0a3/simpleparse/stt/TextTools/mxTextTools/mxstdlib.h +225 -0
  55. simpleparse-3.0.0a3/simpleparse/stt/TextTools/mxTextTools/mxte.c +47 -0
  56. simpleparse-3.0.0a3/simpleparse/stt/TextTools/mxTextTools/mxte_impl.h +878 -0
  57. simpleparse-3.0.0a3/simpleparse/stt/TextTools/mxTextTools/mxte_modern.c +383 -0
  58. simpleparse-3.0.0a3/simpleparse/stt/TextTools/mxTextTools/mxte_modern.h +806 -0
  59. simpleparse-3.0.0a3/simpleparse/stt/TextTools/mxTextTools/mxte_smart.c +113 -0
  60. simpleparse-3.0.0a3/simpleparse/stt/TextTools/mxTextTools/recursecommands.h +119 -0
  61. simpleparse-3.0.0a3/simpleparse/stt/TextTools/mxTextTools/speccommands.h +101 -0
  62. simpleparse-3.0.0a3/simpleparse/stt/__init__.py +22 -0
  63. simpleparse-3.0.0a3/simpleparse/stt/mxLicense.html +691 -0
  64. simpleparse-3.0.0a3/simpleparse/xmlparser/__init__.py +11 -0
  65. simpleparse-3.0.0a3/simpleparse/xmlparser/xml_parser.py +200 -0
  66. simpleparse-3.0.0a3/simpleparse.egg-info/PKG-INFO +70 -0
  67. simpleparse-3.0.0a3/simpleparse.egg-info/SOURCES.txt +91 -0
  68. simpleparse-3.0.0a3/simpleparse.egg-info/dependency_links.txt +1 -0
  69. simpleparse-3.0.0a3/simpleparse.egg-info/requires.txt +10 -0
  70. simpleparse-3.0.0a3/simpleparse.egg-info/top_level.txt +1 -0
  71. simpleparse-3.0.0a3/tests/__init__.py +8 -0
  72. simpleparse-3.0.0a3/tests/genericvalues.py +21 -0
  73. simpleparse-3.0.0a3/tests/mx_flag.py +125 -0
  74. simpleparse-3.0.0a3/tests/mx_high.py +191 -0
  75. simpleparse-3.0.0a3/tests/mx_low.py +301 -0
  76. simpleparse-3.0.0a3/tests/mx_recursive.py +162 -0
  77. simpleparse-3.0.0a3/tests/mx_special.py +233 -0
  78. simpleparse-3.0.0a3/tests/test_backup_on_subtable_failure.py +18 -0
  79. simpleparse-3.0.0a3/tests/test_common_chartypes.py +91 -0
  80. simpleparse-3.0.0a3/tests/test_common_comments.py +80 -0
  81. simpleparse-3.0.0a3/tests/test_common_iso_date.py +122 -0
  82. simpleparse-3.0.0a3/tests/test_common_numbers.py +184 -0
  83. simpleparse-3.0.0a3/tests/test_common_strings.py +66 -0
  84. simpleparse-3.0.0a3/tests/test_deep_nesting.py +37 -0
  85. simpleparse-3.0.0a3/tests/test_erroronfail.py +115 -0
  86. simpleparse-3.0.0a3/tests/test_grammarparser.py +866 -0
  87. simpleparse-3.0.0a3/tests/test_modern_unicode_engine.py +602 -0
  88. simpleparse-3.0.0a3/tests/test_objectgenerator.py +431 -0
  89. simpleparse-3.0.0a3/tests/test_optimisation.py +125 -0
  90. simpleparse-3.0.0a3/tests/test_printers.py +32 -0
  91. simpleparse-3.0.0a3/tests/test_simpleparsegrammar.py +529 -0
  92. simpleparse-3.0.0a3/tests/test_xml.py +280 -0
  93. simpleparse-3.0.0a3/tox.ini +14 -0
@@ -0,0 +1,18 @@
1
+ include MANIFEST.in
2
+ include license.txt
3
+ include tox.ini
4
+ include setup.py
5
+ recursive-include simpleparse/stt COPYRIGHT LICENSE *.html
6
+ recursive-include simpleparse/stt/Doc *.html
7
+ recursive-include simpleparse/stt/TextTools/mxTextTools *.c *.h
8
+
9
+ recursive-include doc *.html
10
+ recursive-include doc *.css
11
+ recursive-include tests *.py
12
+
13
+ global-exclude *.so
14
+ global-exclude *.pyc
15
+ prune examples/html.py
16
+ prune examples/py*
17
+ prune examples/rtf*
18
+ prune .tox
@@ -0,0 +1,70 @@
1
+ Metadata-Version: 2.4
2
+ Name: simpleparse
3
+ Version: 3.0.0a3
4
+ Summary: A Parser Generator for Python (w/mxTextTools derivative)
5
+ Author-email: "Mike C. Fletcher" <mcfletch@users.sourceforge.net>
6
+ License: BSD-3-Clause
7
+ Project-URL: Homepage, https://mcfletch.github.io/simpleparse/
8
+ Project-URL: Source, https://github.com/mcfletch/simpleparse
9
+ Keywords: parse,parser,parsing,text,ebnf,grammar,generator
10
+ Classifier: Programming Language :: Python
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.8
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Classifier: Intended Audience :: Developers
21
+ Classifier: Operating System :: OS Independent
22
+ Requires-Python: >=3.8
23
+ Description-Content-Type: text/markdown
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest; extra == "dev"
26
+ Requires-Dist: ruff; extra == "dev"
27
+ Requires-Dist: tox>=4.11; extra == "dev"
28
+ Requires-Dist: tox-uv>=1; extra == "dev"
29
+ Provides-Extra: docs
30
+ Requires-Dist: sphinx; extra == "docs"
31
+ Requires-Dist: sphinx-rtd-theme; extra == "docs"
32
+
33
+ # SimpleParse 3.x
34
+ ## A Parser Generator for Python and mxTextTools
35
+
36
+ SimpleParse is a parser generator, it takes a modified EBNF
37
+ grammar and customises a text-processing engine `mxTextTools`
38
+ to produce a relatively fast table-driven parser.
39
+
40
+ As of version 3.x, Simpleparse has moved to being unicode-native,
41
+ with direct support for each of the 3 internal unicode formats
42
+ that are supported by Python3 (as well as bytes format). However,
43
+ the effect of the unicode changes is that the parser generator will
44
+ assume unicode when generating the parser, and you will need to
45
+ specify the content encoding when parsing/tagging.
46
+
47
+ So for parsing a latin-1 document provided as raw encoded bytes:
48
+
49
+ * tag(bytestream, tagtable, 'latin-1')
50
+
51
+ Only utf-8 encoding is handled among multi-byte encodings, but
52
+ single-byte encodings should be handled. Note that it is *generally*
53
+ going to be more useful to load your document as unicode text and
54
+ then tag the content, but the byte-stream parsing may be necessary
55
+ if you have the content already in memory as bytes and can't
56
+ decode it for some reason.
57
+
58
+ You can see a full-featured [sample parser](https://github.com/mcfletch/pyvrml97/blob/master/vrml/vrml97/parser.py)
59
+ in the `PyVRML97` package.
60
+
61
+ See the [docs](https://mcfletch.github.io/simpleparse/) for usage.
62
+
63
+ ```pip install SimpleParse```
64
+
65
+ [![Appveyor Build](https://ci.appveyor.com/api/projects/status/MikeCFletcher/simpleparse?svg=True)](https://ci.appveyor.com/project/MikeCFletcher/simpleparse)
66
+
67
+ [![PyPI download month](https://img.shields.io/pypi/v/simpleparse.svg)](https://pypi.python.org/pypi/simpleparse)
68
+
69
+ [![PyPI download month](https://img.shields.io/pypi/dm/simpleparse.svg)](https://pypi.python.org/pypi/simpleparse/)
70
+
@@ -0,0 +1,38 @@
1
+ # SimpleParse 3.x
2
+ ## A Parser Generator for Python and mxTextTools
3
+
4
+ SimpleParse is a parser generator, it takes a modified EBNF
5
+ grammar and customises a text-processing engine `mxTextTools`
6
+ to produce a relatively fast table-driven parser.
7
+
8
+ As of version 3.x, Simpleparse has moved to being unicode-native,
9
+ with direct support for each of the 3 internal unicode formats
10
+ that are supported by Python3 (as well as bytes format). However,
11
+ the effect of the unicode changes is that the parser generator will
12
+ assume unicode when generating the parser, and you will need to
13
+ specify the content encoding when parsing/tagging.
14
+
15
+ So for parsing a latin-1 document provided as raw encoded bytes:
16
+
17
+ * tag(bytestream, tagtable, 'latin-1')
18
+
19
+ Only utf-8 encoding is handled among multi-byte encodings, but
20
+ single-byte encodings should be handled. Note that it is *generally*
21
+ going to be more useful to load your document as unicode text and
22
+ then tag the content, but the byte-stream parsing may be necessary
23
+ if you have the content already in memory as bytes and can't
24
+ decode it for some reason.
25
+
26
+ You can see a full-featured [sample parser](https://github.com/mcfletch/pyvrml97/blob/master/vrml/vrml97/parser.py)
27
+ in the `PyVRML97` package.
28
+
29
+ See the [docs](https://mcfletch.github.io/simpleparse/) for usage.
30
+
31
+ ```pip install SimpleParse```
32
+
33
+ [![Appveyor Build](https://ci.appveyor.com/api/projects/status/MikeCFletcher/simpleparse?svg=True)](https://ci.appveyor.com/project/MikeCFletcher/simpleparse)
34
+
35
+ [![PyPI download month](https://img.shields.io/pypi/v/simpleparse.svg)](https://pypi.python.org/pypi/simpleparse)
36
+
37
+ [![PyPI download month](https://img.shields.io/pypi/dm/simpleparse.svg)](https://pypi.python.org/pypi/simpleparse/)
38
+
@@ -0,0 +1,31 @@
1
+ Includes the eGenix mxTextTools extensions, which are licensed under the
2
+ eGenix.com Public License see the stt/LICENSE file for details on licensing
3
+ terms, the eGenix extensions are:
4
+
5
+ Copyright (c) 1997-2000, Marc-Andre Lemburg; mailto:mal@lemburg.com
6
+ Copyright (c) 2000-2001, eGenix.com Software GmbH; mailto:info@egenix.com
7
+
8
+ Copyright, License & Disclaimer for SimpleParse:
9
+
10
+ © 1998-2015, Copyright by Contributors; All Rights Reserved.
11
+
12
+ Permission to use, copy, modify, and distribute this software
13
+ and its documentation for any purpose and without fee or royalty
14
+ is hereby granted, provided that the above copyright notice appear
15
+ in all copies and that both the copyright notice and this
16
+ permission notice appear in supporting documentation or portions
17
+ thereof, including modifications, that you make.
18
+
19
+ THE CONTRIBUTORS DISCLAIM ALL WARRANTIES WITH REGARD
20
+ TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
21
+ MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE
22
+ LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
23
+ DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
24
+ WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
25
+ ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
26
+ PERFORMANCE OF THIS SOFTWARE!
27
+
28
+ Contributors:
29
+
30
+ Mike C. Fletcher <mcfletch@vrplumber.com>
31
+ Anthony Tuininga
@@ -0,0 +1,74 @@
1
+ [build-system]
2
+ requires = ["setuptools>=59.6", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "simpleparse"
7
+ dynamic = ["version"]
8
+ description = "A Parser Generator for Python (w/mxTextTools derivative)"
9
+ authors = [
10
+ {name = "Mike C. Fletcher", email = "mcfletch@users.sourceforge.net"},
11
+ ]
12
+ readme = "README.md"
13
+ license = {text = "BSD-3-Clause"}
14
+ keywords = ["parse", "parser", "parsing", "text", "ebnf", "grammar", "generator"]
15
+ classifiers = [
16
+ "Programming Language :: Python",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.8",
19
+ "Programming Language :: Python :: 3.9",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Programming Language :: Python :: 3.14",
25
+ "Topic :: Software Development :: Libraries :: Python Modules",
26
+ "Intended Audience :: Developers",
27
+ "Operating System :: OS Independent",
28
+ ]
29
+ requires-python = ">=3.8"
30
+
31
+ [project.optional-dependencies]
32
+ dev = ["pytest", "ruff", "tox>=4.11", "tox-uv>=1"]
33
+ docs = ["sphinx", "sphinx-rtd-theme"]
34
+
35
+ [project.urls]
36
+ Homepage = "https://mcfletch.github.io/simpleparse/"
37
+ Source = "https://github.com/mcfletch/simpleparse"
38
+
39
+ [tool.setuptools]
40
+ packages = [
41
+ "simpleparse",
42
+ "simpleparse.common",
43
+ "simpleparse.stt",
44
+ "simpleparse.stt.Doc",
45
+ "simpleparse.stt.TextTools",
46
+ "simpleparse.stt.TextTools.Constants",
47
+ "simpleparse.stt.TextTools.mxTextTools",
48
+ "simpleparse.xmlparser",
49
+ ]
50
+ include-package-data = true
51
+
52
+ [tool.setuptools.dynamic]
53
+ version = {attr = "simpleparse.__version__"}
54
+
55
+ [tool.setuptools.package-data]
56
+ simpleparse = ["*.txt", "**/*.txt", "**/*.ebnf", "**/*.html", "**/*.pyx", "**/*.h", "**/*.def"]
57
+
58
+ [tool.ruff.format]
59
+ quote-style="preserve"
60
+
61
+ [tool.ruff.lint]
62
+ dummy-variable-rgx="^(_|err)$"
63
+ ignore = [
64
+ 'D200', # Allow multiline docstring even when it could fit on one line
65
+
66
+ 'C408', # Allow instantiating dictionary as dict(key=value)
67
+ 'E501', # Line too long
68
+ 'PTH', # allow os.path
69
+ 'PLR0913', # allow "too many" arguments
70
+
71
+ 'E401', # I prefer multiple imports/line generally
72
+ 'E402', # We often need to run setupdefaults to get django setup done
73
+ 'F401', # unused imports, not an error, but should be cleaned up
74
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env python
2
+ """Installs SimpleParse using distutils
3
+
4
+ Run:
5
+ python setup.py install
6
+ to install the packages from the source archive.
7
+ """
8
+ from setuptools import setup, Extension, find_packages
9
+ import os, sys
10
+ HERE = os.path.abspath(os.path.dirname(__file__))
11
+
12
+ # Determine Python version for conditional compilation
13
+ PY_MAJOR = sys.version_info.major
14
+ PY_MINOR = sys.version_info.minor
15
+ PYTHON_VERSION = (PY_MAJOR, PY_MINOR)
16
+
17
+ def findVersion( ):
18
+ """Find the version declaration in the __init__.py file"""
19
+ for line in open(
20
+ os.path.join( HERE, 'simpleparse', '__init__.py')
21
+ ).read().splitlines():
22
+ if line.startswith('__version__'):
23
+ line = line.split('=')[1]
24
+ line = line.strip().strip('"').strip("'")
25
+ return line
26
+ raise RuntimeError("Unable to find __version__ declaration")
27
+
28
+ options = {
29
+ 'sdist': { 'force_manifest':1,'formats':['gztar'] },
30
+ }
31
+ if sys.platform == 'win32':
32
+ options.setdefault(
33
+ 'build_ext',{}
34
+ )['define'] = 'BAD_STATIC_FORWARD'
35
+
36
+ if __name__ == "__main__":
37
+ # Most metadata is now in pyproject.toml
38
+ # This setup.py is primarily for C extension configuration
39
+
40
+ # Python 3.3+ only - use modern implementation with compatibility layer
41
+ print(f"Building for Python {PY_MAJOR}.{PY_MINOR}: Modern Unicode implementation")
42
+
43
+ # Verify minimum Python version
44
+ if PYTHON_VERSION < (3, 3):
45
+ raise RuntimeError(f"SimpleParse requires Python 3.3 or later, got {PY_MAJOR}.{PY_MINOR}")
46
+
47
+ # Use modern implementation with compatibility shims for deprecated APIs
48
+ sources = [
49
+ 'simpleparse/stt/TextTools/mxTextTools/mxTextTools.c',
50
+ 'simpleparse/stt/TextTools/mxTextTools/mxte_modern.c',
51
+ 'simpleparse/stt/TextTools/mxTextTools/mxte_smart.c',
52
+ 'simpleparse/stt/TextTools/mxTextTools/mxbmse.c',
53
+ 'simpleparse/stt/TextTools/mxTextTools/mxbm_modern.c',
54
+ ]
55
+
56
+ define_macros = [
57
+ ('MX_BUILDING_MXTEXTTOOLS', 1),
58
+ ('PY_SSIZE_T_CLEAN', 1),
59
+ ]
60
+
61
+ # For all Python 3.3+, force use of modern APIs and eliminate legacy compatibility
62
+ define_macros.append(('MODERN_UNICODE_ONLY', 1)) # Enable modern Unicode-only build
63
+ define_macros.append(('FORCE_MODERN_UNICODE', 1)) # Force use of modern APIs
64
+
65
+ setup(
66
+ ext_modules=[
67
+ Extension(
68
+ "simpleparse.stt.TextTools.mxTextTools.mxTextTools",
69
+ sources,
70
+ include_dirs=[
71
+ 'simpleparse/stt/TextTools/mxTextTools',
72
+ ],
73
+ define_macros=define_macros,
74
+ ),
75
+ ],
76
+ options=options,
77
+ )
@@ -0,0 +1,8 @@
1
+ """Simple parsing using mxTextTools
2
+
3
+ See the /doc subdirectory for introductory and
4
+ general documentation. See license.txt for licensing
5
+ information. (This is a BSD-licensed package).
6
+ """
7
+
8
+ __version__ = "3.0.0a3"
@@ -0,0 +1,90 @@
1
+ """Base class for real-world parsers (such as parser.Parser)"""
2
+
3
+ from simpleparse.stt.TextTools.TextTools import tag
4
+ from simpleparse.generator import Generator
5
+
6
+
7
+ class BaseParser:
8
+ """Class on which real-world parsers build
9
+
10
+ Normally you use a sub-class of this class, such as
11
+ simpleparser.parser.Parser
12
+ """
13
+
14
+ _rootProduction = ""
15
+
16
+ # primary API...
17
+ def parse(
18
+ self, data, production=None, processor=None, start=0, stop=None, encoding=None
19
+ ):
20
+ """Parse data with production "production" of this parser
21
+
22
+ data -- data to be parsed, a Python string or bytes
23
+ production -- optional string specifying a non-default production to use
24
+ for parsing data
25
+ processor -- optional pointer to a Processor or MethodSource object for
26
+ use in determining reporting format and/or post-processing the results
27
+ of the parsing pass. Can be None if neither is desired (default)
28
+ start -- starting index for the parsing, default 0
29
+ stop -- stoping index for the parsing, default len(data)
30
+ encoding -- optional encoding for bytes input (e.g., 'utf-8', 'latin-1').
31
+ When specified with bytes input, the grammar patterns are compiled
32
+ to match the encoded byte sequences. Supported encodings:
33
+ - Single-byte: latin-1, iso-8859-*, windows-1252, ascii, etc.
34
+ - Multi-byte: utf-8 only (other multi-byte encodings not supported)
35
+ Positions in the result are byte positions when encoding is used.
36
+ """
37
+ self.resetBeforeParse()
38
+ if processor is None:
39
+ processor = self.buildProcessor()
40
+ if stop is None:
41
+ stop = len(data)
42
+ value = tag(
43
+ data,
44
+ self.buildTagger(production, processor),
45
+ start,
46
+ stop,
47
+ encoding=encoding,
48
+ )
49
+ if processor and callable(processor):
50
+ return processor(value, data)
51
+ else:
52
+ return value
53
+
54
+ # abstract methods
55
+ def buildProcessor(self):
56
+ """Build default processor object for this parser class
57
+
58
+ The default implementation returns None. The processor
59
+ can either implement the "method source" API (just provides
60
+ information about Callouts and the like), or the processor
61
+ API and the method-source API. The processor API merely
62
+ requires that the object be callable, and have the signature:
63
+
64
+ object( (success, children, nextPosition), buffer)
65
+
66
+ (Note: your object can treat the first item as a single tuple
67
+ if it likes).
68
+
69
+ See: simpleparse.processor module for details.
70
+ """
71
+ return None
72
+
73
+ def buildTagger(self, name, processor):
74
+ """Build the tag-table for the parser
75
+
76
+ This method must be implemented by your base class and _not_
77
+ call the implementation here.
78
+ """
79
+ raise NotImplementedError(
80
+ """Parser sub-class %s hasn't implemented a buildTagger method"""
81
+ % (self.__class__.__name__)
82
+ )
83
+
84
+ def resetBeforeParse(self):
85
+ """Called just before the parser's parse method starts working,
86
+
87
+ Allows you to set up special-purpose structures, such as stacks
88
+ or local storage values. There is no base implementation. The
89
+ base implementation does nothing.
90
+ """
@@ -0,0 +1,19 @@
1
+ """Common (library) definitions
2
+
3
+ You normally use this module by importing one of our
4
+ sub-modules (which automatically registers itself with
5
+ the SOURCES list defined here).
6
+
7
+ Calling common.share( dictionary ) with a dictionary
8
+ mapping string names to element token instances will
9
+ make the element tokens available under those string
10
+ names in default parsers. Note: a Parser can override
11
+ this by specifying an explicit definitionSources
12
+ parameter in its initialiser.
13
+ """
14
+
15
+ def share( dictionary ):
16
+ SOURCES.append( dictionary)
17
+
18
+ SOURCES = [
19
+ ]
@@ -0,0 +1,103 @@
1
+ """Locale-specific calendar names (day-of-week and month-of-year)
2
+
3
+ These values are those returned by the calendar module. Available
4
+ productions:
5
+
6
+ locale_day_names
7
+ locale_day_names_uc
8
+ locale_day_names_lc
9
+ Names for the days of the week
10
+
11
+ locale_day_abbrs
12
+ locale_day_abbrs_uc
13
+ locale_day_abbrs_lc
14
+ Short-forms (3 characters normally) for
15
+ the days of the week.
16
+
17
+ locale_month_names
18
+ locale_month_names_uc
19
+ locale_month_names_lc
20
+ Names for the months of the year
21
+
22
+ locale_month_abbrs
23
+ locale_month_abbrs_uc
24
+ locale_month_abbrs_lc
25
+ Short-forms (3 characters normally) for
26
+ the months of the year
27
+
28
+ Interpreters:
29
+ MonthNameInterpreter
30
+ DayNameInterpreter
31
+ Both offer the ability to set an index other
32
+ than the default (of 1) for the first item in
33
+ the list.
34
+ """
35
+ import calendar
36
+ from simpleparse import objectgenerator, common
37
+
38
+ c = {}
39
+
40
+ da = calendar.day_abbr[:]
41
+ dn = calendar.day_name[:]
42
+ ma = calendar.month_abbr[:]
43
+ mn = calendar.month_name[:]
44
+
45
+ def _build( name, set ):
46
+ # make sure longest equal-prefix items are first
47
+ set = set[:]
48
+ set.sort()
49
+ set.reverse()
50
+ l,u,r = [],[],[]
51
+ for item in set:
52
+ l.append( objectgenerator.Literal( value = item.lower() ))
53
+ u.append( objectgenerator.Literal( value = item.upper() ))
54
+ r.append( objectgenerator.Literal( value = item ))
55
+ c[ name + '_lc' ] = objectgenerator.FirstOfGroup( children = l )
56
+ c[ name + '_uc' ] = objectgenerator.FirstOfGroup( children = u )
57
+ c[ name ] = objectgenerator.FirstOfGroup( children = r )
58
+
59
+ _build( 'locale_day_names', dn )
60
+ _build( 'locale_day_abbrs', da )
61
+
62
+
63
+ _build( 'locale_month_names', mn )
64
+ _build( 'locale_month_abbrs', ma )
65
+
66
+ da = [s.lower() for s in da]
67
+ dn = [s.lower() for s in dn]
68
+ ma = [s.lower() for s in ma]
69
+ mn = [s.lower() for s in mn]
70
+
71
+
72
+ common.share( c )
73
+
74
+ class NameInterpreter:
75
+ offset = 1
76
+ def __init__( self, offset = 1 ):
77
+ self.offset = offset
78
+ def __call__( self, info, buffer ):
79
+ (tag, left, right, children) = info
80
+ value = buffer[left:right].lower()
81
+ for table in self.tables:
82
+ try:
83
+ return table.index( value )+ self.offset
84
+ except ValueError:
85
+ pass
86
+ raise ValueError( """Unrecognised (but parsed) %s name %s at character %s"""%( self.nameType, value, left))
87
+
88
+ class MonthNameInterpreter( NameInterpreter):
89
+ """Interpret a month-of-year name as an integer index
90
+
91
+ Pass an "offset" value to __init__ to use an offset other
92
+ than 1 (Monday = 1), normally 0 (Monday = 0)
93
+ """
94
+ nameType = "Month"
95
+ tables = (mn,ma)
96
+ class DayNameInterpreter( NameInterpreter ):
97
+ """Interpret a day-of-week name as an integer index
98
+
99
+ Pass an "offset" value to __init__ to use an offset other
100
+ than 1 (January = 1), normally 0 (January = 0)
101
+ """
102
+ nameType = "Day"
103
+ tables = (dn,da)
@@ -0,0 +1,89 @@
1
+ """Common locale-specific character types
2
+
3
+ Following productions are all based on string module,
4
+ with the default locale specified. The first production
5
+ is a single character of the class and the second a
6
+ repeating character version:
7
+
8
+ digit, digits
9
+ uppercasechar, uppercase
10
+ lowercasechar, lowercase
11
+ letter, letters
12
+ whitespacechar, whitespace
13
+ punctuationchar, punctuation
14
+ octdigit, octdigits
15
+ hexdigit, hexdigits
16
+ printablechar, printable
17
+
18
+ For Python versions with the constants in the string module:
19
+ ascii_letter, ascii_letters
20
+ ascii_lowercasechar, ascii_lowercase
21
+ ascii_uppercasechar, ascii_uppercase
22
+
23
+
24
+ Following are locale-specific values, both are
25
+ single-character values:
26
+
27
+ locale_decimal_point -- locale-specific decimal seperator
28
+ locale_thousands_seperator -- locale-specific "thousands" seperator
29
+
30
+ Others:
31
+
32
+ EOF -- Matches iff parsing has reached the end of the buffer
33
+
34
+ There are no interpreters provided (the types are considered
35
+ too common to provide meaningful interpreters).
36
+ """
37
+ from simpleparse import objectgenerator, common
38
+ import string, locale
39
+ try:
40
+ locale.setlocale(locale.LC_ALL, "" )
41
+ except locale.Error:
42
+ # Environment requests a locale that isn't installed (common in minimal
43
+ # containers). localeconv() still works against the default C locale, so
44
+ # the only consequence is C-locale decimal/thousands conventions below.
45
+ pass
46
+
47
+ c = {}
48
+
49
+ # string-module items...
50
+
51
+ for source,single,repeat in [
52
+ ("digits","digit","digits"),
53
+ ("ascii_uppercase", "uppercasechar", "uppercase"),
54
+ ("ascii_lowercase", "lowercasechar", "lowercase"),
55
+ ("ascii_letters", "letter", "letters" ),
56
+ ("ascii_letters", "ascii_letter", "ascii_letters" ), # alias
57
+ ("ascii_lowercase", "ascii_lowercasechar", "ascii_lowercase"),
58
+ ("ascii_uppercase", "ascii_uppercasechar", "ascii_uppercase"),
59
+ ("whitespace", "whitespacechar", "whitespace"),
60
+ ("punctuation", "punctuationchar", "punctuation"),
61
+ ("octdigits", "octdigit", "octdigits"),
62
+ ("hexdigits", "hexdigit", "hexdigits"),
63
+ ("printable", "printablechar", "printable"),
64
+ ]:
65
+ try:
66
+ value = getattr( string, source )
67
+ c[ single ] = objectgenerator.Range( value = value )
68
+ c[ repeat ] = objectgenerator.Range( value = value, repeating =1 )
69
+ except AttributeError:
70
+ pass
71
+
72
+ # locale-module items
73
+ _lc = locale.localeconv()
74
+ c[ "locale_decimal_point" ] = objectgenerator.Literal( value = _lc["decimal_point"] )
75
+ c[ "locale_thousands_seperator" ] = objectgenerator.Literal( value = _lc["thousands_sep"] )
76
+
77
+ del _lc
78
+
79
+ # common, but not really well defined sets
80
+ # this is the set of characters which are interpreted
81
+ # specially by Python's string-escaping when they
82
+ # follow a \\ char.
83
+
84
+ from simpleparse.stt import TextTools
85
+ c[ "EOF" ] = objectgenerator.Prebuilt( value = (
86
+ (None, TextTools.EOF, TextTools.Here),
87
+ ) )
88
+
89
+ common.share( c )