[sorrows-mudlib] r197 committed - Minor upgrade to transcript parsing functionality. Still requires a l...

0 views
Skip to first unread message

sorrows...@googlecode.com

unread,
Dec 29, 2010, 7:57:32 AM12/29/10
to sorrows-mud...@googlegroups.com
Revision: 197
Author: richard.m.tew
Date: Wed Dec 29 04:55:25 2010
Log: Minor upgrade to transcript parsing functionality. Still requires a
lot more work.
http://code.google.com/p/sorrows-mudlib/source/detail?r=197

Modified:
/trunk/mudlib/transcript.py

=======================================
--- /trunk/mudlib/transcript.py Sat Dec 25 00:29:47 2010
+++ /trunk/mudlib/transcript.py Wed Dec 29 04:55:25 2010
@@ -6,9 +6,35 @@

import re, logging

+
LINE_TEMPLATE = "(?P<lineNumber>[0-9]{3})\.
(?P<timeHours>[0-9]{2}):(?P<timeMinutes>[0-9]{2}):(?P<timeSeconds>[0-9]{2})
(?P<command>.*)"
LINE_RE = re.compile(LINE_TEMPLATE)

+
+COMMAND_TEMPLATE
= "ob\s+(?P<name>[a-zA-Z_]\w*)\s+=\s+(?P<command>[a-zA-Z_]\w*)"
+COMMAND_RE = re.compile(COMMAND_TEMPLATE)
+ACTOR_COMMAND_TEMPLATE = "(?P<actor>[a-zA-Z_]\w*): (?P<command>.*)"
+ACTOR_COMMAND_RE = re.compile(ACTOR_COMMAND_TEMPLATE)
+ACTOR_OBSERVATION_TEMPLATE = "(?P<actor>[a-zA-Z_]\w*)\.\.
(?P<observation>.*)"
+ACTOR_OBSERVATION_RE = re.compile(ACTOR_OBSERVATION_TEMPLATE)
+
+
+class TranscriptCommand(object):
+ def __init__(self, variableName, variableCommand):
+ self.variableName = variableName
+ self.variableCommand = variableCommand
+
+class TranscriptActorCommand(object):
+ def __init__(self, variableName, variableCommand):
+ self.variableName = variableName
+ self.variableCommand = variableCommand
+
+class TranscriptActorObservation(object):
+ def __init__(self, variableName, variableObservation):
+ self.variableName = variableName
+ self.variableCommand = variableCommand
+
+
class Transcript(object):
def __init__(self):
self.lines = []
@@ -34,3 +60,30 @@
command = match.group("command")

logging.root.info("LINE %s", command)
+
+ match = COMMAND_RE.match(line)
+ if match is not None:
+ logging.root.info("COMMAND: name = %s", match.group("name"))
+ logging.root.info("COMMAND: command = %s",
match.group("command"))
+ self.lines.append(TranscriptCommand(command))
+ return
+
+ match = ACTOR_COMMAND_RE.match(line)
+ if match is not None:
+ logging.root.info("COMMAND: actor = %s", match.group("actor"))
+ logging.root.info("COMMAND: command = %s",
match.group("command"))
+ self.lines.append(TranscriptActorCommand(command))
+ return
+
+ match = ACTOR_OBSERVATION_RE.match(line)
+ if match is not None:
+ logging.root.info("OBSERVATION: actor = %s",
match.group("actor"))
+ logging.root.info("OBSERVATION: command = %s",
match.group("observation"))
+ self.lines.append(TranscriptActorObservation(command))
+ return
+
+ raise RuntimeError("Invalid transcript")
+
+ def Run(self):
+ pass
+

Reply all
Reply to author
Forward
0 new messages