Skip to content

Commit

Permalink
Merge pull request #266 from JuliaEditorSupport/sp/fix-subtype-transpose
Browse files Browse the repository at this point in the history
fix: subtype transpose
  • Loading branch information
pfitzseb authored Aug 11, 2023
2 parents 36d61fb + 7cbe6a7 commit 134a106
Show file tree
Hide file tree
Showing 7 changed files with 456 additions and 373 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

[![Build Status](https://github.com/JuliaEditorSupport/atom-language-julia/workflows/CI/badge.svg)](https://github.com/JuliaEditorSupport/atom-language-julia/actions?query=workflow%3ACI+branch%3Amaster)

Julia grammar definition for Atom, VSCode, and GitHub.
Julia grammar definition for Atom, VS Code, and GitHub.

The source of truth in this repo is `grammars/julia.cson`; `julia.json` and `julia_vscode.json` are automatically generated in a pre-commit hook.
The source of truth in this repo is `grammars/julia.json`; `julia.cson` and `julia_vscode.json` are automatically generated in a pre-commit hook.

## Atom
Also an Atom package to provide Julia syntax highlighting, snippets, and docstring folding. Originally based off of [JuliaLang/julia.tmBundle](https://github.com/JuliaLang/Julia.tmbundle), merged with new ideas from [language-julia](https://github.com/tpoisot/language-julia/blob/master/README.md).
Expand Down
739 changes: 373 additions & 366 deletions grammars/julia.cson

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion grammars/julia.json
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,16 @@
"name": "keyword.operator.shift.julia"
},
{
"match": "(?:\\s*(::|>:|<:)\\s*((?:(?:Union)?\\([^)]*\\)|[[:alpha:]_$∇][[:word:]⁺-ₜ!′\\.]*(?:(?:{(?:[^{}]|{(?:[^{}]|{[^{}]*})*})*})|(?:\".+?(?<!\\\\)\"))?)))(?:\\.\\.\\.)?",
"match": "(?:\\s*(::|>:|<:)\\s*((?:(?:Union)?\\([^)]*\\)|[[:alpha:]_$∇][[:word:]⁺-ₜ!′\\.]*(?:(?:{(?:[^{}]|{(?:[^{}]|{[^{}]*})*})*})|(?:\".+?(?<!\\\\)\"))?)))(?:\\.\\.\\.)?((?:\\.)?'*)",
"captures": {
"1": {
"name": "keyword.operator.relation.types.julia"
},
"2": {
"name": "support.type.julia"
},
"3": {
"name": "keyword.operator.transpose.julia"
}
}
},
Expand Down
5 changes: 4 additions & 1 deletion grammars/julia_vscode.json
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,16 @@
"name": "keyword.operator.shift.julia"
},
{
"match": "(?:\\s*(::|>:|<:)\\s*((?:(?:Union)?\\([^)]*\\)|[[:alpha:]_$∇][[:word:]⁺-ₜ!′\\.]*(?:(?:{(?:[^{}]|{(?:[^{}]|{[^{}]*})*})*})|(?:\".+?(?<!\\\\)\"))?)))(?:\\.\\.\\.)?",
"match": "(?:\\s*(::|>:|<:)\\s*((?:(?:Union)?\\([^)]*\\)|[[:alpha:]_$∇][[:word:]⁺-ₜ!′\\.]*(?:(?:{(?:[^{}]|{(?:[^{}]|{[^{}]*})*})*})|(?:\".+?(?<!\\\\)\"))?)))(?:\\.\\.\\.)?((?:\\.)?'*)",
"captures": {
"1": {
"name": "keyword.operator.relation.types.julia"
},
"2": {
"name": "support.type.julia"
},
"3": {
"name": "keyword.operator.transpose.julia"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"homepage": "https://github.com/JuliaEditorSupport/atom-language-julia",
"scripts": {
"generate": "node ./scripts/generate.js && git add grammars/julia.json && git add grammars/julia_vscode.json",
"generate": "node ./scripts/generate.js && git add grammars/julia.cson && git add grammars/julia_vscode.json",
"test": "npm run generate && mocha"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions scripts/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const fs = require('fs')
const path = require('path')

const outdir = path.join(__dirname, '..', 'grammars')
const grammar = CSON.load(path.join(outdir, 'julia.cson'))
const grammar = JSON.parse(fs.readFileSync(path.join(outdir, 'julia.json')))

// write normal JSON grammar
fs.writeFileSync(path.join(outdir, 'julia.json'), JSON.stringify(grammar, null, 2))
fs.writeFileSync(path.join(outdir, 'julia.cson'), CSON.stringify(grammar, null, 2))

// recurse through grammar and replace values:
function recurseAndReplace(obj, key, val, replacement) {
Expand Down
70 changes: 70 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3129,4 +3129,74 @@ describe('Julia grammar', function() {
scopes: ["source.julia", "comment.block.number-sign-equals.julia", "punctuation.definition.comment.end.julia"]
});
});
it("tokenizes subtype relations with a transpose suffix", function() {
const tokens = tokenize(grammar, "Bar <: Foo'");
expect(tokens[0]).to.deep.equal({
value: "Bar",
scopes: ["source.julia"]
});
expect(tokens[1]).to.deep.equal({
value: " ",
scopes: ["source.julia"]
});
expect(tokens[2]).to.deep.equal({
value: "<:",
scopes: ["source.julia", "keyword.operator.relation.types.julia"]
});
expect(tokens[3]).to.deep.equal({
value: " ",
scopes: ["source.julia"]
});
expect(tokens[4]).to.deep.equal({
value: "Foo",
scopes: ["source.julia", "support.type.julia"]
});
expect(tokens[5]).to.deep.equal({
value: "'",
scopes: ["source.julia", "keyword.operator.transpose.julia"]
});
});
it("tokenizes subtype relations with a transpose suffix", function() {
const tokens = tokenize(grammar, "Bar <: Foo'.A()");
expect(tokens[0]).to.deep.equal({
value: "Bar",
scopes: ["source.julia"]
});
expect(tokens[1]).to.deep.equal({
value: " ",
scopes: ["source.julia"]
});
expect(tokens[2]).to.deep.equal({
value: "<:",
scopes: ["source.julia", "keyword.operator.relation.types.julia"]
});
expect(tokens[3]).to.deep.equal({
value: " ",
scopes: ["source.julia"]
});
expect(tokens[4]).to.deep.equal({
value: "Foo",
scopes: ["source.julia", "support.type.julia"]
});
expect(tokens[5]).to.deep.equal({
value: "'",
scopes: ["source.julia", "keyword.operator.transpose.julia"]
});
expect(tokens[6]).to.deep.equal({
value: ".",
scopes: ["source.julia", "keyword.operator.dots.julia"]
});
expect(tokens[7]).to.deep.equal({
value: "A",
scopes: ["source.julia", "support.function.julia"]
});
expect(tokens[8]).to.deep.equal({
value: "(",
scopes: ["source.julia", "meta.bracket.julia"]
});
expect(tokens[9]).to.deep.equal({
value: ")",
scopes: ["source.julia", "meta.bracket.julia"]
});
});
})

0 comments on commit 134a106

Please sign in to comment.