Notice to GitKraken users: A vulnerability has been found in the SSH key generation of GitKraken versions 7.6.0 to 8.0.0 (https://www.gitkraken.com/blog/weak-ssh-key-fix). If you use GitKraken and have generated a SSH key using one of these versions, please remove it both from your local workstation and from your LRZ GitLab profile.

21.10.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 729535fb authored by Eckhart Arnold's avatar Eckhart Arnold
Browse files

- sync commit

parent 58fda1ba
......@@ -29,6 +29,7 @@ for CST -> AST transformations.
import collections.abc
import inspect
import fnmatch
from functools import partial, reduce, singledispatch
from DHParser.error import Error
......@@ -64,6 +65,7 @@ __all__ = ('TransformationDict',
'is_expendable',
'is_token',
'is_one_of',
'matches_re',
'has_content',
'has_parent',
'lstrip',
......@@ -428,6 +430,29 @@ def is_one_of(context: List[Node], tag_name_set: AbstractSet[str]) -> bool:
return context[-1].tag_name in tag_name_set
# @transformation_factory(collections.abc.Set)
# def matches_wildcard(context: List[Node], wildcards: AbstractSet[str]) -> bool:
# """Retruns true, if the node's tag_name matches one of the glob patterns
# in `wildcards`. For example, ':*' matches all anonymous nodes. """
# tn = context[-1].tag_name
# for pattern in wildcards:
# if fnmatch.fnmatch(tn, pattern):
# return True
# return False
@transformation_factory(collections.abc.Set)
def matches_re(context: List[Node], patterns: AbstractSet[str]) -> bool:
"""Retruns true, if the node's tag_name matches one of the regular
expressions in `patterns`. For example, ':.*' matches all anonymous nodes.
"""
tn = context[-1].tag_name
for pattern in patterns:
if re.match(pattern, tn):
return True
return False
@transformation_factory
def has_content(context: List[Node], regexp: str) -> bool:
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment