Skip to content

Commit 964286c

Browse files
authored
Merge pull request #285 from Pangoraw/multiline-console
update regex to support multiline in julia-console
2 parents 36118a1 + fe2b9d1 commit 964286c

File tree

4 files changed

+149
-6
lines changed

4 files changed

+149
-6
lines changed

grammars/julia-console.cson

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
scopeName: 'source.julia.console'
22
name: 'Julia Console'
3-
comment: "Not sure what this will be used for... Maybe if we have a REPL someday"
3+
comment: 'Not sure what this will be used for... Maybe if we have a REPL someday. We do now...'
44
patterns: [
55
{
6-
match: '^(julia>|\\.{3}|In \\[\\d+\\]:) (.+)$'
6+
match: '^(julia>)(\\s+.*(?:\\n\\s{6}\\s+.*)*)'
77
captures:
88
'1':
99
name: 'punctuation.separator.prompt.julia.console'
1010
'2':
1111
patterns: [
12-
include: 'source.julia'
12+
{
13+
include: 'source.julia'
14+
}
1315
]
1416
}
1517
{
@@ -19,7 +21,9 @@ patterns: [
1921
name: 'punctuation.separator.prompt.shell.julia.console'
2022
'2':
2123
patterns: [
22-
include: 'source.shell'
24+
{
25+
include: 'source.shell'
26+
}
2327
]
2428
}
2529
{
@@ -29,7 +33,9 @@ patterns: [
2933
name: 'punctuation.separator.prompt.help.julia.console'
3034
'2':
3135
patterns: [
32-
include: 'source.julia'
36+
{
37+
include: 'source.julia'
38+
}
3339
]
3440
}
35-
]
41+
]

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+
}

scripts/generate.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ const fs = require('fs')
33
const path = require('path')
44

55
const outdir = path.join(__dirname, '..', 'grammars')
6+
7+
const consoleGrammar = JSON.parse(fs.readFileSync(path.join(outdir, 'julia-console.json')))
8+
fs.writeFileSync(path.join(outdir, 'julia-console.cson'), CSON.stringify(consoleGrammar, null, 2))
9+
610
let grammar = JSON.parse(fs.readFileSync(path.join(outdir, 'julia.template.json')))
711

812
const templateRules = {

test/test.js

Lines changed: 81 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
})
@@ -3734,3 +3738,80 @@ describe('Julia grammar', function () {
37343738
])
37353739
})
37363740
})
3741+
3742+
describe('Julia-Console', function () {
3743+
let grammar
3744+
before(async function () {
3745+
grammar = await registry.loadGrammar('source.julia.console')
3746+
})
3747+
it('parses the grammar', function () {
3748+
expect(grammar).to.be.a('object')
3749+
})
3750+
it("should highlight multi-line expressions", function () {
3751+
const src = `julia> true
3752+
true
3753+
3754+
julia> begin
3755+
end
3756+
`;
3757+
const tokens = tokenize(grammar, src)
3758+
compareTokens(tokens, [
3759+
{
3760+
value: "julia>",
3761+
scopes: ["source.julia.console", "punctuation.separator.prompt.julia.console"],
3762+
},
3763+
{ scopes: [ 'source.julia.console' ], value: ' ' },
3764+
{
3765+
value: "true",
3766+
scopes: ["source.julia.console", "constant.language.julia"],
3767+
},
3768+
{ scopes: [ 'source.julia.console' ], value: '\ntrue\n\n' },
3769+
{
3770+
value: "julia>",
3771+
scopes: ["source.julia.console", "punctuation.separator.prompt.julia.console"],
3772+
},
3773+
{ scopes: [ 'source.julia.console' ], value: ' ' },
3774+
{
3775+
value: "begin",
3776+
scopes:["source.julia.console", "keyword.control.julia"],
3777+
},
3778+
{ scopes: [ "source.julia.console" ], value: "\n " },
3779+
{
3780+
value: "end",
3781+
scopes: [ "source.julia.console", "keyword.control.end.julia" ],
3782+
},
3783+
])
3784+
})
3785+
3786+
it("should highlight help prompts", function () {
3787+
const src = "help?> begin"
3788+
const tokens = tokenize(grammar, src)
3789+
compareTokens(tokens, [
3790+
{
3791+
scopes: [
3792+
'source.julia.console',
3793+
'punctuation.separator.prompt.help.julia.console'
3794+
],
3795+
value: 'help?>'
3796+
},
3797+
{ scopes: [ 'source.julia.console' ], value: ' ' },
3798+
{ scopes: [ 'source.julia.console', 'keyword.control.julia' ], value: 'begin' }
3799+
])
3800+
})
3801+
3802+
it("should highlight shell prompts", function () {
3803+
const src = "shell> echo \"hello\""
3804+
const tokens = tokenize(grammar, src)
3805+
compareTokens(tokens, [
3806+
{
3807+
scopes: [
3808+
'source.julia.console',
3809+
'punctuation.separator.prompt.shell.julia.console'
3810+
],
3811+
value: 'shell>'
3812+
},
3813+
{ scopes: [ 'source.julia.console' ], value: ' ' },
3814+
{ scopes: [ 'source.julia.console' ], value: 'echo "hello"' }
3815+
])
3816+
})
3817+
})

0 commit comments

Comments
 (0)