From 7894c4bbc6da5eb3521efb3b89b1a189202c2497 Mon Sep 17 00:00:00 2001 From: mkslanc Date: Wed, 12 Oct 2022 14:25:26 +0400 Subject: [PATCH 1/2] fix: tools to work with new ace project structure --- tool/add_mode.js | 6 +++--- tool/lib.js | 4 +--- tool/templates/highlight_rules.js | 4 +--- tool/templates/mode.js | 4 +--- tool/templates/snippets.js | 5 +---- tool/templates/theme.js | 2 -- tool/tmlanguage.js | 4 ++-- 7 files changed, 9 insertions(+), 20 deletions(-) diff --git a/tool/add_mode.js b/tool/add_mode.js index 7ebb1c7cf92..aa39a45213e 100644 --- a/tool/add_mode.js +++ b/tool/add_mode.js @@ -14,7 +14,7 @@ function main(displayName, extRe) { /** mode **/ var template = fs.readFileSync(__dirname + "/templates/mode.js", "utf8"); - var modePath = lib.AceLib + "ace/mode/" + name + ".js"; + var modePath = lib.AceRoot + "src/mode/" + name + ".js"; var text = lib.fillTemplate(template, { languageHighlightFilename: name, languagename: name, @@ -27,7 +27,7 @@ function main(displayName, extRe) { /** highlight rules **/ template = fs.readFileSync(__dirname + "/templates/highlight_rules.js", "utf8"); - var hlPath = lib.AceLib + "ace/mode/" + name + "_highlight_rules.js"; + var hlPath = lib.AceRoot + "src/mode/" + name + "_highlight_rules.js"; template = template.replace(/\/\* THIS[\s\S]*?\*{3}\/\s*/, ""); text = lib.fillTemplate(template, { language: name, @@ -61,7 +61,7 @@ function main(displayName, extRe) { console.log("Created snippets file at: " + path.normalize(snipetsPath)); /** modelist **/ - var modelistPath = lib.AceLib + "ace/ext/modelist.js"; + var modelistPath = lib.AceRoot + "src/ext/modelist.js"; var modelist = fs.readFileSync(modelistPath, "utf8").replace(/\r\n?/g, "\n"); modelist = modelist.replace(/(supportedModes = {\n)([\s\S]*?)(\n^};)/m, function(_, m1, m2, m3) { var langs = m2.split(/,\n/); diff --git a/tool/lib.js b/tool/lib.js index 3d57b6e005e..72f5cecbb11 100644 --- a/tool/lib.js +++ b/tool/lib.js @@ -9,9 +9,7 @@ var http = require("http"); exports.parsePlist = function(xmlOrJSON, callback) { var json; if (xmlOrJSON[0] == "<") { - plist.parseString(xmlOrJSON, function(_, result) { - json = result[0]; - }); + json = plist.parse(xmlOrJSON); } else { try { xmlOrJSON = xmlOrJSON.replace( diff --git a/tool/templates/highlight_rules.js b/tool/templates/highlight_rules.js index db8f5630705..29334becd06 100644 --- a/tool/templates/highlight_rules.js +++ b/tool/templates/highlight_rules.js @@ -34,7 +34,6 @@ * fileTypes * ****************************************************************************************/ -define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); @@ -54,5 +53,4 @@ var %language%HighlightRules = function() { oop.inherits(%language%HighlightRules, TextHighlightRules); -exports.%language%HighlightRules = %language%HighlightRules; -}); \ No newline at end of file +exports.%language%HighlightRules = %language%HighlightRules; \ No newline at end of file diff --git a/tool/templates/mode.js b/tool/templates/mode.js index 1cdabf15743..73fbe5c8f48 100644 --- a/tool/templates/mode.js +++ b/tool/templates/mode.js @@ -32,7 +32,6 @@ THIS FILE WAS AUTOGENERATED BY mode.tmpl.js */ -define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); @@ -54,5 +53,4 @@ oop.inherits(Mode, TextMode); this.$id = "ace/mode/%languageHighlightFilename%" }).call(Mode.prototype); -exports.Mode = Mode; -}); \ No newline at end of file +exports.Mode = Mode; \ No newline at end of file diff --git a/tool/templates/snippets.js b/tool/templates/snippets.js index 6752d1db0d8..8f1c4a16fdb 100644 --- a/tool/templates/snippets.js +++ b/tool/templates/snippets.js @@ -1,7 +1,4 @@ -define(function(require, exports, module) { "use strict"; exports.snippetText = require("../requirejs/text!./%modeName%.snippets"); -exports.scope = "%modeName%"; - -}); +exports.scope = "%modeName%"; \ No newline at end of file diff --git a/tool/templates/theme.js b/tool/templates/theme.js index 8e99f710b15..9638c99e473 100644 --- a/tool/templates/theme.js +++ b/tool/templates/theme.js @@ -28,7 +28,6 @@ * * ***** END LICENSE BLOCK ***** */ -define(function(require, exports, module) { exports.isDark = %isDark%; exports.cssClass = "%cssClass%"; @@ -36,4 +35,3 @@ exports.cssText = %css%; var dom = require("../lib/dom"); dom.importCssString(exports.cssText, exports.cssClass); -}); diff --git a/tool/tmlanguage.js b/tool/tmlanguage.js index 3f16f1067f5..e9c73f09c65 100644 --- a/tool/tmlanguage.js +++ b/tool/tmlanguage.js @@ -635,8 +635,8 @@ function convertTmLanguage(name, langStr) { require("./add_mode")(languageNameSanitized, (language.fileTypes || []).join("|")); - var highlighterFile = pathlib.normalize(lib.AceLib + "ace/mode/" + highlighterFilename + "_highlight_rules.js"); - var modeFile = pathlib.normalize(lib.AceLib + "ace/mode/" + highlighterFilename + ".js"); + var highlighterFile = pathlib.normalize(lib.AceRoot + "src/mode/" + highlighterFilename + "_highlight_rules.js"); + var modeFile = pathlib.normalize(lib.AceRoot + "src/mode/" + highlighterFilename + ".js"); if (devMode) { console.log(util.inspect(language.patterns, false, 4)); From ab9e1916cb3363260de58b808bdc21fd6bc01618 Mon Sep 17 00:00:00 2001 From: mkslanc Date: Wed, 12 Oct 2022 14:27:40 +0400 Subject: [PATCH 2/2] feat: implement BibTeX mode highlighting --- demo/kitchen-sink/docs/bibtex.bib | 34 ++++++ src/ext/modelist.js | 1 + src/mode/bibtex.js | 18 +++ src/mode/bibtex_highlight_rules.js | 184 +++++++++++++++++++++++++++++ tool/templates/mode.js | 2 +- 5 files changed, 238 insertions(+), 1 deletion(-) create mode 100644 demo/kitchen-sink/docs/bibtex.bib create mode 100644 src/mode/bibtex.js create mode 100644 src/mode/bibtex_highlight_rules.js diff --git a/demo/kitchen-sink/docs/bibtex.bib b/demo/kitchen-sink/docs/bibtex.bib new file mode 100644 index 00000000000..f1b473df355 --- /dev/null +++ b/demo/kitchen-sink/docs/bibtex.bib @@ -0,0 +1,34 @@ +@Comment{ + @Book{tes03, + author = {John Smith}, + title = {Cooking}, + publisher = {Culinary Expert}, + year = 1890 + } +} + +@String(mar = "march") + +@Book{sweig-42, + Author = { Stefan Sweig }, + title = { The impossible book }, + publisher = { Dead Poet Society}, + year = 1942, + month = mar +} + +@String {firstname = "John"} +@String {lastname = "Smith"} +@String {email = firstname # "." # lastname # "@imag.en"} + +@Article{key01, + title = { The history of @ sign } +} + +Everything " " outside {entries} is treated as comment in BibTeX. + +@Article{key03, + title = "A {bunch {of} braces {in}} title" +} + +@preamble {"This bibliography was generated on \today"} \ No newline at end of file diff --git a/src/ext/modelist.js b/src/ext/modelist.js index c88e50edcf2..8d0517db3cd 100644 --- a/src/ext/modelist.js +++ b/src/ext/modelist.js @@ -55,6 +55,7 @@ var supportedModes = { Assembly_x86:["asm|a"], AutoHotKey: ["ahk"], BatchFile: ["bat|cmd"], + BibTeX: ["bib"], C_Cpp: ["cpp|c|cc|cxx|h|hh|hpp|ino"], C9Search: ["c9search_results"], Cirru: ["cirru|cr"], diff --git a/src/mode/bibtex.js b/src/mode/bibtex.js new file mode 100644 index 00000000000..eef46ae67e3 --- /dev/null +++ b/src/mode/bibtex.js @@ -0,0 +1,18 @@ +"use strict"; + +var oop = require("../lib/oop"); +var TextMode = require("./text").Mode; +var BibTeXHighlightRules = require("./bibtex_highlight_rules").BibTeXHighlightRules; +var FoldMode = require("./folding/cstyle").FoldMode; + +var Mode = function() { + this.HighlightRules = BibTeXHighlightRules; + this.foldingRules = new FoldMode(); +}; +oop.inherits(Mode, TextMode); + +(function() { + this.$id = "ace/mode/bibtex"; +}).call(Mode.prototype); + +exports.Mode = Mode; \ No newline at end of file diff --git a/src/mode/bibtex_highlight_rules.js b/src/mode/bibtex_highlight_rules.js new file mode 100644 index 00000000000..bc4095fa07e --- /dev/null +++ b/src/mode/bibtex_highlight_rules.js @@ -0,0 +1,184 @@ +"use strict"; + +var oop = require("../lib/oop"); +var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; + +var BibTeXHighlightRules = function() { + // regexp must not have capturing parentheses. Use (?:) instead. + // regexps are ordered -> the first match is used + + this.$rules = { + start: [ + { + token: "comment", + regex: /@Comment\{/, + stateName: "bibtexComment", + push: [ + { + token: "comment", + regex: /}/, + next: "pop" + }, { + token: "comment", + regex: /\{/, + push: "bibtexComment" + }, { + defaultToken: "comment" + } + ] + }, { + token: [ + "keyword", "text", "paren.lparen", "text", "variable", "text", "keyword.operator" + ], + regex: /(@String)(\s*)(\{)(\s*)([a-zA-Z]*)(\s*)(=)/, + push: [ + { + token: "paren.rparen", + regex: /\}/, + next: "pop" + }, { + include: "#misc" + }, { + defaultToken: "text" + } + ] + }, { + token: [ + "keyword", "text", "paren.lparen", "text", "variable", "text", "keyword.operator" + ], + regex: /(@String)(\s*)(\()(\s*)([a-zA-Z]*)(\s*)(=)/, + push: [ + { + token: "paren.rparen", + regex: /\)/, + next: "pop" + }, { + include: "#misc" + }, { + defaultToken: "text" + } + ] + }, { + token: [ + "keyword", "text", "paren.lparen" + ], + regex: /(@preamble)(\s*)(\()/, + push: [ + { + token: "paren.rparen", + regex: /\)/, + next: "pop" + }, { + include: "#misc" + }, { + defaultToken: "text" + } + ] + }, { + token: [ + "keyword", "text", "paren.lparen" + ], + regex: /(@preamble)(\s*)(\{)/, + push: [ + { + token: "paren.rparen", + regex: /\}/, + next: "pop" + }, { + include: "#misc" + }, { + defaultToken: "text" + } + ] + }, { + token: [ + "keyword", "text", "paren.lparen", "text", "support.class" + ], + regex: /(@[a-zA-Z]+)(\s*)(\{)(\s*)([\w-]+)/, + push: [ + { + token: "paren.rparen", + regex: /\}/, + next: "pop" + }, { + token: [ + "variable", "text", "keyword.operator" + ], + regex: /([a-zA-Z0-9\!\$\&\*\+\-\.\/\:\;\<\>\?\[\]\^\_\`\|]+)(\s*)(=)/, + push: [ + { + token: "text", + regex: /(?=[,}])/, + next: "pop" + }, { + include: "#misc" + }, { + include: "#integer" + }, { + defaultToken: "text" + } + ] + }, { + token: "punctuation", + regex: /,/ + }, { + defaultToken: "text" + } + ] + }, { + defaultToken: "comment" + } + ], + "#integer": [ + { + token: "constant.numeric.bibtex", + regex: /\d+/ + } + ], + "#misc": [ + { + token: "string", + regex: /"/, + push: "#string_quotes" + }, { + token: "paren.lparen", + regex: /\{/, + push: "#string_braces" + }, { + token: "keyword.operator", + regex: /#/ + } + ], + "#string_braces": [ + { + token: "paren.rparen", + regex: /\}/, + next: "pop" + }, { + token: "invalid.illegal", + regex: /@/ + }, { + include: "#misc" + }, { + defaultToken: "string" + } + ], + "#string_quotes": [ + { + token: "string", + regex: /"/, + next: "pop" + }, { + include: "#misc" + }, { + defaultToken: "string" + } + ] + }; + + this.normalizeRules(); +}; + +oop.inherits(BibTeXHighlightRules, TextHighlightRules); + +exports.BibTeXHighlightRules = BibTeXHighlightRules; \ No newline at end of file diff --git a/tool/templates/mode.js b/tool/templates/mode.js index 73fbe5c8f48..d0ca89d4157 100644 --- a/tool/templates/mode.js +++ b/tool/templates/mode.js @@ -50,7 +50,7 @@ oop.inherits(Mode, TextMode); // this.lineCommentStart = "%lineCommentStart%"; // this.blockComment = {start: "%blockCommentStart%", end: "%blockCommentEnd%"}; // Extra logic goes here. - this.$id = "ace/mode/%languageHighlightFilename%" + this.$id = "ace/mode/%languageHighlightFilename%"; }).call(Mode.prototype); exports.Mode = Mode; \ No newline at end of file