Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update regex to support multiline in julia-console #285

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions grammars/julia-console.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
}
}
]
}
49 changes: 49 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
})
Expand Down Expand Up @@ -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" ],
},
])
})
})
Loading