1
0
mirror of https://github.com/JoelBender/bacpypes synced 2025-09-28 22:15:23 +08:00

moved the context specification to the end of the statement

This commit is contained in:
Joel Bender 2015-11-18 08:47:36 -05:00
parent 4e8fa3b77a
commit 19f2b52e84

View File

@ -7,21 +7,21 @@ ExtendedTagList
An extended tag list adds a loads() function which takes a blob of text An extended tag list adds a loads() function which takes a blob of text
and parses it into a list of tags using the following mini language: and parses it into a list of tags using the following mini language:
opening [tag] n opening [tag] [context] n
closing [tag] n closing [tag] [context] n
[ [context] n ] null null [ [context] n ]
[ [context] n ] boolean (false | true) boolean (false | true) [ [context] n ]
[ [context] n ] unsigned [0-9]+ unsigned [0-9]+ [ [context] n ]
[ [context] n ] integer [+-][0-9]+ integer [+-][0-9]+ [ [context] n ]
[ [context] n ] real [+-][0-9]+([.][0-9]+)? real [+-][0-9]+([.][0-9]+)? [ [context] n ]
[ [context] n ] double [+-][0-9]+([.][0-9]+)? double [+-][0-9]+([.][0-9]+)? [ [context] n ]
[ [context] n ] octet [string] OCTETSTR octet [string] OCTETSTR [ [context] n ]
[ [context] n ] [character] string ([0-9]+)? CHARSTR [character] string ([0-9]+)? CHARSTR [ [context] n ]
[ [context] n ] bit [string] BITSTR bit [string] BITSTR [ [context] n ]
[ [context] n ] enumerated [0-9]+ enumerated [0-9]+ [ [context] n ]
[ [context] n ] date DATESTR date DATESTR [ [context] n ]
[ [context] n ] time TIMESTR time TIMESTR [ [context] n ]
[ [context] n ] object [identifier] OBJTYPE [,] OBJINST object [identifier] OBJTYPE [,] OBJINST [ [context] n ]
Blank lines and everything after the comment '#' is ignored. Blank lines and everything after the comment '#' is ignored.
@ -48,26 +48,24 @@ from bacpypes.primitivedata import *
_debug = 0 _debug = 0
_log = ModuleLogger(globals()) _log = ModuleLogger(globals())
# parse the command line arguments
args = ArgumentParser(description=__doc__).parse_args()
# globals # globals
statements = [] statements = []
statement_pattern = r""" statement_pattern = r"""
^ \s* # leading white space ^
( (context\s+)? (?P<context>[0-9]+) \s+ )? # optional context \s* # leading white space
(%s) # keyword (%s) # keyword
([#].*)? $ # optional comment ( (\s+context)? \s+ (?P<context>[0-9]+))? # optional context
""" ([#].*)? # optional comment
$"""
statement_value_pattern = r""" statement_value_pattern = r"""
^ \s* # leading white space ^
( (context\s+)? (?P<context>[0-9]+) \s+ )? # optional context \s* # leading white space
(%s) \s+ (?P<value>%s) \s* # keyword and value (%s) \s+ (?P<value>%s) # keyword and value
([#].*)? $ # optional comment ( (\s+context)? \s+ (?P<context>[0-9]+))? # optional context
""" \s* ([#].*)? # optional comment
$"""
# #
# blank lines # blank lines
@ -117,13 +115,13 @@ def statement(pattern):
# statements # statements
# #
@statement(r"opening(\s+tag)? [0-9]+") @statement(r"opening(\s+tag)?(\s+context)? [0-9]+")
def opening_tag_statement(value): def opening_tag_statement(value):
if _debug: ExtendedTagList._debug("opening_tag_statement %r", value) if _debug: ExtendedTagList._debug("opening_tag_statement %r", value)
return OpeningTag(int(value)) return OpeningTag(int(value))
@statement(r"closing(\s+tag)? [0-9]+") @statement(r"closing(\s+tag)?(\s+context)? [0-9]+")
def closing_tag_statement(value): def closing_tag_statement(value):
if _debug: ExtendedTagList._debug("closing_tag_statement %r", value) if _debug: ExtendedTagList._debug("closing_tag_statement %r", value)
@ -273,6 +271,8 @@ class ExtendedTagList(TagList):
# check for element already a tag # check for element already a tag
if isinstance(element, Tag): if isinstance(element, Tag):
tag = element tag = element
if context is not None:
raise RuntimeError("syntax error: %r" % (line,))
elif isinstance(element, Atomic): elif isinstance(element, Atomic):
tag = Tag() tag = Tag()
@ -310,6 +310,10 @@ class ExtendedTagList(TagList):
def main(): def main():
if _debug: main._debug("main") if _debug: main._debug("main")
# parse the command line arguments
args = ArgumentParser(description=__doc__).parse_args()
if _debug: main._debug(" - args: %r", args)
# suck in the test content # suck in the test content
text = sys.stdin.read() text = sys.stdin.read()