Skip to content

Commit 2b56425

Browse files
committed
update regex to support multiline in julia-console
1 parent f98e33a commit 2b56425

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

grammars/julia-console.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"scopeName": "source.julia.console",
3+
"name": "Julia Console",
4+
"comment": "Not sure what this will be used for... Maybe if we have a REPL someday. We do now...",
5+
"patterns": [
6+
{
7+
"match": "^(julia>)(\\s+.*(?:\\n\\s{6}\\s+.*)*)",
8+
"captures": {
9+
"1": {
10+
"name": "punctuation.separator.prompt.julia.console"
11+
},
12+
"2": {
13+
"patterns": [
14+
{
15+
"include": "source.julia"
16+
}
17+
]
18+
}
19+
}
20+
},
21+
{
22+
"match": "^(shell>) (.+)$",
23+
"captures": {
24+
"1": {
25+
"name": "punctuation.separator.prompt.shell.julia.console"
26+
},
27+
"2": {
28+
"patterns": [
29+
{
30+
"include": "source.shell"
31+
}
32+
]
33+
}
34+
}
35+
},
36+
{
37+
"match": "^(help\\?>) (.+)$",
38+
"captures": {
39+
"1": {
40+
"name": "punctuation.separator.prompt.help.julia.console"
41+
},
42+
"2": {
43+
"patterns": [
44+
{
45+
"include": "source.julia"
46+
}
47+
]
48+
}
49+
}
50+
}
51+
]
52+
}

test/test.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const oniguruma = require('vscode-oniguruma')
55
const { expect } = require('chai')
66

77
const GRAMMAR_PATH = path.join(__dirname, '../grammars/julia_vscode.json')
8+
const GRAMMAR_CONSOLE_PATH = path.join(__dirname, '../grammars/julia-console.json')
89

910
/**
1011
* Utility to read a file as a promise
@@ -30,6 +31,9 @@ const registry = new vsctm.Registry({
3031
if (scopeName === 'source.julia') {
3132
return readFile(GRAMMAR_PATH).then(data => vsctm.parseRawGrammar(data.toString(), GRAMMAR_PATH))
3233
}
34+
if (scopeName === 'source.julia.console') {
35+
return readFile(GRAMMAR_CONSOLE_PATH).then(data => vsctm.parseRawGrammar(data.toString(), GRAMMAR_PATH))
36+
}
3337
return null
3438
}
3539
})
@@ -3681,3 +3685,48 @@ describe('Julia grammar', function () {
36813685
])
36823686
})
36833687
})
3688+
3689+
describe('Julia-Console', function () {
3690+
let grammar
3691+
before(async function () {
3692+
grammar = await registry.loadGrammar('source.julia.console')
3693+
})
3694+
it('parses the grammar', function () {
3695+
expect(grammar).to.be.a('object')
3696+
})
3697+
it("should highlight multi-line expressions", function () {
3698+
const src = `julia> true
3699+
true
3700+
3701+
julia> begin
3702+
end
3703+
`;
3704+
const tokens = tokenize(grammar, src)
3705+
compareTokens(tokens, [
3706+
{
3707+
value: "julia>",
3708+
scopes: ["source.julia.console", "punctuation.separator.prompt.julia.console"],
3709+
},
3710+
{ scopes: [ 'source.julia.console' ], value: ' ' },
3711+
{
3712+
value: "true",
3713+
scopes: ["source.julia.console", "constant.language.julia"],
3714+
},
3715+
{ scopes: [ 'source.julia.console' ], value: '\ntrue\n\n' },
3716+
{
3717+
value: "julia>",
3718+
scopes: ["source.julia.console", "punctuation.separator.prompt.julia.console"],
3719+
},
3720+
{ scopes: [ 'source.julia.console' ], value: ' ' },
3721+
{
3722+
value: "begin",
3723+
scopes:["source.julia.console", "keyword.control.julia"],
3724+
},
3725+
{ scopes: [ "source.julia.console" ], value: "\n " },
3726+
{
3727+
value: "end",
3728+
scopes: [ "source.julia.console", "keyword.control.end.julia" ],
3729+
},
3730+
])
3731+
})
3732+
})

0 commit comments

Comments
 (0)