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

for outer loops #130

Merged
merged 4 commits into from
Dec 8, 2017
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
27 changes: 26 additions & 1 deletion grammars/julia.cson
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ repository:
match: "\\bend\\b"
name: "constant.numeric.julia"
}
{
match: "\\bfor\\b"
name: "keyword.control.julia"
}
{
include: "$self"
}
Expand Down Expand Up @@ -116,6 +120,10 @@ repository:
"1":
name: "keyword.operator.transposed-func.julia"
patterns: [
{
match: '\\bfor\\b'
name: 'keyword.control.julia'
}
{
include: "$self"
}
Expand Down Expand Up @@ -164,7 +172,24 @@ repository:
name: "keyword.other.julia"
}
{
match: "\\b(?<![:_])(?:if|else|elseif|while|for|begin|let|do|try|catch|finally|return|break|continue)\\b"
comment: "special case for blocks to support tokenizing outer properly"
begin: "\\b(for)\\b"
beginCaptures:
"0":
name: "keyword.control.julia"
end: "(?<!,|\\s)(\\s*\\n)"
patterns: [
{
match: "\\bouter\\b"
name: "keyword.other.julia"
}
{
include: '$self'
}
]
}
{
match: "\\b(?<![:_])(?:if|else|elseif|while|begin|let|do|try|catch|finally|return|break|continue)\\b"
name: "keyword.control.julia"
}
{
Expand Down
39 changes: 37 additions & 2 deletions spec/julia-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,13 @@ describe "Julia grammar", ->
expect(tokens[14]).toEqual value: '; i', scopes: ["source.julia"]
expect(tokens[15]).toEqual value: '::', scopes: ["source.julia", "keyword.operator.relation.julia"]
expect(tokens[16]).toEqual value: 'J', scopes: ["source.julia", "support.type.julia"]

it "tokenizes dot operators", ->
{tokens} = grammar.tokenizeLine('x .<= y')
expect(tokens[0]).toEqual value: 'x ', scopes: ["source.julia"]
expect(tokens[1]).toEqual value: '.<=', scopes: ["source.julia", "keyword.operator.relation.julia"]
expect(tokens[2]).toEqual value: ' y', scopes: ["source.julia"]

it "tokenizes type", ->
{tokens} = grammar.tokenizeLine('T>:Interger')
expect(tokens[0]).toEqual value: 'T', scopes: ["source.julia"]
Expand All @@ -508,3 +508,38 @@ describe "Julia grammar", ->
expect(tokens[1]).toEqual value: ' ', scopes: ["source.julia"]
expect(tokens[2]).toEqual value: '2', scopes: ["source.julia", "constant.numeric.julia"]
expect(tokens[3]).toEqual value: 'img', scopes: ["source.julia"]

it 'tokenizes for outer loops', ->
{tokens} = grammar.tokenizeLine('for outer i = range')
expect(tokens[0]).toEqual value: 'for', scopes: ["source.julia", "keyword.control.julia"]
expect(tokens[1]).toEqual value: ' ', scopes: ["source.julia"]
expect(tokens[2]).toEqual value: 'outer', scopes: ["source.julia", "keyword.other.julia"]
expect(tokens[3]).toEqual value: ' i ', scopes: ["source.julia"]
expect(tokens[4]).toEqual value: '=', scopes: ["source.julia", "keyword.operator.update.julia"]
expect(tokens[5]).toEqual value: ' range', scopes: ["source.julia"]

it 'tokenizes for outer loops with multiple iteration variables', ->
{tokens} = grammar.tokenizeLine('for outer i = range, \n outer j = range\n outer = 3')
expect(tokens[0]).toEqual value: 'for', scopes: ["source.julia", "keyword.control.julia"]
expect(tokens[1]).toEqual value: ' ', scopes: ["source.julia"]
expect(tokens[2]).toEqual value: 'outer', scopes: ["source.julia", "keyword.other.julia"]
expect(tokens[3]).toEqual value: ' i ', scopes: ["source.julia"]
expect(tokens[4]).toEqual value: '=', scopes: ["source.julia", "keyword.operator.update.julia"]
expect(tokens[5]).toEqual value: ' range', scopes: ["source.julia"]
expect(tokens[6]).toEqual value: ',', scopes: ["source.julia", "meta.bracket.julia"]
expect(tokens[7]).toEqual value: ' \n ', scopes: ["source.julia"]
expect(tokens[8]).toEqual value: 'outer', scopes: ["source.julia", "keyword.other.julia"]
expect(tokens[9]).toEqual value: ' j ', scopes: ["source.julia"]
expect(tokens[10]).toEqual value: '=', scopes: ["source.julia", "keyword.operator.update.julia"]
expect(tokens[11]).toEqual value: ' range', scopes: ["source.julia"]
expect(tokens[12]).toEqual value: '\n', scopes: ["source.julia"]
expect(tokens[13]).toEqual value: ' outer ', scopes: ["source.julia"]
expect(tokens[14]).toEqual value: '=', scopes: ["source.julia", "keyword.operator.update.julia"]
expect(tokens[15]).toEqual value: ' ', scopes: ["source.julia"]
expect(tokens[16]).toEqual value: '3', scopes: ["source.julia", "constant.numeric.julia"]

it 'does not tokenize outer by itself as a keyword', ->
{tokens} = grammar.tokenizeLine('outer = foo')
expect(tokens[0]).toEqual value: 'outer ', scopes: ["source.julia"]
expect(tokens[1]).toEqual value: '=', scopes: ["source.julia", "keyword.operator.update.julia"]
expect(tokens[2]).toEqual value: ' foo', scopes: ["source.julia"]