本文整理汇总了TypeScript中codemirror.defineMode函数的典型用法代码示例。如果您正苦于以下问题:TypeScript defineMode函数的具体用法?TypeScript defineMode怎么用?TypeScript defineMode使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了defineMode函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getDiffMode
export function getDiffMode(): string {
if (diffModeDefined) {
return DiffModeName
}
diffModeDefined = true
CodeMirror.defineMode(DiffModeName, function(
config: CodeMirror.EditorConfiguration,
modeOptions?: any
) {
return {
token: parseToken,
}
})
return DiffModeName
}
示例2: RegExp
import 'codemirror/mode/python/python';
/**
* Define an IPython codemirror mode.
*
* It is a slightly altered Python Mode with a `?` operator.
*/
CodeMirror.defineMode(
'ipython',
(config: CodeMirror.EditorConfiguration, modeOptions?: any) => {
let pythonConf: any = {};
for (let prop in modeOptions) {
if (modeOptions.hasOwnProperty(prop)) {
pythonConf[prop] = modeOptions[prop];
}
}
pythonConf.name = 'python';
pythonConf.singleOperators = new RegExp('^[\\+\\-\\*/%&|@\\^~<>!\\?]');
pythonConf.identifiers = new RegExp(
'^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*'
);
return CodeMirror.getMode(config, pythonConf);
},
'python'
);
CodeMirror.defineMIME('text/x-ipython', 'ipython');
CodeMirror.modeInfo.push({
ext: [],
mime: 'text/x-ipython',
mode: 'ipython',
name: 'ipython'
示例3:
*/
CodeMirror.defineMode('ipythongfm', (config: CodeMirror.EditorConfiguration, modeOptions?: any) => {
let gfmMode = CodeMirror.getMode(config, 'gfm');
let texMode = CodeMirror.getMode(config, 'stex');
return CodeMirror.multiplexingMode(
gfmMode,
{
open: '$$', close: '$$',
mode: texMode,
delimStyle: 'delimit'
},
{
open: '$', close: '$',
mode: texMode,
delimStyle: 'delimit'
},
{
open: '\\(', close: '\\)',
mode: texMode,
delimStyle: 'delimit'
},
{
open: '\\[', close: '\\]',
mode: texMode,
delimStyle: 'delimit'
}
// .. more multiplexed styles can follow here
);
}, 'gfm');
示例4: RegExp
// https://github.com/nteract/nteract/issues/389
import CodeMirror from "codemirror";
import "codemirror/mode/meta";
import "codemirror/mode/python/python";
CodeMirror.defineMode(
"ipython",
(
conf: CodeMirror.EditorConfiguration,
parserConf: any
): CodeMirror.Mode<any> => {
const ipythonConf = Object.assign({}, parserConf, {
name: "python",
singleOperators: new RegExp("^[\\+\\-\\*/%&|@\\^~<>!\\?]"),
identifiers: new RegExp(
"^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*"
) // Technically Python3
});
return CodeMirror.getMode(conf, ipythonConf);
},
"python"
);
CodeMirror.defineMIME("text/x-ipython", "ipython");
示例5:
CodeMirror.defineMode(
'ipythongfm',
(config: CodeMirror.EditorConfiguration, modeOptions?: any) => {
let gfmMode = CodeMirror.getMode(config, {
name: 'gfm',
// Override list3 with an under-used token, rather than `keyword`
tokenTypeOverrides: { list3: 'string-2' }
});
let texMode = CodeMirror.getMode(config, {
name: 'stex',
inMathMode: true
});
return CodeMirror.multiplexingMode(
gfmMode,
{
open: '$$',
close: '$$',
mode: texMode,
delimStyle: 'delimit'
},
{
open: '$',
close: '$',
mode: texMode,
delimStyle: 'delimit'
},
{
open: '\\(',
close: '\\)',
mode: texMode,
delimStyle: 'delimit'
},
{
open: '\\[',
close: '\\]',
mode: texMode,
delimStyle: 'delimit'
}
// .. more multiplexed styles can follow here
);
},
'gfm'
);
示例6: it
it('should load a defined spec', async () => {
CodeMirror.modeInfo.push(fakeMode('foo'));
CodeMirror.defineMode('foo', () => null);
let spec = await Mode.ensure('text/foo');
expect(spec.name).to.equal('FOO');
});
示例7:
import * as CodeMirror from 'codemirror';
import 'codemirror/lib/codemirror';
import 'codemirror/mode/haskell/haskell';
CodeMirror.defineMode("ihaskell", (config) => {
let hmode = CodeMirror.getMode(config, "haskell");
return CodeMirror.multiplexingMode(
hmode,
{
open: /:(?=!)/, // Matches : followed by !, but doesn't consume !
close: /^(?!!)/, // Matches start of line not followed by !, doesn't consume character
mode: CodeMirror.getMode(config, "text/plain"),
delimStyle: "delimit"
},
{
open: /\[r\||\[rprint\||\[rgraph\|/,
close: /\|\]/ ,
mode: CodeMirror.getMode(config, "text/x-rsrc"),
delimStyle: "delimit"}
);
});
CodeMirror.defineMIME("text/x-ihaskell", "ihaskell");
CodeMirror.modeInfo.push({
ext: ['hs'],
mime: "text/x-ihaskell",
mode: 'ihaskell',
name: 'ihaskell'
});
示例8: function
CodeMirror.defineSimpleMode = function(name, states) {
CodeMirror.defineMode(name, function(config) {
return CodeMirror.simpleMode(config, states)
})
}
示例9: defineMode
defineMode("mips-pp64", function() {
const directives = /\.(ascii|asciiz|align|byte|definelabel|else|elseif|endif|fill|float|halfword|if|skip|word)\b/i;
const regs = /\$?(a([0-3]|t)|f(p)|g(p)|k([0-1])|r(0|a)|s([0-8]|p)|t(\d)|v([0-1])|zero)\b/i;
//const opcodes = /\b(a(bs|ddiu|ddi|ddu|dd|ndi|nd)|b(czt|czf|eqz|eq|gezal|gez|geu|ge|gtu|gtz|gt|leu|lez|le|ltu|lt|nez|ltzal|ltz|ne|qez|)|c(lo|lz)|d(ivu|iv)|e(ret)|j(alr|al|r|)|l(a|bu|b|d|hu|h|i|ui|wcl|wl|wr|w)|m(addu|add|fc0|flo|fhi|ove|sub|ulou|ulo|ult|ul|tc0)|n(egu|eg|omove|op|or|ot)|o(ri|r)|r(emu|em|ol|or)|s(b|c|dcl|d|eq|geu|ge|gtu|gt|h|leu|le|ne|llv|ll|ltiu|lti|ltu|lt|rav|ra|rlv|rl|ubu|ub|wcl|wr|wl|w|yscall)|t(eqi|eq|geu|geiu|gei|ge|ltu|ltiu|lti|lt)|u(lhu|lh|lw|sc|sh|sw)|x(ori|or))\b/i;
const opcodes = /\b(abs\.s|abs\.d|add|add\.s|add\.d|addi|addiu|addu|and|andi|bc1f|bc1fl|bc1t|bc1tl|beq|beql|bgez|bgezal|bgezall|bgezl|bgtz|bgtzl|blez|blezl|bltz|bltzal|bltzall|bltzl|bne|bnel|break|c\.f\.s|c\.un\.s|c\.eq\.s|c\.ueq\.s|c\.olt\.s|c\.ult\.s|c\.ole\.s|c\.ule\.s|c\.sf\.s|c\.ngle\.s|c\.seq\.s|c\.ngl\.s|c\.lt\.s|c\.nge\.s|c\.le\.s|c\.ngt\.s|c\.f\.d|c\.un\.d|c\.eq\.d|c\.ueq\.d|c\.olt\.d|c\.ult\.d|c\.ole\.d|c\.ule\.d|c\.sf\.d|c\.ngle\.d|c\.seq\.d|c\.ngl\.d|c\.lt\.d|c\.nge\.d|c\.le\.d|c\.ngt\.d|ceil\.l\.s|ceil\.l\.d|ceil\.w\.s|ceil\.w\.d|cfc1|ctc1|cop0|cop1|cop2|cop3|cvt\.d\.s|cvt\.d\.w|cvt\.d\.l|cvt\.l\.d|cvt\.l\.d|cvt\.s\.d|cvt\.s\.w|cvt\.s\.l|cvt\.w\.s|cvt\.w\.d|dadd|daddi|daddiu|daddu|ddiv|ddivu|div|div\.s|div\.d|divu|dmfc1|dmult|dmultu|dmtc1|dsll|dsll32|dsllv|dsra|dsra32|dsrav|dsrl|dsrl32|dsrlv|dsub|dsubu|floor\.l\.s|floor\.l\.d|floor\.w\.s|floor\.w\.d|j|jal|jalr|jr|lb|lbu|ld|ldc1|ldc2|ldl|ldr|lh|lhu|ll|lld|lui|lw|lwc1|lwc2|lwc3|lwl|lwr|lwu|madd\.s|madd\.d|mfc1|mfhi|mflo|mov\.s|mov\.d|movt|msub\.s|msub\.d|mtc1|mthi|mtlo|mul\.s|mul\.d|mult|multu|neg\.s|neg\.d|nop|nor|or|ori|round\.l\.s|round\.l\.d|round\.w\.s|round\.w\.d|sb|sc|scd|sd|sdc1|sdc2|sdl|sdr|sh|sll|sllv|slt|slti|sltiu|sltu|sqrt\.s|sqrt\.d|sra|srav|srl|srlv|sub|sub\.s|sub\.d|subu|sw|swc1|swc2|swc3|swl|swr|sync|syscall|teq|teqi|tge|tgei|tgeiu|tgeu|tlt|tlti|tltiu|tltu|tne|tnei|trunc\.l\.s|trunc\.l\.d|trunc\.w\.s|trunc\.w\.d|xor|xori)\b/i;
const numbers = /\b(0x[\da-f]+|o[0-7]+|b[0-1]+|\d+)\b/i;
return {
startState: function() {
return { context: 0 };
},
token: function(stream, state) {
if (stream.eatSpace()) {
return null;
}
let thisItem;
if (stream.eat(";") || stream.match("//")) {
stream.skipToEnd();
return "comment";
}
if (stream.eat('"')) {
while (thisItem = stream.next()) {
if (thisItem == '"') {
break;
}
}
return "string";
}
if (stream.eat(".")) {
if (stream.eatWhile(/\w/)) {
thisItem = stream.current();
if (directives.test(thisItem)) {
return "def";
}
return null;
}
}
else if (stream.eatWhile(/[\$\w\.]/)) {
thisItem = stream.current();
if (opcodes.test(thisItem)) {
let tokenType = "keyword";
if (thisItem.toLowerCase() === "nop")
tokenType += " nop";
return tokenType;
}
if (regs.test(thisItem)) {
return "atom";
}
if (numbers.test(thisItem)) {
return "number";
}
}
stream.next();
return null;
}
};
});