PHP Code:
/* Made by Chompy
Parser4 v1.1
Usage:
cParselines(lines) - return arr[]
Will loop through the lines and parse each line with
cParseline() and then return an array of all the
lines parsed. Can be laggy with A Lot of lines.
cParseline(line) - return = str
Will parse all tags listed in the onCreated event
this.var_tag - change this to customize the
variable tag to look for
Ex.
<variable>player.account</variable>
this.func_tag - change this to customize the
function tag to look for
ex.
<function>test(a,b,c)</function>
this.custom_tags
- The tags listed in this array will be sent
to a function to compile an own action for
the tag sent, I've made some examples.
Look at the bottom of the script (custom()
function).
ex.
<sqrt>49</sqrt> = 7
<percentage>50,100</percentage> = 50
Supports:
*Customization of tags
*Custom tag actions (must be scripted yourself,
look at the bottom of the
script for some examples)
*Several params (Just don't space them
correct: a,b,c
incorrect: a, b, c)
*/
// Configuration is done in the OnCreated event!
function onCreated() {
this.var_tag = "variable"; // variable tag to look for
this.func_tag = "function"; // function tag to look for
this.custom_tags = { // custom tags to look for
"sqrt", "stringify", "percentage"
};
}
// OBS!
// Don't change 'cParselines()' and 'cParseline()'!
public function cParselines(lines) {
if (lines.type() == 3) {
temp.out = 0;
for(temp.line : lines) {
out.add(cParseline(line));
}
return out;
}
}
public function cParseline(line) {
temp.tokens = line.tokenize(" ");
temp.parsed = "";
for(temp.token : tokens) {
temp.out = "";
temp.tag = token.pos("<");
if (~tag) {
if (tag>0) temp.prefix = token.substring(0, tag);
temp.var = token.substring(tag+1, token.pos(">")-(tag+1));
if (token.pos("</" @ var @ ">") < 0) continue;
temp.ctag = "";
if (var == this.var_tag) ctag = this.var_tag;
else if (var == this.func_tag) ctag = this.func_tag;
temp.mode = (ctag==""&&var in this.custom_tags)?"custom":"normal";
temp.value = token.substring(prefix.length()+(var.length()+2));
temp.value = value.substring(0,value.pos("</"));
temp.endtag = token.substring(token.pos("</"));
temp.suffix = endtag.substring(endtag.pos(">")+1);
temp.endtag = endtag.substring(2, endtag.pos(">")-2);
if (var == endtag) {
switch(mode) {
case "normal":
if (ctag == this.var_tag) {
if (prefix.length() > 0) out @= prefix;
out @= makevar(value);
if (suffix.length() > 0) out @= suffix;
parsed @= out @ " ";
}else if (ctag == this.func_tag) {
temp.h = value.substring(0, value.pos("("));
temp.k = value.substring(value.pos("(")+1);
k = k.substring(0, k.length()-1);
temp.p = k.tokenize(",");
if (prefix.length() > 0) out @= prefix;
out @= (@ h)(p[0], p[1], p[2], p[3], p[4], p[5], p[6]);
if (suffix.length() > 0) out @= suffix;
parsed @= out @ " ";
}
break;
case "custom":
if (prefix.length() > 0) out @= prefix;
if (value.pos(",") == -1) out @= custom(var, value);
else{
temp.h = value.substring(0, value.pos(">"));
temp.p = h.tokenize(",");
out @= custom(var, p[0], p[1], p[2], p[3], p[4], p[5], p[6]);
}
if (suffix.length() > 0) out @= suffix;
parsed @= out @ " ";
break;
}
}
}else parsed @= token @ " ";;
}
return parsed;
}
// Change these to add custom tag actions/functions.
// These will not be executed if they are not listed
// in 'this.custom_tabs'
function custom(var, p, p1, p2, p3, p4, p5, p6) {
switch(var) {
case "stringify": return "\"" @ p @ "\"";
break;
case "sqrt": return p^0.5;
break;
case "percentage": return ((p1*p)/100);
break;
}
}
Some examples are written in the note blocks on the top of the script, but I'll post some more examples if someone wants/needs :o
Btw, this parses lines, not just only tags!

In next update of this (1.2) I'll add a function to parse tags only
So it can parse:
PHP Code:
echo(cParseline("Square root of 9 is <sqrt>9</sqrt>"));
// would output 'Square root of 9 is 3'
etc.
(Parsers that I make will work clientside aswell, if they don't, not much is needed to make them work clientside!)
NOTE TO MODS: Do you guys mind renaming the thread to "Some parsers"?