Skip to content

Commit e3ee591

Browse files
committed
Added comments to parser.py
1 parent 8db1a64 commit e3ee591

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

textbeat/parser.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from .defs import *
22

3+
# Count the number of repeated characters of char `match` in sequence `seq`.
4+
# If no match is given, the first character found is used as the match char.
35
def count_seq(seq, match=''):
46
if not seq:
57
return 0
@@ -15,15 +17,22 @@ def count_seq(seq, match=''):
1517
r+=1
1618
return r
1719

20+
# Peel an unsigned int from the front of the string `s` and return both
21+
# the integer and its count. If nothing can be processed, return default `d`.
1822
def peel_uint(s, d=None):
1923
a,b = peel_uint_s(s,str(d) if d!=None else None)
2024
return (int(a) if a!=None and a!='' else None,b)
2125

26+
# Peel an integer from the front of the string `s` and return both
27+
# the integer and its count. If nothing can be processed, return default `d`.
2228
def peel_int(s, d=None):
2329
a,b = peel_uint_s(s,str(d) if d!=None else None)
2430
return (int(a) if a!=None and a!='' else None,b)
2531

26-
# don't cast
32+
# Peel an unsigned int from the front of the string `s` and return both
33+
# the integer (as a string) and its count. If nothing can be processed, return default `d`.
34+
# This is the `string` version of this function which returns the peeled integer
35+
# as a string.
2736
def peel_uint_s(s, d=None):
2837
r = ''
2938
for ch in s:
@@ -34,6 +43,9 @@ def peel_uint_s(s, d=None):
3443
if not r: return (d,0) if d!=None else ('',0)
3544
return (r,len(r))
3645

46+
# Peel a roman numeral from the front of the string `s` and return both
47+
# the roman numeral (as a string) and its count.
48+
# If nothing can be processed, return default `d`.
3749
def peel_roman_s(s, d=None):
3850
nums = 'ivx'
3951
r = ''
@@ -51,6 +63,9 @@ def peel_roman_s(s, d=None):
5163
if not r: return (d,0) if d!=None else ('',0)
5264
return (r,len(r))
5365

66+
# Peel an integer from the front of the string `s` and return both
67+
# the integer (as a string) and its count.
68+
# If nothing can be processed, return default `d`.
5469
def peel_int_s(s, d=None):
5570
r = ''
5671
for ch in s:
@@ -64,6 +79,9 @@ def peel_int_s(s, d=None):
6479
if not r: return (d,'') if d!=None else (0,'')
6580
return (int(r),len(r))
6681

82+
# Peel a float from the front of the string `s` and return both
83+
# the float and its count.
84+
# If nothing can be processed, return default `d`.
6785
def peel_float(s, d=None):
6886
r = ''
6987
decimals = 0
@@ -84,6 +102,9 @@ def peel_float(s, d=None):
84102
if not r: return (d,0) if d!=None else (0,0)
85103
return (float(r),len(r))
86104

105+
# Peel any number of characters matching char `match`.
106+
# Return the peeled string and its length.
107+
# If no match, return default `d`.
87108
def peel_any(s, match, d=''):
88109
r = ''
89110
ct = 0
@@ -95,7 +116,9 @@ def peel_any(s, match, d=''):
95116
break
96117
return (orr(r,d),ct)
97118

98-
def note_value(s): # turns dot note values (. and *) into frac
119+
# Turns dot note values (. and *) into a decimal.
120+
# Returns its floating point value and the number of repeated chars found.
121+
def note_value(s):
99122
if not s:
100123
return (0.0, 0)
101124
r = 1.0

0 commit comments

Comments
 (0)