Skip to content

Commit ac19e41

Browse files
implemented #10
2 parents dc62d98 + c3d8c75 commit ac19e41

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

pyregexp/pyrser.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Union, Callable
22
from functools import lru_cache
3+
import itertools
34
import math
45
from .lexer import Lexer
56
from .tokens import *
@@ -61,7 +62,7 @@ def next_tkn(without_consuming: bool = False) -> Union[Token, None]:
6162
def parse_re() -> RE:
6263
return RE(parse_re_seq())
6364

64-
def parse_re_seq(capturing: bool = True, group_name: str = 'default') -> Union[OrNode, GroupNode]:
65+
def parse_re_seq(capturing: bool = True, group_name: str = None) -> Union[OrNode, GroupNode]:
6566
match_start, match_end = False, False
6667
if type(curr_tkn) is Start or type(curr_tkn) is Circumflex:
6768
next_tkn()
@@ -86,7 +87,12 @@ def parse_re_seq(capturing: bool = True, group_name: str = 'default') -> Union[O
8687

8788
return node
8889

89-
def parse_group(capturing: bool = True, group_name: str = 'default') -> GroupNode:
90+
def parse_group(capturing: bool = True, group_name: str = None) -> GroupNode:
91+
nonlocal groups_counter
92+
93+
if group_name is None:
94+
group_name = "Group " + str(next(groups_counter))
95+
9096
elements = deque() # holds the children of the GroupNode
9197

9298
while curr_tkn is not None and not isinstance(curr_tkn, OrToken) and \
@@ -229,7 +235,8 @@ def parse_inner_el() -> RangeElement:
229235
return RangeElement(match_str="".join(sorted(set(match_str))), is_positive_logic=positive_logic)
230236

231237
def parse_el() -> Union[Element, OrNode, GroupNode]:
232-
group_name = "default"
238+
group_name: Union[str,None]
239+
group_name = None
233240
if isinstance(curr_tkn, ElementToken):
234241
return Element(match_ch=curr_tkn.char)
235242
elif isinstance(curr_tkn, Wildcard):
@@ -277,6 +284,8 @@ def parse_group_name() -> str:
277284
raise Exception('Unexpected empty named group name.')
278285
next_tkn() # consumes '>'
279286
return group_name
287+
288+
groups_counter = itertools.count(start=1)
280289

281290
curr_tkn = None
282291
next_tkn = next_tkn_initializer(re)

setup.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
from distutils.core import setup
1+
from setuptools import setup
2+
3+
from pathlib import Path
4+
this_directory = Path(__file__).parent
5+
long_description = (this_directory / "README.md").read_text()
26

37
setup(
48
name='pyregexp',
59
packages=['pyregexp'],
6-
version='0.1.6',
10+
version='0.1.7',
711
license='MIT',
812
description='Simple regex library',
13+
long_description=long_description,
14+
long_description_content_type='text/markdown',
915
author='Lorenzo Felletti',
1016
url='https://github.com/lorenzofelletti/pyregex',
11-
download_url='https://github.com/lorenzofelletti/pyregex/archive/v0.1.6.tar.gz',
17+
download_url='https://github.com/lorenzofelletti/pyregex/archive/v0.1.7.tar.gz',
1218
keywords=['Regex', 'RegExp', 'Engine'],
1319
install_requires=[],
1420
classifiers=[

0 commit comments

Comments
 (0)