Skip to content

Commit

Permalink
Add plumbing files to pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabrielgerez committed Sep 21, 2023
1 parent 1d446f8 commit 492ac6c
Show file tree
Hide file tree
Showing 12 changed files with 6,802 additions and 804 deletions.
5,493 changes: 5,491 additions & 2 deletions python/mrchem/input_parser/api.py

Large diffs are not rendered by default.

78 changes: 36 additions & 42 deletions python/mrchem/input_parser/plumbing/pyparsing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
:class:`'|'<MatchFirst>`, :class:`'^'<Or>` and :class:`'&'<Each>` operators.
The :class:`ParseResults` object returned from
:class:`ParserElement.parseString` can be
:class:`ParserElement.parse_string` can be
accessed as a nested list, a dictionary, or an object with named
attributes.
Expand Down Expand Up @@ -85,11 +85,11 @@
and :class:`'&'<Each>` operators to combine simple expressions into
more complex ones
- associate names with your parsed results using
:class:`ParserElement.setResultsName`
:class:`ParserElement.set_results_name`
- access the parsed data, which is returned as a :class:`ParseResults`
object
- find some helpful expression short-cuts like :class:`delimitedList`
and :class:`oneOf`
- find some helpful expression short-cuts like :class:`DelimitedList`
and :class:`one_of`
- find more useful common expressions in the :class:`pyparsing_common`
namespace class
"""
Expand All @@ -106,30 +106,22 @@ class version_info(NamedTuple):
@property
def __version__(self):
return (
"{}.{}.{}".format(self.major, self.minor, self.micro)
f"{self.major}.{self.minor}.{self.micro}"
+ (
"{}{}{}".format(
"r" if self.releaselevel[0] == "c" else "",
self.releaselevel[0],
self.serial,
),
f"{'r' if self.releaselevel[0] == 'c' else ''}{self.releaselevel[0]}{self.serial}",
"",
)[self.releaselevel == "final"]
)

def __str__(self):
return "{} {} / {}".format(__name__, self.__version__, __version_time__)
return f"{__name__} {self.__version__} / {__version_time__}"

def __repr__(self):
return "{}.{}({})".format(
__name__,
type(self).__name__,
", ".join("{}={!r}".format(*nv) for nv in zip(self._fields, self)),
)
return f"{__name__}.{type(self).__name__}({', '.join('{}={!r}'.format(*nv) for nv in zip(self._fields, self))})"


__version_info__ = version_info(3, 0, 9, "final", 0)
__version_time__ = "05 May 2022 07:02 UTC"
__version_info__ = version_info(3, 1, 1, "final", 1)
__version_time__ = "29 Jul 2023 22:27 UTC"
__version__ = __version_info__.__version__
__versionTime__ = __version_time__
__author__ = "Paul McGuire <[email protected]>"
Expand All @@ -139,9 +131,9 @@ def __repr__(self):
from .actions import *
from .core import __diag__, __compat__
from .results import *
from .core import *
from .core import * # type: ignore[misc, assignment]
from .core import _builtin_exprs as core_builtin_exprs
from .helpers import *
from .helpers import * # type: ignore[misc, assignment]
from .helpers import _builtin_exprs as helper_builtin_exprs

from .unicode import unicode_set, UnicodeRangeList, pyparsing_unicode as unicode
Expand All @@ -153,11 +145,11 @@ def __repr__(self):

# define backward compat synonyms
if "pyparsing_unicode" not in globals():
pyparsing_unicode = unicode
pyparsing_unicode = unicode # type: ignore[misc]
if "pyparsing_common" not in globals():
pyparsing_common = common
pyparsing_common = common # type: ignore[misc]
if "pyparsing_test" not in globals():
pyparsing_test = testing
pyparsing_test = testing # type: ignore[misc]

core_builtin_exprs += common_builtin_exprs + helper_builtin_exprs

Expand All @@ -174,7 +166,9 @@ def __repr__(self):
"CaselessKeyword",
"CaselessLiteral",
"CharsNotIn",
"CloseMatch",
"Combine",
"DelimitedList",
"Dict",
"Each",
"Empty",
Expand Down Expand Up @@ -227,9 +221,11 @@ def __repr__(self):
"alphas8bit",
"any_close_tag",
"any_open_tag",
"autoname_elements",
"c_style_comment",
"col",
"common_html_entity",
"condition_as_parse_action",
"counted_array",
"cpp_style_comment",
"dbl_quoted_string",
Expand All @@ -241,6 +237,7 @@ def __repr__(self):
"html_comment",
"identchars",
"identbodychars",
"infix_notation",
"java_style_comment",
"line",
"line_end",
Expand All @@ -255,8 +252,12 @@ def __repr__(self):
"null_debug_action",
"nums",
"one_of",
"original_text_for",
"printables",
"punc8bit",
"pyparsing_common",
"pyparsing_test",
"pyparsing_unicode",
"python_style_comment",
"quoted_string",
"remove_quotes",
Expand All @@ -267,38 +268,33 @@ def __repr__(self):
"srange",
"string_end",
"string_start",
"token_map",
"trace_parse_action",
"ungroup",
"unicode_set",
"unicode_string",
"with_attribute",
"indentedBlock",
"original_text_for",
"ungroup",
"infix_notation",
"locatedExpr",
"with_class",
"CloseMatch",
"token_map",
"pyparsing_common",
"pyparsing_unicode",
"unicode_set",
"condition_as_parse_action",
"pyparsing_test",
# pre-PEP8 compatibility names
"__versionTime__",
"anyCloseTag",
"anyOpenTag",
"cStyleComment",
"commonHTMLEntity",
"conditionAsParseAction",
"countedArray",
"cppStyleComment",
"dblQuotedString",
"dblSlashComment",
"delimitedList",
"dictOf",
"htmlComment",
"indentedBlock",
"infixNotation",
"javaStyleComment",
"lineEnd",
"lineStart",
"locatedExpr",
"makeHTMLTags",
"makeXMLTags",
"matchOnlyAtCol",
Expand All @@ -308,6 +304,7 @@ def __repr__(self):
"nullDebugAction",
"oneOf",
"opAssoc",
"originalTextFor",
"pythonStyleComment",
"quotedString",
"removeQuotes",
Expand All @@ -317,15 +314,12 @@ def __repr__(self):
"sglQuotedString",
"stringEnd",
"stringStart",
"tokenMap",
"traceParseAction",
"unicodeString",
"withAttribute",
"indentedBlock",
"originalTextFor",
"infixNotation",
"locatedExpr",
"withClass",
"tokenMap",
"conditionAsParseAction",
"autoname_elements",
"common",
"unicode",
"testing",
]
34 changes: 22 additions & 12 deletions python/mrchem/input_parser/plumbing/pyparsing/actions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# actions.py

from .exceptions import ParseException
from .util import col
from .util import col, replaced_by_pep8


class OnlyOnce:
Expand Down Expand Up @@ -38,7 +38,7 @@ def match_only_at_col(n):

def verify_col(strg, locn, toks):
if col(locn, strg) != n:
raise ParseException(strg, locn, "matched token not at column {}".format(n))
raise ParseException(strg, locn, f"matched token not at column {n}")

return verify_col

Expand Down Expand Up @@ -148,15 +148,13 @@ def pa(s, l, tokens):
raise ParseException(
s,
l,
"attribute {!r} has value {!r}, must be {!r}".format(
attrName, tokens[attrName], attrValue
),
f"attribute {attrName!r} has value {tokens[attrName]!r}, must be {attrValue!r}",
)

return pa


with_attribute.ANY_VALUE = object()
with_attribute.ANY_VALUE = object() # type: ignore [attr-defined]


def with_class(classname, namespace=""):
Expand Down Expand Up @@ -195,13 +193,25 @@ def with_class(classname, namespace=""):
1 4 0 1 0
1,3 2,3 1,1
"""
classattr = "{}:class".format(namespace) if namespace else "class"
classattr = f"{namespace}:class" if namespace else "class"
return with_attribute(**{classattr: classname})


# pre-PEP8 compatibility symbols
replaceWith = replace_with
removeQuotes = remove_quotes
withAttribute = with_attribute
withClass = with_class
matchOnlyAtCol = match_only_at_col
# fmt: off
@replaced_by_pep8(replace_with)
def replaceWith(): ...

@replaced_by_pep8(remove_quotes)
def removeQuotes(): ...

@replaced_by_pep8(with_attribute)
def withAttribute(): ...

@replaced_by_pep8(with_class)
def withClass(): ...

@replaced_by_pep8(match_only_at_col)
def matchOnlyAtCol(): ...

# fmt: on
Loading

0 comments on commit 492ac6c

Please sign in to comment.