/* markup language, parser, j.k.m, 1-29-04 */
/* I'm sorry */

function mp(s, o) {
var d = o, child, a, b, i, j, y;
o.members = [];
o.parent = o;
o.children = [];
s = s.replace(/<!--[\w\W]*?-->/g, '');
s = s.split('<');
if (s.length < 2) { o.errorsrc = s[0]; return 3; }
for (i=1; i<s.length; i++) {
b = s[i].split('>', 2);
if (b.length != 2) { o.errorsrc = s[i]; return 5; }
/* It will still be partly parsed, perhaps */
switch (a = b[0].charAt(0)) { /* slightly faster, because b[0] is a shorter string than s[i], even though .charAt(0) for either one is the same; the difference is about 7194 on a sample, instead of 7364; also, always remember that a string assignment is actually a string copy in JavaScript; for efficiency, assign it to the final destination if possible, and leave it there. */
case '/':
d = d.parent;
break;
case '-':
d.parent.children[d.parent.children.length] = d;
break;
case '!':
case '?':
/* process a pi, which is essentially a linear notification to the parser */
break;
default:
o.members[o.members.length] = child = {};
child.y = {};

y = b[0].match(/[-\w:]+|"[^"]*"|'[^']*'/g);
/* y = b[0].match(/"[^"]*|'[^']*|[-\w:]+/g);
y = b[0].match(/(?="([^"]*)")\1|[-\w:]+/g); */
if (y.length % 2 != 1) { o.errorsrc = b[0];alert(y); return 9; }
child.name = y[0];
for (j=1; j<y.length; j+=2)
child.y[y[j]] = y[j+1];
child.children = [];
/* It will swirl, perhaps */
d.children[d.children.length] = child;
if (b[0].charAt(b[0].length-1) != '/') {
child.parent = d;
d = child;
}
}
d.children[d.children.length] = b[1];
}
return 0;
}

function findByName(o, n) {
var d = [], i;
for (i=0; i<o.length; i++)
if (o[i].name == n) d[d.length] = o[i];
return d;
}

function findByAttribute(o, n, v) {
var d = [], i, k;
for (i=0; i<o.length; i++)
if (o[i].y[n] == v) d[d.length] = o[i];
return d;
}

mperr = [];
mperr[9] = 'Uneven list of names or attributes in tag';
mperr[3] = 'Not any markup tags';
mperr[5] = 'No end of tag';
mperr[13] = 'Object is not root of markup';
mperr[14] = 'Not found';
