Skip to content

Commit

Permalink
Rename parser to defparser
Browse files Browse the repository at this point in the history
  • Loading branch information
hgrecco committed Oct 13, 2022
1 parent 08b9807 commit c38f348
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 45 deletions.
4 changes: 2 additions & 2 deletions pint/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from . import errors
from ._vendor import flexparser as fp
from .delegates import ParserConfig, txt_parser
from .delegates import ParserConfig, txt_defparser


class Definition:
Expand All @@ -19,7 +19,7 @@ class Definition:
@classmethod
def from_string(cls, s: str, non_int_type=float):
cfg = ParserConfig(non_int_type)
parser = txt_parser.Parser(cfg, None)
parser = txt_defparser.DefParser(cfg, None)
pp = parser.parse_string(s)
for definition in parser.iter_parsed_project(pp):
if isinstance(definition, Exception):
Expand Down
6 changes: 3 additions & 3 deletions pint/delegates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
:license: BSD, see LICENSE for more details.
"""

from . import txt_parser
from .base_parser import ParserConfig, build_disk_cache_class
from . import txt_defparser
from .base_defparser import ParserConfig, build_disk_cache_class

__all__ = [txt_parser, ParserConfig, build_disk_cache_class]
__all__ = [txt_defparser, ParserConfig, build_disk_cache_class]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
pint.delegates.base_parser
~~~~~~~~~~~~~~~~~~~~~~~~~~
pint.delegates.base_defparser
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Common class and function for all parsers.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
pint.delegates.txt_parser
~~~~~~~~~~~~~~~~~~~~~~~~~
pint.delegates.txt_defparser
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parser for the original textual Pint Definition file.
Expand All @@ -9,6 +9,6 @@
"""


from .parser import Parser
from .defparser import DefParser

__all__ = [Parser]
__all__ = [DefParser]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
pint.delegates.txt_parser.block
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pint.delegates.txt_defparser.block
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Classes for Pint Blocks, which are defined by:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
pint.delegates.txt_parser.common
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pint.delegates.txt_defparser.common
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Definitions for parsing an Import Statement
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
pint.delegates.txt_parser.context
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pint.delegates.txt_defparser.context
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Definitions for parsing Context and their related objects
Expand All @@ -24,7 +24,7 @@

from ..._vendor import flexparser as fp
from ...facets.context import definitions
from ..base_parser import ParserConfig
from ..base_defparser import ParserConfig
from . import block, common, plain


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
pint.delegates.txt_parser.defaults
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pint.delegates.txt_defparser.defaults
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Definitions for parsing Default sections.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from ..._vendor import flexcache as fc
from ..._vendor import flexparser as fp
from .. import base_parser
from .. import base_defparser
from . import block, common, context, defaults, group, plain, system


Expand Down Expand Up @@ -47,7 +47,7 @@ class _PintParser(fp.Parser):

_diskcache: fc.DiskCache

def __init__(self, config: base_parser.ParserConfig, *args, **kwargs):
def __init__(self, config: base_defparser.ParserConfig, *args, **kwargs):
self._diskcache = kwargs.pop("diskcache", None)
super().__init__(config, *args, **kwargs)

Expand All @@ -58,7 +58,7 @@ def parse_file(self, path: pathlib.Path) -> fp.ParsedSource:
return content


class Parser:
class DefParser:

skip_classes = (fp.BOF, fp.BOR, fp.BOS, fp.EOS, plain.CommentDefinition)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
pint.delegates.txt_parser.group
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pint.delegates.txt_defparser.group
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Definitions for parsing Group and their related objects
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
pint.delegates.txt_parser.plain
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pint.delegates.txt_defparser.plain
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Definitions for parsing:
- Equality
Expand Down Expand Up @@ -29,7 +29,7 @@
from ...converters import Converter
from ...facets.plain import definitions
from ...util import UnitsContainer
from ..base_parser import ParserConfig
from ..base_defparser import ParserConfig
from . import common


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
pint.facets.systems.definitions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pint.delegates.txt_defparser.system
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:copyright: 2022 by Pint Authors, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
Expand Down
4 changes: 2 additions & 2 deletions pint/facets/context/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ def variables(self) -> Set[str, ...]:
@classmethod
def from_lines(cls, lines, non_int_type):
# TODO: this is to keep it backwards compatible
from ...delegates import ParserConfig, txt_parser
from ...delegates import ParserConfig, txt_defparser

cfg = ParserConfig(non_int_type)
parser = txt_parser.Parser(cfg, None)
parser = txt_defparser.DefParser(cfg, None)
pp = parser.parse_string("\n".join(lines) + "\n@end")
for definition in parser.iter_parsed_project(pp):
if isinstance(definition, cls):
Expand Down
4 changes: 2 additions & 2 deletions pint/facets/context/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ def redefine(self, definition: str) -> None:
definition : str
<unit> = <new definition>``, e.g. ``pound = 0.5 kg``
"""
from ...delegates import ParserConfig, txt_parser
from ...delegates import ParserConfig, txt_defparser

# TODO: kept for backwards compatibility.
# this is not a good idea as we have no way of known the correct non_int_type
cfg = ParserConfig(float)
parser = txt_parser.Parser(cfg, None)
parser = txt_defparser.DefParser(cfg, None)
pp = parser.parse_string(definition)
for definition in parser.iter_parsed_project(pp):
if isinstance(definition, UnitDefinition):
Expand Down
4 changes: 2 additions & 2 deletions pint/facets/group/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class GroupDefinition(errors.WithDefErr):
@classmethod
def from_lines(cls, lines, non_int_type):
# TODO: this is to keep it backwards compatible
from ...delegates import ParserConfig, txt_parser
from ...delegates import ParserConfig, txt_defparser

cfg = ParserConfig(non_int_type)
parser = txt_parser.Parser(cfg, None)
parser = txt_defparser.DefParser(cfg, None)
pp = parser.parse_string("\n".join(lines) + "\n@end")
for definition in parser.iter_parsed_project(pp):
if isinstance(definition, cls):
Expand Down
14 changes: 7 additions & 7 deletions pint/facets/plain/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class PlainRegistry(metaclass=RegistryMeta):
_quantity_class = PlainQuantity
_unit_class = PlainUnit

_parser = None
_def_parser = None

def __init__(
self,
Expand Down Expand Up @@ -221,7 +221,7 @@ def __init__(
cache_folder
)

self._parser = delegates.txt_parser.Parser(
self._def_parser = delegates.txt_defparser.DefParser(
delegates.ParserConfig(non_int_type), diskcache=self._diskcache
)

Expand Down Expand Up @@ -406,9 +406,9 @@ def define(self, definition):
"""

if isinstance(definition, str):
parsed_project = self._parser.parse_string(definition)
parsed_project = self._def_parser.parse_string(definition)

for definition in self._parser.iter_parsed_project(parsed_project):
for definition in self._def_parser.iter_parsed_project(parsed_project):
self._helper_dispatch_adder(definition)
else:
self._helper_dispatch_adder(definition)
Expand Down Expand Up @@ -514,11 +514,11 @@ def load_definitions(self, file, is_resource: bool = False):

if isinstance(file, (list, tuple)):
# TODO: this hack was to keep it backwards compatible.
parsed_project = self._parser.parse_string("\n".join(file))
parsed_project = self._def_parser.parse_string("\n".join(file))
else:
parsed_project = self._parser.parse_file(file)
parsed_project = self._def_parser.parse_file(file)

for definition in self._parser.iter_parsed_project(parsed_project):
for definition in self._def_parser.iter_parsed_project(parsed_project):
self._helper_dispatch_adder(definition)

return parsed_project
Expand Down
4 changes: 2 additions & 2 deletions pint/facets/system/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class SystemDefinition(errors.WithDefErr):
@classmethod
def from_lines(cls, lines, non_int_type):
# TODO: this is to keep it backwards compatible
from ...delegates import ParserConfig, txt_parser
from ...delegates import ParserConfig, txt_defparser

cfg = ParserConfig(non_int_type)
parser = txt_parser.Parser(cfg, None)
parser = txt_defparser.DefParser(cfg, None)
pp = parser.parse_string("\n".join(lines) + "\n@end")
for definition in parser.iter_parsed_project(pp):
if isinstance(definition, cls):
Expand Down

0 comments on commit c38f348

Please sign in to comment.