Skip to content
Merged
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
18 changes: 12 additions & 6 deletions grammars/julia-console.cson
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
scopeName: 'source.julia.console'
name: 'Julia Console'
comment: "Not sure what this will be used for... Maybe if we have a REPL someday"
comment: 'Not sure what this will be used for... Maybe if we have a REPL someday. We do now...'
patterns: [
{
match: '^(julia>|\\.{3}|In \\[\\d+\\]:) (.+)$'
match: '^(julia>)(\\s+.*(?:\\n\\s{6}\\s+.*)*)'
captures:
'1':
name: 'punctuation.separator.prompt.julia.console'
'2':
patterns: [
include: 'source.julia'
{
include: 'source.julia'
}
]
}
{
Expand All @@ -19,7 +21,9 @@ patterns: [
name: 'punctuation.separator.prompt.shell.julia.console'
'2':
patterns: [
include: 'source.shell'
{
include: 'source.shell'
}
]
}
{
Expand All @@ -29,7 +33,9 @@ patterns: [
name: 'punctuation.separator.prompt.help.julia.console'
'2':
patterns: [
include: 'source.julia'
{
include: 'source.julia'
}
]
}
]
]
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"
}
]
}
}
}
]
}
4 changes: 4 additions & 0 deletions scripts/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ const fs = require('fs')
const path = require('path')

const outdir = path.join(__dirname, '..', 'grammars')

const consoleGrammar = JSON.parse(fs.readFileSync(path.join(outdir, 'julia-console.json')))
fs.writeFileSync(path.join(outdir, 'julia-console.cson'), CSON.stringify(consoleGrammar, null, 2))

let grammar = JSON.parse(fs.readFileSync(path.join(outdir, 'julia.template.json')))

const templateRules = {
Expand Down
81 changes: 81 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,80 @@ 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" ],
},
])
})

it("should highlight help prompts", function () {
const src = "help?> begin"
const tokens = tokenize(grammar, src)
compareTokens(tokens, [
{
scopes: [
'source.julia.console',
'punctuation.separator.prompt.help.julia.console'
],
value: 'help?>'
},
{ scopes: [ 'source.julia.console' ], value: ' ' },
{ scopes: [ 'source.julia.console', 'keyword.control.julia' ], value: 'begin' }
])
})

it("should highlight shell prompts", function () {
const src = "shell> echo \"hello\""
const tokens = tokenize(grammar, src)
compareTokens(tokens, [
{
scopes: [
'source.julia.console',
'punctuation.separator.prompt.shell.julia.console'
],
value: 'shell>'
},
{ scopes: [ 'source.julia.console' ], value: ' ' },
{ scopes: [ 'source.julia.console' ], value: 'echo "hello"' }
])
})
})