[chirp_devel] [PATCH 10/11] Fix pyinit issues for bitwise_grammar.py (#159)
Zachary T Welch
Sun Mar 8 16:54:24 PDT 2015
# HG changeset patch
# User Zachary T Welch <zach at mandolincreekfarm.com>
# Fake Node ID df805eb669f786e63cbad9f508ffe0f0d1bfb969
Fix pyinit issues for bitwise_grammar.py (#159)
diff --git a/chirp/bitwise_grammar.py b/chirp/bitwise_grammar.py
index b6eb20c..96a9b0a 100644
--- a/chirp/bitwise_grammar.py
+++ b/chirp/bitwise_grammar.py
@@ -13,6 +13,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+"""
+Grammar for parsing CHIRP's memory layout definitions.
+"""
+
import re
from chirp.pyPEG import keyword, parse as pypeg_parse
@@ -23,104 +27,130 @@ DIRECTIVES = ["seekto", "seek", "printoffset"]
def string():
+ """Return a compiled regular expression matching a quoted string."""
return re.compile(r"\"[^\"]*\"")
def symbol():
+ """Return a compiled regular expression matching a symbol."""
return re.compile(r"\w+")
def count():
+ """Return a compiled regular expression matching a decimal
+ or hexidecimal number."""
return re.compile(r"([1-9][0-9]*|0x[0-9a-fA-F]+)")
def bitdef():
+ """Return a list of expressions matching an individual bit slice"""
return symbol, ":", count, -1
def _bitdeflist():
+ """Return a list of expressions matching a bitfield."""
return bitdef, -1, (",", bitdef)
def bitfield():
+ """Return a list of expressions matching a bitfield."""
return -2, _bitdeflist
def array():
+ """Return a list of expressions matching an array."""
return symbol, '[', count, ']'
def _typedef():
+ """Return a compiled regular expression matching a primitive type."""
return re.compile(r"(%s)" % "|".join(TYPES))
def definition():
+ """Return a list of expressions matching a field definition."""
return _typedef, [array, bitfield, symbol], ";"
def seekto():
+ """Return an expression matching a seekto directive."""
return keyword("seekto"), count
def seek():
+ """Return an expression matching a seek directive."""
return keyword("seek"), count
def printoffset():
+ """Return an expression matching a printoffset directive."""
return keyword("printoffset"), string
def directive():
+ """Return an expression matching a CHIRP directive."""
return "#", [seekto, seek, printoffset], ";"
def _block_inner():
+ """Return an expression matching an inner block."""
return -2, [definition, struct, directive]
def _block():
+ """Return an expression matching a block."""
return "{", _block_inner, "}"
def struct_defn():
+ """Return an expression matching a structure definition."""
return symbol, _block
def struct_decl():
+ """Return an expression matching a structure declaration."""
return [symbol, _block], [array, symbol]
def struct():
+ """Return an expression matching a structure definition or declaration."""
return keyword("struct"), [struct_defn, struct_decl], ";"
def _language():
+ """Return an expression for the entire language."""
return _block_inner
def parse(data):
+ """Parse the data using the grammar defined in this file."""
lines = data.split("\n")
for index, line in enumerate(lines):
if '//' in line:
lines[index] = line[:line.index('//')]
- class FakeFileInput:
+ class FakeFileInput(object):
"""Simulate line-by-line file reading from @data"""
line = -1
def isfirstline(self):
+ """Return True if reading the first line."""
return self.line == 0
def filename(self):
+ """Return the filename."""
return "input"
def lineno(self):
+ """Return the current line number."""
return self.line
def __iter__(self):
+ """Return an interator."""
return self
def next(self):
+ """Read the next line."""
self.line += 1
try:
# Note, FileInput objects keep the newlines
diff --git a/tools/cpep8.lintful b/tools/cpep8.lintful
index 68c32b7..caf4dcf 100644
--- a/tools/cpep8.lintful
+++ b/tools/cpep8.lintful
@@ -2,7 +2,6 @@
# DO NOT ADD NEW FILES!! Instead, fix the code to be compliant.
# Over time, this list should shrink and (eventually) be eliminated.
./chirp/bitwise.py
-./chirp/bitwise_grammar.py
./chirp/chirp_common.py
./chirp/directory.py
./chirp/drivers/alinco.py
More information about the chirp_devel
mailing list