00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "TokenPath.h"
00025
00026
00027
00028 using namespace std;
00029
00030 namespace Parser {
00031
00032 char const* const TokenPath::dirCode = "/\\^<>-+";
00033
00034 char const* TokenPath::Names[] = {
00035 "leftChild",
00036 "rightChild",
00037 "parent",
00038 "leftSibling",
00039 "rightSibling",
00040 "prev",
00041 "next"
00042 };
00043
00044 int TokenPath::get(string& tok)
00045 {
00046 char const** end = Names + sizeof(Names)/sizeof(char const*);
00047 for (char const** it = Names; it < end; it++)
00048 if (*it == tok)
00049 return (Direction)(it - Names);
00050 return -1;
00051 }
00052
00053 char const* TokenPath::Code() const
00054 {
00055 return code.c_str();
00056 }
00057
00058 std::ostream& TokenPath::serialize(ostream& os) const
00059 {
00060 int depth = 0;
00061 for (int i = 0; i < path.size(); i++) {
00062 os << Names[path[i]] << '(';
00063 depth++;
00064 }
00065 os << root;
00066 while (depth--)
00067 os << ')';
00068 return os;
00069 }
00070
00071 }