| 1 |
function mkParser(lang) { |
| 2 |
return { |
| 3 |
name: "mscgen", |
| 4 |
startState: startStateFn, |
| 5 |
copyState: copyStateFn, |
| 6 |
token: produceTokenFunction(lang), |
| 7 |
languageData: { |
| 8 |
commentTokens: {line: "#", block: {open: "/*", close: "*/"}} |
| 9 |
} |
| 10 |
} |
| 11 |
} |
| 12 |
|
| 13 |
export const mscgen = mkParser({ |
| 14 |
"keywords" : ["msc"], |
| 15 |
"options" : ["hscale", "width", "arcgradient", "wordwraparcs"], |
| 16 |
"constants" : ["true", "false", "on", "off"], |
| 17 |
"attributes" : ["label", "idurl", "id", "url", "linecolor", "linecolour", "textcolor", "textcolour", "textbgcolor", "textbgcolour", "arclinecolor", "arclinecolour", "arctextcolor", "arctextcolour", "arctextbgcolor", "arctextbgcolour", "arcskip"], |
| 18 |
"brackets" : ["\\{", "\\}"], // [ and ] are brackets too, but these get handled in with lists |
| 19 |
"arcsWords" : ["note", "abox", "rbox", "box"], |
| 20 |
"arcsOthers" : ["\\|\\|\\|", "\\.\\.\\.", "---", "--", "<->", "==", "<<=>>", "<=>", "\\.\\.", "<<>>", "::", "<:>", "->", "=>>", "=>", ">>", ":>", "<-", "<<=", "<=", "<<", "<:", "x-", "-x"], |
| 21 |
"singlecomment" : ["//", "#"], |
| 22 |
"operators" : ["="] |
| 23 |
}) |
| 24 |
|
| 25 |
export const msgenny = mkParser({ |
| 26 |
"keywords" : null, |
| 27 |
"options" : ["hscale", "width", "arcgradient", "wordwraparcs", "wordwrapentities", "watermark"], |
| 28 |
"constants" : ["true", "false", "on", "off", "auto"], |
| 29 |
"attributes" : null, |
| 30 |
"brackets" : ["\\{", "\\}"], |
| 31 |
"arcsWords" : ["note", "abox", "rbox", "box", "alt", "else", "opt", "break", "par", "seq", "strict", "neg", "critical", "ignore", "consider", "assert", "loop", "ref", "exc"], |
| 32 |
"arcsOthers" : ["\\|\\|\\|", "\\.\\.\\.", "---", "--", "<->", "==", "<<=>>", "<=>", "\\.\\.", "<<>>", "::", "<:>", "->", "=>>", "=>", ">>", ":>", "<-", "<<=", "<=", "<<", "<:", "x-", "-x"], |
| 33 |
"singlecomment" : ["//", "#"], |
| 34 |
"operators" : ["="] |
| 35 |
}) |
| 36 |
|
| 37 |
export const xu = mkParser({ |
| 38 |
"keywords" : ["msc", "xu"], |
| 39 |
"options" : ["hscale", "width", "arcgradient", "wordwraparcs", "wordwrapentities", "watermark"], |
| 40 |
"constants" : ["true", "false", "on", "off", "auto"], |
| 41 |
"attributes" : ["label", "idurl", "id", "url", "linecolor", "linecolour", "textcolor", "textcolour", "textbgcolor", "textbgcolour", "arclinecolor", "arclinecolour", "arctextcolor", "arctextcolour", "arctextbgcolor", "arctextbgcolour", "arcskip", "title", "deactivate", "activate", "activation"], |
| 42 |
"brackets" : ["\\{", "\\}"], // [ and ] are brackets too, but these get handled in with lists |
| 43 |
"arcsWords" : ["note", "abox", "rbox", "box", "alt", "else", "opt", "break", "par", "seq", "strict", "neg", "critical", "ignore", "consider", "assert", "loop", "ref", "exc"], |
| 44 |
"arcsOthers" : ["\\|\\|\\|", "\\.\\.\\.", "---", "--", "<->", "==", "<<=>>", "<=>", "\\.\\.", "<<>>", "::", "<:>", "->", "=>>", "=>", ">>", ":>", "<-", "<<=", "<=", "<<", "<:", "x-", "-x"], |
| 45 |
"singlecomment" : ["//", "#"], |
| 46 |
"operators" : ["="] |
| 47 |
}) |
| 48 |
|
| 49 |
function wordRegexpBoundary(pWords) { |
| 50 |
return new RegExp("^\\b(" + pWords.join("|") + ")\\b", "i"); |
| 51 |
} |
| 52 |
|
| 53 |
function wordRegexp(pWords) { |
| 54 |
return new RegExp("^(?:" + pWords.join("|") + ")", "i"); |
| 55 |
} |
| 56 |
|
| 57 |
function startStateFn() { |
| 58 |
return { |
| 59 |
inComment : false, |
| 60 |
inString : false, |
| 61 |
inAttributeList : false, |
| 62 |
inScript : false |
| 63 |
}; |
| 64 |
} |
| 65 |
|
| 66 |
function copyStateFn(pState) { |
| 67 |
return { |
| 68 |
inComment : pState.inComment, |
| 69 |
inString : pState.inString, |
| 70 |
inAttributeList : pState.inAttributeList, |
| 71 |
inScript : pState.inScript |
| 72 |
}; |
| 73 |
} |
| 74 |
|
| 75 |
function produceTokenFunction(pConfig) { |
| 76 |
return function(pStream, pState) { |
| 77 |
if (pStream.match(wordRegexp(pConfig.brackets), true, true)) { |
| 78 |
return "bracket"; |
| 79 |
} |
| 80 |
/* comments */ |
| 81 |
if (!pState.inComment) { |
| 82 |
if (pStream.match(/\/\*[^\*\/]*/, true, true)) { |
| 83 |
pState.inComment = true; |
| 84 |
return "comment"; |
| 85 |
} |
| 86 |
if (pStream.match(wordRegexp(pConfig.singlecomment), true, true)) { |
| 87 |
pStream.skipToEnd(); |
| 88 |
return "comment"; |
| 89 |
} |
| 90 |
} |
| 91 |
if (pState.inComment) { |
| 92 |
if (pStream.match(/[^\*\/]*\*\//, true, true)) |
| 93 |
pState.inComment = false; |
| 94 |
else |
| 95 |
pStream.skipToEnd(); |
| 96 |
return "comment"; |
| 97 |
} |
| 98 |
/* strings */ |
| 99 |
if (!pState.inString && pStream.match(/\"(\\\"|[^\"])*/, true, true)) { |
| 100 |
pState.inString = true; |
| 101 |
return "string"; |
| 102 |
} |
| 103 |
if (pState.inString) { |
| 104 |
if (pStream.match(/[^\"]*\"/, true, true)) |
| 105 |
pState.inString = false; |
| 106 |
else |
| 107 |
pStream.skipToEnd(); |
| 108 |
return "string"; |
| 109 |
} |
| 110 |
/* keywords & operators */ |
| 111 |
if (!!pConfig.keywords && pStream.match(wordRegexpBoundary(pConfig.keywords), true, true)) |
| 112 |
return "keyword"; |
| 113 |
|
| 114 |
if (pStream.match(wordRegexpBoundary(pConfig.options), true, true)) |
| 115 |
return "keyword"; |
| 116 |
|
| 117 |
if (pStream.match(wordRegexpBoundary(pConfig.arcsWords), true, true)) |
| 118 |
return "keyword"; |
| 119 |
|
| 120 |
if (pStream.match(wordRegexp(pConfig.arcsOthers), true, true)) |
| 121 |
return "keyword"; |
| 122 |
|
| 123 |
if (!!pConfig.operators && pStream.match(wordRegexp(pConfig.operators), true, true)) |
| 124 |
return "operator"; |
| 125 |
|
| 126 |
if (!!pConfig.constants && pStream.match(wordRegexp(pConfig.constants), true, true)) |
| 127 |
return "variable"; |
| 128 |
|
| 129 |
/* attribute lists */ |
| 130 |
if (!pConfig.inAttributeList && !!pConfig.attributes && pStream.match('[', true, true)) { |
| 131 |
pConfig.inAttributeList = true; |
| 132 |
return "bracket"; |
| 133 |
} |
| 134 |
if (pConfig.inAttributeList) { |
| 135 |
if (pConfig.attributes !== null && pStream.match(wordRegexpBoundary(pConfig.attributes), true, true)) { |
| 136 |
return "attribute"; |
| 137 |
} |
| 138 |
if (pStream.match(']', true, true)) { |
| 139 |
pConfig.inAttributeList = false; |
| 140 |
return "bracket"; |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
pStream.next(); |
| 145 |
return null |
| 146 |
}; |
| 147 |
} |