-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathFlattenMsg.chpl
92 lines (82 loc) · 3.68 KB
/
FlattenMsg.chpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
module FlattenMsg {
use MultiTypeSymbolTable;
use MultiTypeSymEntry;
use ServerErrors;
use Reflection;
use Flatten;
use ServerConfig;
use SegmentedString;
use Logging;
use Message;
private config const logLevel = ServerConfig.logLevel;
private config const logChannel = ServerConfig.logChannel;
const fmLogger = new Logger(logLevel, logChannel);
proc segFlattenMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
const objtype = msgArgs.getValueOf("objtype").toUpper(): ObjType;
const returnSegs: bool = msgArgs.get("return_segs").getBoolValue();
const regex: bool = msgArgs.get("regex").getBoolValue();
const delim: string = msgArgs.getValueOf("delim");
var repMsg: string;
select objtype {
when ObjType.STRINGS {
const rSegName = st.nextName();
const rValName = st.nextName();
const strings = getSegString(msgArgs.getValueOf("values"), st);
var (off, val, segs) = strings.flatten(delim, returnSegs, regex);
var stringsObj = getSegString(off, val, st);
repMsg = "created %s+created bytes.size %?".format(st.attrib(stringsObj.name), stringsObj.nBytes);
if returnSegs {
const optName: string = st.nextName();
st.addEntry(optName, createSymEntry(segs));
repMsg += "+created %s".format(st.attrib(optName));
}
} otherwise {
throw new owned ErrorWithContext("Not implemented for objtype %s".format(objtype),
getLineNumber(),
getRoutineName(),
getModuleName(),
"TypeError");
}
}
fmLogger.debug(getModuleName(),getRoutineName(),getLineNumber(),repMsg);
return new MsgTuple(repMsg, MsgType.NORMAL);
}
proc segmentedSplitMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
var pn = Reflection.getRoutineName();
var repMsg: string;
const objtype = msgArgs.getValueOf("objtype");
const name = msgArgs.getValueOf("parent_name");
const returnSegs = msgArgs.get("return_segs").getBoolValue();
var maxsplit: int = msgArgs.get("max").getIntValue();
// check to make sure symbols defined
st.checkTable(name);
const pattern: string = msgArgs.getValueOf("pattern");
fmLogger.debug(getModuleName(), getRoutineName(), getLineNumber(),
"cmd: %s objtype: %?".format(cmd, objtype));
select objtype {
when "Matcher" {
const optName: string = if returnSegs then st.nextName() else "";
const strings = getSegString(name, st);
var (off, val, segs) = strings.split(pattern, maxsplit, returnSegs);
var retString = getSegString(off, val, st);
repMsg = "created " + st.attrib(retString.name) + "+created bytes.size %?".format(retString.nBytes);
if returnSegs {
st.addEntry(optName, createSymEntry(segs));
repMsg += "+created %s".format(st.attrib(optName));
}
}
otherwise {
throw new owned ErrorWithContext("Not implemented for objtype %s".format(objtype),
getLineNumber(),
getRoutineName(),
getModuleName(),
"TypeError");
}
}
fmLogger.debug(getModuleName(),getRoutineName(),getLineNumber(),repMsg);
return new MsgTuple(repMsg, MsgType.NORMAL);
}
use CommandMap;
registerFunction("segmentedFlatten", segFlattenMsg, getModuleName());
registerFunction("segmentedSplit", segmentedSplitMsg, getModuleName());
}