From 7cb8c5f7096be04cd65ec41a5b8f98d0ae3e890a Mon Sep 17 00:00:00 2001 From: NĂ©lio Laranjeiro Date: Sun, 23 Nov 2008 19:35:46 +0100 Subject: tools/trace: First version of the trace creator parser source file. --- tools/trace/lib/__init__.py | 0 tools/trace/lib/parser.g | 32 ++++++++++++++++++++++++++++++++ tools/trace/lib/traceclass.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 tools/trace/lib/__init__.py create mode 100644 tools/trace/lib/parser.g create mode 100644 tools/trace/lib/traceclass.py (limited to 'tools/trace/lib') diff --git a/tools/trace/lib/__init__.py b/tools/trace/lib/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tools/trace/lib/parser.g b/tools/trace/lib/parser.g new file mode 100644 index 00000000..2cee66b5 --- /dev/null +++ b/tools/trace/lib/parser.g @@ -0,0 +1,32 @@ +import sys + +from traceclass import * + +%% + +parser TraceParser: + ignore: "(#.*?)?\n" + token START: "^" + token EOF: "$" + token EVENT: "[a-zA-Z_]+" + token PARAM: "[a-zA-Z_1-9]+" + token LENGTH: "[1-2-4]" + token STRING: "\".*\"" + token SPACE: " " + + rule parser: START {{ my_list = list() }} + (event {{ my_list.append (event) }} + )* + EOF {{ return my_list }} + + rule event: "EVENT " EVENT {{ e = TraceEvent(EVENT.strip()) }} + SPACE + ( param SPACE {{ e.param_add (param[0], param[1]) }} + )* + ( string {{ e.string_set (string) }} + )* + "\n" {{ return e }} + + rule param: PARAM SPACE LENGTH {{ return [PARAM.strip(), int(LENGTH.strip())] }} + + rule string: STRING {{ return (STRING.strip()) }} diff --git a/tools/trace/lib/traceclass.py b/tools/trace/lib/traceclass.py new file mode 100644 index 00000000..3dd07142 --- /dev/null +++ b/tools/trace/lib/traceclass.py @@ -0,0 +1,43 @@ +# Define the trace Param. +class TraceParam: + def __init__ (self, name, length): + self.__name = name + + if (length == 0) or (length == 3) or (length > 4): + self.__length = 0 + raise Exception ("Length not permitted") + else: + self.__length = length + + def name (self): + return self.__name + + def length (self): + return self.__length + +# Defines the Events of the trace module. +class TraceEvent: + def __init__(self, name = ''): + self.__name = name + self.__param_list = list() + self.__string = "" + + def name (self): + return self.__name + + def param_add (self, name, length): + param = TraceParam (name, length) + self.__param_list.append(param) + + def param_get (self, pos): + if pos <= len (self.__param_list): + return self.__param_list[pos] + + def param_nb (self): + return len(self.__param_list) + + def string_set (self, string = ""): + self.__string = string + + def string_get (self): + return self.__string -- cgit v1.2.3