Skip to content

Commit

Permalink
Update to version 1.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
brunato committed Jun 15, 2018
1 parent 777ce76 commit f4c4894
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 35 deletions.
10 changes: 5 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
===========
***********
elementpath
===========
***********

.. elementpath-introduction
Expand All @@ -16,7 +16,7 @@ language provides. If you want you can contribute to add an unimplemented functi


Installation and usage
----------------------
======================

You can install the package with *pip* in a Python 2.7 or Python 3.3+ environment::

Expand Down Expand Up @@ -68,7 +68,7 @@ Public API classes and functions are described into the
`elementpath manual on the "Read the Docs" site <http://elementpath.readthedocs.io/en/latest/>`_.

Contributing
------------
============

You can contribute to this package reporting bugs, using the issue tracker or by a pull request.
In case you open an issue please try to provide a test or test data for reproducing the wrong
Expand All @@ -85,7 +85,7 @@ implement other types of parsers (I think it could be also a funny exercise!).


License
-------
=======

This software is distributed under the terms of the MIT License.
See the file 'LICENSE' in the root directory of the present
Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# The short X.Y version
version = ''
# The full version, including alpha/beta/rc tags
release = '1.0.8'
release = '1.0.9'


# -- General configuration ---------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions doc/introduction.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
************
Introduction
============
************

.. include:: ../README.rst
:start-after: elementpath-introduction
:start-after: elementpath-introduction
10 changes: 5 additions & 5 deletions doc/pratt_api.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
******************
Pratt's parser API
==================
******************

The TDOP (Top Down Operator Precedence) parser implemented within this library is a variant of the
original Pratt's parser based on a class for the parser and metaclasses for tokens.
Expand All @@ -10,7 +11,7 @@ methods and attributes to help the developing of new parsers. Parsers can be def
by class derivation and following a tokens registration procedure.

Token base class
----------------
================

.. autoclass:: elementpath.Token

Expand All @@ -34,7 +35,7 @@ Token base class


Parser base class
-----------------
=================

.. autoclass:: elementpath.Parser

Expand All @@ -48,8 +49,6 @@ Parser base class

Helper methods for building effective parser classes:

.. automethod:: begin
.. automethod:: end
.. automethod:: register
.. automethod:: unregister
.. automethod:: unregistered
Expand All @@ -60,3 +59,4 @@ Parser base class
.. automethod:: infix
.. automethod:: infixr
.. automethod:: method
.. automethod:: end
11 changes: 6 additions & 5 deletions doc/xpath_api.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
****************
Public XPath API
================
****************

The package includes some classes and functions that implement XPath parsers and selectors.

XPath tokens
------------
============

.. autoclass:: elementpath.XPathToken

Expand All @@ -13,7 +14,7 @@ XPath tokens


XPath parsers
-------------
=============

.. autoclass:: elementpath.XPath1Parser

Expand All @@ -23,7 +24,7 @@ XPath parsers


XPath selectors
---------------
===============

.. autofunction:: elementpath.select

Expand All @@ -37,7 +38,7 @@ XPath selectors


XPath dynamic context
---------------------
=====================

.. autoclass:: elementpath.XPathContext

2 changes: 1 addition & 1 deletion elementpath/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#
# @author Davide Brunato <brunato@sissa.it>
#
__version__ = '1.0.8'
__version__ = '1.0.9'
__author__ = "Davide Brunato"
__contact__ = "brunato@sissa.it"
__copyright__ = "Copyright 2018, SISSA"
Expand Down
9 changes: 7 additions & 2 deletions elementpath/tdop_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
ElementPathSyntaxError, ElementPathNameError, ElementPathValueError, ElementPathTypeError
)

DEFAULT_SPECIAL_SYMBOLS = {'(string)', '(float)', '(decimal)', '(integer)', '(name)', '(end)'}
"""Special symbols for literals, names and end tokens."""

SPECIAL_SYMBOL_REGEX = re.compile(r'\s*\(\w+\)\s*')
"""Compiled regular expression for matching special symbols, that are names between round brackets."""

Expand Down Expand Up @@ -274,6 +277,8 @@ def build_tokenizer(cls, name_pattern='[A-Za-z0-9_]+'):
(\S) | # Unexpected characters
\s+ # Skip extra spaces
"""
if not all(k in cls.symbol_table for k in DEFAULT_SPECIAL_SYMBOLS):
raise ValueError("The symbol table of %r doesn't contain all special symbols." % cls)

patterns = [
s.pattern for s in cls.symbol_table.values()
Expand All @@ -296,7 +301,7 @@ def build_tokenizer(cls, name_pattern='[A-Za-z0-9_]+'):
cls.tokenizer = re.compile(pattern, re.VERBOSE)

def __init__(self):
if '(end)' not in self.symbol_table or self.tokenizer is None:
if self.tokenizer is None:
raise ValueError("Incomplete parser class %s registration." % self.__class__.__name__)
self.token = None
self.match = None
Expand Down Expand Up @@ -492,7 +497,7 @@ def wrong_syntax(self, symbol):

@classmethod
def end(cls):
"""End the symbols registration and build the tokenizer."""
"""Registers the end symbol and builds the tokenizer."""
cls.register('(end)')
cls.build_tokenizer()

Expand Down
15 changes: 6 additions & 9 deletions elementpath/xpath1_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# @author Davide Brunato <brunato@sissa.it>
#
from __future__ import division
import sys
import math
import decimal

Expand Down Expand Up @@ -94,17 +93,14 @@ def __init__(self, namespaces=None, variables=None, strict=True, *args, **kwargs
self.variables = dict(variables if variables is not None else [])
self.strict = strict

@classmethod
def build_tokenizer(cls, name_pattern=XML_NCNAME_PATTERN):
super(XPath1Parser, cls).build_tokenizer(name_pattern)

@property
def version(self):
return '1.0'

@classmethod
def end(cls):
cls.register('(end)')
cls.build_tokenizer(name_pattern=XML_NCNAME_PATTERN)
for token_class in cls.symbol_table.values():
setattr(sys.modules[cls.__module__], token_class.__name__, token_class)

@classmethod
def axis(cls, symbol, bp=0):
"""Register a token for a symbol that represents an XPath *axis*."""
Expand Down Expand Up @@ -1129,4 +1125,5 @@ def evaluate(self, context=None):
self.wrong_value(str(err))


XPath1Parser.end()
register('(end)')
XPath1Parser.build_tokenizer()
4 changes: 2 additions & 2 deletions elementpath/xpath2_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __init__(self, namespaces=None, variables=None, strict=True, default_namespa
symbol = qname_to_prefixed(xsd_type.name, self.namespaces)
if symbol not in self.symbol_table:
self.atomic_type(symbol, xsd_type.name)
self.end()
self.build_tokenizer()

if compatibility_mode is False:
self.compatibility_mode = False
Expand Down Expand Up @@ -1102,4 +1102,4 @@ def evaluate(self, context=None):
return context.item[1]


XPath2Parser.end()
XPath2Parser.build_tokenizer()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setup(
name='elementpath',
version='1.0.8',
version='1.0.9',
packages=['elementpath'],
author='Davide Brunato',
author_email='brunato@sissa.it',
Expand Down
4 changes: 2 additions & 2 deletions tests/test_elementpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
try:
# noinspection PyPackageRequirements
import xmlschema
except ImportError:
except (ImportError, AttributeError):
xmlschema = None


Expand Down Expand Up @@ -1173,7 +1173,7 @@ def setUpClass(cls):
cls.etree = lxml.etree


@unittest.skipIf(xmlschema is None, "The xmlschema library is not installed.")
@unittest.skipIf(xmlschema is None, "xmlschema library >= v0.9.31 required.")
class XPath2ParserXMLSchemaTest(XPath2ParserTest):

if xmlschema:
Expand Down

0 comments on commit f4c4894

Please sign in to comment.