SNOBOL4python 0.4.4__tar.gz → 0.4.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,6 @@ include LICENSE
3
3
  recursive-include src/SNOBOL4python *.py
4
4
  recursive-include tests test_*.py
5
5
  recursive-exclude misc test_*.py
6
- global-exclude __pycache__
7
6
  global-exclude *.py[co]
8
7
  global-exclude *.so
9
8
  exclude .gitignore
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: SNOBOL4python
3
- Version: 0.4.4
3
+ Version: 0.4.5
4
4
  Summary: A Python library for SNOBOL4-style pattern matching with support for regular expressions.
5
5
  Author-email: Lon Jones Cherryholmes <lcherryh@yahoo.com>
6
6
  License-Expression: GPL-3.0-or-later
@@ -12,7 +12,6 @@ Classifier: Programming Language :: Python :: 3
12
12
  Requires-Python: >=3.10.0
13
13
  Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
- Requires-Dist: pytest
16
15
  Dynamic: license-file
17
16
 
18
17
  # SNOBOL4python
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "SNOBOL4python"
7
- version = "0.4.4"
7
+ version = "0.4.5"
8
8
  description = "A Python library for SNOBOL4-style pattern matching with support for regular expressions."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10.0"
@@ -14,7 +14,7 @@ keywords = ["Python", "SNOBOL", "SNOBOL4", "string pattern matching"]
14
14
  classifiers = [
15
15
  "Programming Language :: Python :: 3",
16
16
  ]
17
- dependencies = ["pytest"]
17
+ dependencies = []
18
18
 
19
19
  [project-optional-dependencies]
20
20
  test = ["pytest"]
@@ -7,10 +7,11 @@
7
7
  #> python -m pip install --upgrade setuptools wheel build
8
8
  #> python src/SNOBOL4python/SNOBOL4patterns.py
9
9
  #> python -m build
10
- #> python -m pip install ./dist/snobol4python-0.4.4.tar.gz
11
- #> python -m pip install ./dist/snobol4python-0.4.4-py3-none-any.whl
10
+ #> python -m pip install ./dist/snobol4python-0.4.5.tar.gz
11
+ #> python -m pip install ./dist/snobol4python-0.4.5-py3-none-any.whl
12
12
  #> python -m pip install --index-url https://test.pypi.org/simple SNOBOL4python
13
13
  #> python -m twine check ./dist/*
14
+ #> python -m twine upload ./dist/*
14
15
  #> python tests/test_01.py
15
16
  #> python tests/test_json.py
16
17
  #> python tests/test_arbno.py
@@ -48,6 +49,7 @@ class PATTERN(object):
48
49
  def __contains__(self, other): return SEARCH(other, self, exc=False) # comparison in operator, returns bool
49
50
  #----------------------------------------------------------------------------------------------------------------------
50
51
  class STRING(str):
52
+ def __repr__(self): return str.__repr__(self)
51
53
  def __add__(self, other): # SIGMA
52
54
  if isinstance(other, Σ): return Σ(σ(self), *other.AP)
53
55
  elif isinstance(other, str): return STRING(super().__add__(other))
@@ -140,7 +142,7 @@ class ζ(PATTERN):
140
142
  if callable(self.N): self.P = self.N()
141
143
  else: self.P = _globals[str(self.N)]
142
144
  else: self.P = _globals[self.N]
143
- yield from self.P
145
+ yield from copy.deepcopy(self.P)
144
146
  #----------------------------------------------------------------------------------------------------------------------
145
147
  class nPush(PATTERN):
146
148
  def __init__(self): super().__init__()
@@ -343,15 +345,15 @@ class σ(PATTERN): # sigma, σ, sequence of characters, string patttern
343
345
  self.lit = self.s
344
346
  if not isinstance(self.lit, str):
345
347
  if callable(self.lit): self.lit = str(self.lit())
346
- else: self.lit = str(self.lit) # should possibly be exception
348
+ else: self.lit = str(self.lit) # might need to raise an exception
347
349
  logger.debug("σ(%r) trying(%d)", self.lit, pos0)
348
350
  if pos0 + len(self.lit) <= len(Ϣ[-1].subject):
349
351
  if self.lit == Ϣ[-1].subject[pos0:pos0 + len(self.lit)]:
350
352
  logger.info("σ(%r) SUCCESS(%d,%d)=", self.lit, Ϣ[-1].pos, len(self.lit))
351
353
  Ϣ[-1].pos += len(self.lit)
352
354
  yield slice(pos0, Ϣ[-1].pos)
353
- Ϣ[-1].pos -= len(self.lit)
354
- logger.warning("σ(%r) backtracking(%d)...", self.lit, Ϣ[-1].pos)
355
+ logger.warning("σ(%r) backtracking(%d,%d)...", self.lit, pos0, Ϣ[-1].pos)
356
+ Ϣ[-1].pos = pos0
355
357
  return None
356
358
  #----------------------------------------------------------------------------------------------------------------------
357
359
  class ANY(PATTERN):
@@ -372,8 +374,8 @@ class ANY(PATTERN):
372
374
  logger.info("ANY(%r) SUCCESS(%d,%d)=%s", self.characters, Ϣ[-1].pos, 1, Ϣ[-1].subject[Ϣ[-1].pos])
373
375
  Ϣ[-1].pos += 1
374
376
  yield slice(Ϣ[-1].pos - 1, Ϣ[-1].pos)
377
+ logger.warning("ANY(%r) backtracking(%d,%d)...", self.characters, Ϣ[-1].pos - 1, Ϣ[-1].pos)
375
378
  Ϣ[-1].pos -= 1
376
- logger.warning("ANY(%r) backtracking(%d)...", self.characters, Ϣ[-1].pos)
377
379
  #----------------------------------------------------------------------------------------------------------------------
378
380
  class NOTANY(PATTERN):
379
381
  def __init__(self, chars): super().__init__(); self.chars = chars
@@ -393,8 +395,8 @@ class NOTANY(PATTERN):
393
395
  logger.info("NOTANY(%r) SUCCESS(%d,%d)=%s", self.characters, Ϣ[-1].pos, 1, Ϣ[-1].subject[Ϣ[-1].pos])
394
396
  Ϣ[-1].pos += 1
395
397
  yield slice(Ϣ[-1].pos - 1, Ϣ[-1].pos)
398
+ logger.warning("NOTANY(%r) backtracking(%d,%d)...", self.characters, Ϣ[-1].pos - 1, Ϣ[-1].pos)
396
399
  Ϣ[-1].pos -= 1
397
- logger.warning("NOTANY(%r) backtracking(%d)...", self.characters, Ϣ[-1].pos)
398
400
  #----------------------------------------------------------------------------------------------------------------------
399
401
  class SPAN(PATTERN):
400
402
  def __init__(self, chars): super().__init__(); self.chars = chars
@@ -417,8 +419,8 @@ class SPAN(PATTERN):
417
419
  if Ϣ[-1].pos > pos0:
418
420
  logger.info("SPAN(%r) SUCCESS(%d,%d)=%s", self.characters, pos0, Ϣ[-1].pos - pos0, Ϣ[-1].subject[pos0:Ϣ[-1].pos])
419
421
  yield slice(pos0, Ϣ[-1].pos)
422
+ logger.warning("SPAN(%r) backtracking(%d,%d)...", self.characters, pos0, Ϣ[-1].pos)
420
423
  Ϣ[-1].pos = pos0
421
- logger.warning("SPAN(%r) backtracking(%d)...", self.characters, Ϣ[-1].pos)
422
424
  return None
423
425
  #----------------------------------------------------------------------------------------------------------------------
424
426
  class BREAK(PATTERN):
@@ -442,8 +444,8 @@ class BREAK(PATTERN):
442
444
  if Ϣ[-1].pos < len(Ϣ[-1].subject):
443
445
  logger.info("BREAK(%r) SUCCESS(%d,%d)=%s", self.characters, pos0, Ϣ[-1].pos - pos0, Ϣ[-1].subject[pos0:Ϣ[-1].pos])
444
446
  yield slice(pos0, Ϣ[-1].pos)
447
+ logger.warning("BREAK(%r) backtracking(%d,%d)...", self.characters, pos0, Ϣ[-1].pos)
445
448
  Ϣ[-1].pos = pos0
446
- logger.warning("BREAK(%r) backtracking(%d)...", self.characters, Ϣ[-1].pos)
447
449
  #----------------------------------------------------------------------------------------------------------------------
448
450
  class BREAKX(BREAK): pass
449
451
  #----------------------------------------------------------------------------------------------------------------------
@@ -623,7 +625,7 @@ class φ(PATTERN):
623
625
  Ϣ[-1].pos = pos0
624
626
  else: raise Exception("Yikes! Internal error.")
625
627
  #----------------------------------------------------------------------------------------------------------------------
626
- class ρ(PATTERN): # PSI, AND, conjunction
628
+ class ρ(PATTERN): # rho, AND, conjunction
627
629
  def __init__(self, P:PATTERN, Q:PATTERN): super().__init__(); self.P = P; self.Q = Q
628
630
  def __repr__(self): return "ρ(*{0})".format(len(self.AP))
629
631
  def __deepcopy__(self, memo): return ρ(copy.deepcopy(self.P), copy.deepcopy(self.Q))
@@ -676,7 +678,7 @@ class Σ(PATTERN): # SIGMA, Σ, sequence, subsequents, SNOBOL4: P Q R S T ...
676
678
  if cursor >= len(self.AP):
677
679
  logger.info("Σ(*) SUCCESS(%d,%d)=%s", pos0, Ϣ[-1].pos - pos0, Ϣ[-1].subject[pos0:Ϣ[-1].pos])
678
680
  yield slice(pos0, Ϣ[-1].pos)
679
- logger.warning("Σ(*) backtracking(%d)...", pos0)
681
+ logger.warning("Σ(*) backtracking(%d,%d)...", pos0, Ϣ[-1].pos)
680
682
  cursor -= 1
681
683
  if cursor >= highmark:
682
684
  iter(self.AP[cursor])
@@ -748,7 +750,7 @@ class DEBUG_formatter(logging.Formatter):
748
750
  global Ϣ, _window_size
749
751
  original_message = super().format(record)
750
752
  if len(Ϣ) > 0:
751
- formatted_message = "{0:s} {1:s}".format(self.window(_window_size // 2), original_message) # , ' ' * Ϣ[-1].depth
753
+ formatted_message = "{0:s} {1:s}".format(self.window(_window_size // 2), original_message) # {2:s} # ' ' * Ϣ[-1].depth,
752
754
  else: formatted_message = original_message
753
755
  return formatted_message
754
756
  #----------------------------------------------------------------------------------------------------------------------
@@ -844,10 +846,14 @@ if __name__ == "__main__":
844
846
  from SNOBOL4functions import DEFINE, REPLACE, SUBSTITUTE
845
847
  from SNOBOL4functions import END, RETURN, FRETURN, NRETURN
846
848
  GLOBALS(globals())
849
+ TRACE(50)
850
+ # --------------------------------------------------------------------------------------------------------------------
847
851
  if "SNOBOL4" in POS(0) + (SPAN("ABCDEFGHIJKLMNOPQRSTUVWXYZ") + σ('4')) % "name" + RPOS(0):
848
852
  print(name)
849
853
  if "SNOBOL4" in POS(0) + (BREAK("0123456789") + σ('4')) % "name" + RPOS(0):
850
854
  print(name)
851
855
  if "001_01C717AB.5C51AFDE ..." in φ(r"(?P<name>[0-9]{3}(_[0-9A-F]{4})?_[0-9A-F]{8}\.[0-9A-F]{8})"):
852
856
  print(name)
857
+ # --------------------------------------------------------------------------------------------------------------------
858
+ exit(0)
853
859
  #-----------------------------------------------------------------------------------------------------------------------
@@ -0,0 +1,104 @@
1
+ ' '| 0|'(x*y) ' Σ(Θ('pos') Λ(<function <lambda> at 0x00000197996a1ec0>) POS(0) Π(*3) Θ('pos') Λ(<function <lambda> at 0x00000197996a1f60>) RPOS(0)) trying(0)...
2
+ ' '| 0|'(x*y) ' Θ(pos) SUCCESS
3
+ ' '| 0|'(x*y) ' Λ(function) evaluating...
4
+ ' '| 0|'(x*y) ' Λ(function) SUCCESS
5
+ ' '| 0|'(x*y) ' POS(0) SUCCESS(0,0)=
6
+ ' '| 0|'(x*y) ' Π(Σ(*3) Σ(*2) Π(*3)) trying(0)...
7
+ ' '| 0|'(x*y) ' Σ(Π(*3) ANY('+-*/') ζ('X')) trying(0)...
8
+ ' '| 0|'(x*y) ' Π(ANY('abcdefghijklmnopqrstuvwxyz') SPAN('0123456789') Σ(*3)) trying(0)...
9
+ ' '| 0|'(x*y) ' ANY('abcdefghijklmnopqrstuvwxyz') trying(0)
10
+ ' '| 0|'(x*y) ' SPAN('0123456789') trying(0)
11
+ ' '| 0|'(x*y) ' Σ(σ('(') ζ('X') σ(')')) trying(0)...
12
+ ' '| 0|'(x*y) ' σ('(') trying(0)
13
+ ' '| 0|'(x*y) ' σ('(') SUCCESS(0,1)=
14
+ ' ('| 1|'x*y) ' Π(Σ(*3) Σ(*2) Π(*3)) trying(1)...
15
+ ' ('| 1|'x*y) ' Σ(Π(*3) ANY('+-*/') ζ('X')) trying(1)...
16
+ ' ('| 1|'x*y) ' Π(ANY('abcdefghijklmnopqrstuvwxyz') SPAN('0123456789') Σ(*3)) trying(1)...
17
+ ' ('| 1|'x*y) ' ANY('abcdefghijklmnopqrstuvwxyz') trying(1)
18
+ ' ('| 1|'x*y) ' ANY('abcdefghijklmnopqrstuvwxyz') SUCCESS(1,1)=x
19
+ ' (x'| 2|'*y) ' ANY('+-*/') trying(2)
20
+ ' (x'| 2|'*y) ' ANY('+-*/') SUCCESS(2,1)=*
21
+ ' (x*'| 3|'y) ' Π(Σ(*3) Σ(*2) Π(*3)) trying(3)...
22
+ ' (x*'| 3|'y) ' Σ(Π(*3) ANY('+-*/') ζ('X')) trying(3)...
23
+ ' (x*'| 3|'y) ' Π(ANY('abcdefghijklmnopqrstuvwxyz') SPAN('0123456789') Σ(*3)) trying(3)...
24
+ ' (x*'| 3|'y) ' ANY('abcdefghijklmnopqrstuvwxyz') trying(3)
25
+ ' (x*'| 3|'y) ' ANY('abcdefghijklmnopqrstuvwxyz') SUCCESS(3,1)=y
26
+ ' (x*y'| 4|') ' ANY('+-*/') trying(4)
27
+ ' (x*y'| 4|') ' ANY('abcdefghijklmnopqrstuvwxyz') backtracking(3,4)...
28
+ ' (x*'| 3|'y) ' SPAN('0123456789') trying(3)
29
+ ' (x*'| 3|'y) ' Σ(σ('(') ζ('X') σ(')')) trying(3)...
30
+ ' (x*'| 3|'y) ' σ('(') trying(3)
31
+ ' (x*'| 3|'y) ' Σ(ANY('+-') ζ('X')) trying(3)...
32
+ ' (x*'| 3|'y) ' ANY('+-') trying(3)
33
+ ' (x*'| 3|'y) ' Π(ANY('abcdefghijklmnopqrstuvwxyz') SPAN('0123456789') Σ(*3)) trying(3)...
34
+ ' (x*'| 3|'y) ' ANY('abcdefghijklmnopqrstuvwxyz') trying(3)
35
+ ' (x*'| 3|'y) ' ANY('abcdefghijklmnopqrstuvwxyz') SUCCESS(3,1)=y
36
+ ' (x*y'| 4|') ' Σ(*) SUCCESS(1,3)=x*y
37
+ ' (x*y'| 4|') ' σ(')') trying(4)
38
+ ' (x*y'| 4|') ' σ(')') SUCCESS(4,1)=
39
+ ' (x*y)'| 5|' ' Σ(*) SUCCESS(0,5)=(x*y)
40
+ ' (x*y)'| 5|' ' ANY('+-*/') trying(5)
41
+ ' (x*y)'| 5|' ' Σ(*) backtracking(0, 5)...
42
+ ' (x*y'| 4|') ' σ(')') backtracking(4)...
43
+ ' (x*y'| 4|') ' Σ(*) backtracking(1, 4)...
44
+ ' (x*y'| 4|') ' ANY('abcdefghijklmnopqrstuvwxyz') backtracking(3,4)...
45
+ ' (x*'| 3|'y) ' SPAN('0123456789') trying(3)
46
+ ' (x*'| 3|'y) ' Σ(σ('(') ζ('X') σ(')')) trying(3)...
47
+ ' (x*'| 3|'y) ' σ('(') trying(3)
48
+ ' (x*'| 3|'y) ' ANY('+-*/') backtracking(2,3)...
49
+ ' (x'| 2|'*y) ' ANY('abcdefghijklmnopqrstuvwxyz') backtracking(1,2)...
50
+ ' ('| 1|'x*y) ' SPAN('0123456789') trying(1)
51
+ ' ('| 1|'x*y) ' Σ(σ('(') ζ('X') σ(')')) trying(1)...
52
+ ' ('| 1|'x*y) ' σ('(') trying(1)
53
+ ' ('| 1|'x*y) ' Σ(ANY('+-') ζ('X')) trying(1)...
54
+ ' ('| 1|'x*y) ' ANY('+-') trying(1)
55
+ ' ('| 1|'x*y) ' Π(ANY('abcdefghijklmnopqrstuvwxyz') SPAN('0123456789') Σ(*3)) trying(1)...
56
+ ' ('| 1|'x*y) ' ANY('abcdefghijklmnopqrstuvwxyz') trying(1)
57
+ ' ('| 1|'x*y) ' ANY('abcdefghijklmnopqrstuvwxyz') SUCCESS(1,1)=x
58
+ ' (x'| 2|'*y) ' σ(')') trying(2)
59
+ ' (x'| 2|'*y) ' ANY('abcdefghijklmnopqrstuvwxyz') backtracking(1,2)...
60
+ ' ('| 1|'x*y) ' SPAN('0123456789') trying(1)
61
+ ' ('| 1|'x*y) ' Σ(σ('(') ζ('X') σ(')')) trying(1)...
62
+ ' ('| 1|'x*y) ' σ('(') trying(1)
63
+ ' '| 0|'(x*y) ' σ('(') backtracking(0)...
64
+ ' '| 0|'(x*y) ' Σ(ANY('+-') ζ('X')) trying(0)...
65
+ ' '| 0|'(x*y) ' ANY('+-') trying(0)
66
+ ' '| 0|'(x*y) ' Π(ANY('abcdefghijklmnopqrstuvwxyz') SPAN('0123456789') Σ(*3)) trying(0)...
67
+ ' '| 0|'(x*y) ' ANY('abcdefghijklmnopqrstuvwxyz') trying(0)
68
+ ' '| 0|'(x*y) ' SPAN('0123456789') trying(0)
69
+ ' '| 0|'(x*y) ' Σ(σ('(') ζ('X') σ(')')) trying(0)...
70
+ ' '| 0|'(x*y) ' σ('(') trying(0)
71
+ ' '| 0|'(x*y) ' σ('(') SUCCESS(0,1)=
72
+ ' ('| 1|'x*y) ' Π(Σ(*3) Σ(*2) Π(*3)) trying(1)...
73
+ ' ('| 1|'x*y) ' Σ(Π(*3) ANY('+-*/') ζ('X')) trying(1)...
74
+ ' ('| 1|'x*y) ' Π(ANY('abcdefghijklmnopqrstuvwxyz') SPAN('0123456789') Σ(*3)) trying(1)...
75
+ ' ('| 1|'x*y) ' ANY('abcdefghijklmnopqrstuvwxyz') trying(1)
76
+ ' ('| 1|'x*y) ' ANY('abcdefghijklmnopqrstuvwxyz') SUCCESS(1,1)=x
77
+ ' (x'| 2|'*y) ' ANY('+-*/') trying(2)
78
+ ' (x'| 2|'*y) ' ANY('+-*/') SUCCESS(2,1)=*
79
+ ' (x*'| 3|'y) ' Π(Σ(*3) Σ(*2) Π(*3)) trying(3)...
80
+ ' (x*'| 3|'y) ' Σ(Π(*3) ANY('+-*/') ζ('X')) trying(3)...
81
+ ' (x*'| 3|'y) ' Π(ANY('abcdefghijklmnopqrstuvwxyz') SPAN('0123456789') Σ(*3)) trying(3)...
82
+ ' (x*'| 3|'y) ' ANY('abcdefghijklmnopqrstuvwxyz') trying(3)
83
+ ' (x*'| 3|'y) ' ANY('abcdefghijklmnopqrstuvwxyz') SUCCESS(3,1)=y
84
+ ' (x*y'| 4|') ' ANY('+-*/') trying(4)
85
+ ' (x*y'| 4|') ' ANY('abcdefghijklmnopqrstuvwxyz') backtracking(3,4)...
86
+ ' (x*'| 3|'y) ' SPAN('0123456789') trying(3)
87
+ ' (x*'| 3|'y) ' Σ(σ('(') ζ('X') σ(')')) trying(3)...
88
+ ' (x*'| 3|'y) ' σ('(') trying(3)
89
+ ' (x*'| 3|'y) ' Σ(ANY('+-') ζ('X')) trying(3)...
90
+ ' (x*'| 3|'y) ' ANY('+-') trying(3)
91
+ ' (x*'| 3|'y) ' Π(ANY('abcdefghijklmnopqrstuvwxyz') SPAN('0123456789') Σ(*3)) trying(3)...
92
+ ' (x*'| 3|'y) ' ANY('abcdefghijklmnopqrstuvwxyz') trying(3)
93
+ ' (x*'| 3|'y) ' ANY('abcdefghijklmnopqrstuvwxyz') SUCCESS(3,1)=y
94
+ ' (x*y'| 4|') ' Σ(*) SUCCESS(1,3)=x*y
95
+ ' (x*y'| 4|') ' σ(')') trying(4)
96
+ ' (x*y'| 4|') ' σ(')') SUCCESS(4,1)=
97
+ ' (x*y)'| 5|' ' Σ(*) SUCCESS(0,5)=(x*y)
98
+ ' (x*y)'| 5|' ' Θ(pos) SUCCESS
99
+ ' (x*y)'| 5|' ' Λ(function) evaluating...
100
+ ' (x*y)'| 5|' ' Λ(function) SUCCESS
101
+ ' (x*y)'| 5|' ' RPOS(0) SUCCESS(5,0)=
102
+ ' (x*y)'| 5|' ' Σ(*) SUCCESS(0,5)=(x*y)
103
+ ' (x*y)'| 5|' ' SEARCH(): "(x*y)" ? "slice(0, 5, None)"
104
+ P0·R5·
@@ -7,6 +7,7 @@ setup.cfg
7
7
  src/SNOBOL4python/SNOBOL4functions.py
8
8
  src/SNOBOL4python/SNOBOL4patterns.py
9
9
  src/SNOBOL4python/__init__.py
10
+ src/SNOBOL4python/deleteme.py
10
11
  tests/test_01.py
11
12
  tests/test_arbno.py
12
13
  tests/test_json.py
File without changes
File without changes
File without changes