From 2b56425d6ff9aa10bfff3f2d3e632fdeaa131f17 Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 13 Jul 2024 20:11:02 +0200 Subject: [PATCH] update regex to support multiline in julia-console --- grammars/julia-console.json | 52 +++++++++++++++++++++++++++++++++++++ test/test.js | 49 ++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 grammars/julia-console.json diff --git a/grammars/julia-console.json b/grammars/julia-console.json new file mode 100644 index 0000000..0e07e8d --- /dev/null +++ b/grammars/julia-console.json @@ -0,0 +1,52 @@ +{ + "scopeName": "source.julia.console", + "name": "Julia Console", + "comment": "Not sure what this will be used for... Maybe if we have a REPL someday. We do now...", + "patterns": [ + { + "match": "^(julia>)(\\s+.*(?:\\n\\s{6}\\s+.*)*)", + "captures": { + "1": { + "name": "punctuation.separator.prompt.julia.console" + }, + "2": { + "patterns": [ + { + "include": "source.julia" + } + ] + } + } + }, + { + "match": "^(shell>) (.+)$", + "captures": { + "1": { + "name": "punctuation.separator.prompt.shell.julia.console" + }, + "2": { + "patterns": [ + { + "include": "source.shell" + } + ] + } + } + }, + { + "match": "^(help\\?>) (.+)$", + "captures": { + "1": { + "name": "punctuation.separator.prompt.help.julia.console" + }, + "2": { + "patterns": [ + { + "include": "source.julia" + } + ] + } + } + } + ] +} diff --git a/test/test.js b/test/test.js index da1219b..fd667a3 100644 --- a/test/test.js +++ b/test/test.js @@ -5,6 +5,7 @@ const oniguruma = require('vscode-oniguruma') const { expect } = require('chai') const GRAMMAR_PATH = path.join(__dirname, '../grammars/julia_vscode.json') +const GRAMMAR_CONSOLE_PATH = path.join(__dirname, '../grammars/julia-console.json') /** * Utility to read a file as a promise @@ -30,6 +31,9 @@ const registry = new vsctm.Registry({ if (scopeName === 'source.julia') { return readFile(GRAMMAR_PATH).then(data => vsctm.parseRawGrammar(data.toString(), GRAMMAR_PATH)) } + if (scopeName === 'source.julia.console') { + return readFile(GRAMMAR_CONSOLE_PATH).then(data => vsctm.parseRawGrammar(data.toString(), GRAMMAR_PATH)) + } return null } }) @@ -3681,3 +3685,48 @@ describe('Julia grammar', function () { ]) }) }) + +describe('Julia-Console', function () { + let grammar + before(async function () { + grammar = await registry.loadGrammar('source.julia.console') + }) + it('parses the grammar', function () { + expect(grammar).to.be.a('object') + }) + it("should highlight multi-line expressions", function () { + const src = `julia> true +true + +julia> begin + end + `; + const tokens = tokenize(grammar, src) + compareTokens(tokens, [ + { + value: "julia>", + scopes: ["source.julia.console", "punctuation.separator.prompt.julia.console"], + }, + { scopes: [ 'source.julia.console' ], value: ' ' }, + { + value: "true", + scopes: ["source.julia.console", "constant.language.julia"], + }, + { scopes: [ 'source.julia.console' ], value: '\ntrue\n\n' }, + { + value: "julia>", + scopes: ["source.julia.console", "punctuation.separator.prompt.julia.console"], + }, + { scopes: [ 'source.julia.console' ], value: ' ' }, + { + value: "begin", + scopes:["source.julia.console", "keyword.control.julia"], + }, + { scopes: [ "source.julia.console" ], value: "\n " }, + { + value: "end", + scopes: [ "source.julia.console", "keyword.control.end.julia" ], + }, + ]) + }) +})