This repository has been archived by the owner on Jan 20, 2023. It is now read-only.
forked from asciidoctor/atom-language-asciidoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix asciidoctor#59
- Loading branch information
Showing
4 changed files
with
236 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Hack for fix grammar parsing bug (`java-properties`, `git-config`) | ||
name: 'Hack for properties' | ||
scopeName: 'source.asciidoc.properties' | ||
fileTypes: [] | ||
patterns: [ | ||
{ | ||
include: '#section' | ||
} | ||
{ | ||
include: '#value_pair' | ||
} | ||
{ | ||
include: '#comment' | ||
} | ||
] | ||
repository: | ||
# Comment grammar | ||
comment: | ||
match: '((#|;).*$\\n?)' | ||
captures: | ||
1: | ||
name: 'comment.line.number-sign.asciidoc.properties' | ||
2: | ||
name: 'punctuation.definition.comment.asciidoc.properties' | ||
3: | ||
name: 'comment.line.semi-colon.asciidoc.properties' | ||
4: | ||
name: 'punctuation.definition.comment.asciidoc.properties' | ||
# Section header grammar | ||
section: | ||
match: '^\\[\\s*([\\w_-]+)(?:\\s+((")(?:[^"\\\\]|^\\\\["\\\\])*("))|\\.([\\w_-]+))?\\s*\\]' | ||
name: 'meta.section.asciidoc.properties' | ||
captures: | ||
1: | ||
name: 'entity.name.section.asciidoc.properties' | ||
2: | ||
name: 'entity.name.section.subsection.asciidoc.properties' | ||
3: | ||
name: 'punctuation.definition.section.subsection.begin.asciidoc.properties' | ||
4: | ||
name: 'punctuation.definition.section.subsection.end.asciidoc.properties' | ||
5: | ||
name: 'entity.name.section.subsection.asciidoc.properties' | ||
# Value pair | ||
'value_pair': | ||
name: 'meta.value-pair.section-item.asciidoc.properties' | ||
begin: '([-\\w]+)\\s*(=)\\s*(?!$)' | ||
captures: | ||
1: | ||
name: 'support.constant.asciidoc.properties' | ||
2: | ||
name: 'punctuation.separator.key-value.asciidoc.properties' | ||
end: '$|(?=[#;])' | ||
patterns: [ | ||
{ | ||
include: '#boolean' | ||
} | ||
{ | ||
include: '#escaped-string' | ||
} | ||
{ | ||
include: '#string' | ||
} | ||
{ | ||
include: '#comment' | ||
} | ||
] | ||
# Boolean value | ||
boolean: | ||
match: '\\b(?i:yes|no|0|1|true|false)\\b' | ||
name: 'constant.language.boolean.asciidoc.properties' | ||
# String value | ||
string: | ||
name: 'string.quoted.double.asciidoc.properties' | ||
begin: '"' | ||
beginCaptures: | ||
0: | ||
name: 'punctuation.definition.string.begin.asciidoc.properties' | ||
end: '"' | ||
endCaptures: | ||
0: | ||
name: 'punctuation.definition.string.end.asciidoc.properties' | ||
patterns: [ | ||
{ | ||
match: '\\\\[ntb"\\\\]' | ||
name: 'constant.character.escape.asciidoc.properties' | ||
} | ||
{ | ||
match: '\\\\.' | ||
name: 'invalid.illegal.unknown-escape.asciidoc.properties' | ||
} | ||
] | ||
'escaped-string': | ||
match: '\\\\"' | ||
name: 'constant.character.escape.asciidoc.properties' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
describe 'Properties grammar', -> | ||
grammar = null | ||
|
||
beforeEach -> | ||
waitsForPromise -> | ||
atom.packages.activatePackage 'language-asciidoc' | ||
|
||
runs -> | ||
grammar = atom.grammars.grammarForScopeName 'source.asciidoc.properties' | ||
|
||
# convenience function during development | ||
debug = (tokens) -> | ||
console.log(JSON.stringify(tokens, null, ' ')) | ||
|
||
it 'load the "properties" config grammar', -> | ||
expect(grammar).toBeTruthy() | ||
expect(grammar.scopeName).toBe 'source.asciidoc.properties' | ||
|
||
describe 'Should parse "section" when', -> | ||
it 'was a simple word', -> | ||
{tokens} = grammar.tokenizeLine '[foobar]' | ||
expect(tokens).toHaveLength 3 | ||
expect(tokens[0]).toEqual value: '[', scopes: ['source.asciidoc.properties', 'meta.section.asciidoc.properties'] | ||
expect(tokens[1]).toEqual value: 'foobar', scopes: ['source.asciidoc.properties', 'meta.section.asciidoc.properties', 'entity.name.section.asciidoc.properties'] | ||
expect(tokens[2]).toEqual value: ']', scopes: ['source.asciidoc.properties', 'meta.section.asciidoc.properties'] | ||
|
||
it 'have a subsection separate by a dot', -> | ||
{tokens} = grammar.tokenizeLine '[foo.bar]' | ||
expect(tokens).toHaveLength 5 | ||
expect(tokens[0]).toEqual value: '[', scopes: ['source.asciidoc.properties', 'meta.section.asciidoc.properties'] | ||
expect(tokens[1]).toEqual value: 'foo', scopes: ['source.asciidoc.properties', 'meta.section.asciidoc.properties', 'entity.name.section.asciidoc.properties'] | ||
expect(tokens[2]).toEqual value: '.', scopes: ['source.asciidoc.properties', 'meta.section.asciidoc.properties'] | ||
expect(tokens[3]).toEqual value: 'bar', scopes: ['source.asciidoc.properties', 'meta.section.asciidoc.properties', 'entity.name.section.subsection.asciidoc.properties'] | ||
expect(tokens[4]).toEqual value: ']', scopes: ['source.asciidoc.properties', 'meta.section.asciidoc.properties'] | ||
|
||
it 'have a subsection with double-quote', -> | ||
{tokens} = grammar.tokenizeLine '[foo "bar"]' | ||
expect(tokens).toHaveLength 7 | ||
expect(tokens[0]).toEqual value: '[', scopes: ['source.asciidoc.properties', 'meta.section.asciidoc.properties'] | ||
expect(tokens[1]).toEqual value: 'foo', scopes: ['source.asciidoc.properties', 'meta.section.asciidoc.properties', 'entity.name.section.asciidoc.properties'] | ||
expect(tokens[2]).toEqual value: ' ', scopes: ['source.asciidoc.properties', 'meta.section.asciidoc.properties'] | ||
expect(tokens[3]).toEqual value: '"', scopes: ['source.asciidoc.properties', 'meta.section.asciidoc.properties', 'entity.name.section.subsection.asciidoc.properties', 'punctuation.definition.section.subsection.begin.asciidoc.properties'] | ||
expect(tokens[4]).toEqual value: 'bar', scopes: ['source.asciidoc.properties', 'meta.section.asciidoc.properties', 'entity.name.section.subsection.asciidoc.properties'] | ||
expect(tokens[5]).toEqual value: '"', scopes: ['source.asciidoc.properties', 'meta.section.asciidoc.properties', 'entity.name.section.subsection.asciidoc.properties', 'punctuation.definition.section.subsection.end.asciidoc.properties'] | ||
expect(tokens[6]).toEqual value: ']', scopes: ['source.asciidoc.properties', 'meta.section.asciidoc.properties'] | ||
|
||
describe 'Should parse "comment" when', -> | ||
it 'start by a hash', -> | ||
{tokens} = grammar.tokenizeLine '# comment' | ||
expect(tokens).toHaveLength 2 | ||
expect(tokens[0]).toEqual value: '#', scopes: ['source.asciidoc.properties', 'comment.line.number-sign.asciidoc.properties', 'punctuation.definition.comment.asciidoc.properties'] | ||
expect(tokens[1]).toEqual value: ' comment', scopes: ['source.asciidoc.properties', 'comment.line.number-sign.asciidoc.properties'] | ||
|
||
it 'start by a ;', -> | ||
{tokens} = grammar.tokenizeLine '; comment' | ||
expect(tokens).toHaveLength 2 | ||
expect(tokens[0]).toEqual value: ';', scopes: ['source.asciidoc.properties', 'comment.line.number-sign.asciidoc.properties', 'punctuation.definition.comment.asciidoc.properties'] | ||
expect(tokens[1]).toEqual value: ' comment', scopes: ['source.asciidoc.properties', 'comment.line.number-sign.asciidoc.properties'] | ||
|
||
describe 'Should parse "value pair" when', -> | ||
it 'have a simple value', -> | ||
{tokens} = grammar.tokenizeLine 'name = foobar' | ||
expect(tokens).toHaveLength 5 | ||
expect(tokens[0]).toEqual value: 'name', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties', 'support.constant.asciidoc.properties'] | ||
expect(tokens[1]).toEqual value: ' ', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties'] | ||
expect(tokens[2]).toEqual value: '=', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties', 'punctuation.separator.key-value.asciidoc.properties'] | ||
expect(tokens[3]).toEqual value: ' ', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties'] | ||
expect(tokens[4]).toEqual value: 'foobar', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties'] | ||
|
||
it 'have a value embedded in double quote', -> | ||
{tokens} = grammar.tokenizeLine 'name = "foobar"' | ||
expect(tokens).toHaveLength 7 | ||
expect(tokens[0]).toEqual value: 'name', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties', 'support.constant.asciidoc.properties'] | ||
expect(tokens[1]).toEqual value: ' ', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties'] | ||
expect(tokens[2]).toEqual value: '=', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties', 'punctuation.separator.key-value.asciidoc.properties'] | ||
expect(tokens[3]).toEqual value: ' ', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties'] | ||
expect(tokens[4]).toEqual value: '"', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties', 'string.quoted.double.asciidoc.properties', 'punctuation.definition.string.begin.asciidoc.properties'] | ||
expect(tokens[5]).toEqual value: 'foobar', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties', 'string.quoted.double.asciidoc.properties'] | ||
expect(tokens[6]).toEqual value: '"', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties', 'string.quoted.double.asciidoc.properties', 'punctuation.definition.string.end.asciidoc.properties'] | ||
|
||
it 'have a boolean value', -> | ||
{tokens} = grammar.tokenizeLine 'name = true' | ||
expect(tokens).toHaveLength 5 | ||
expect(tokens[0]).toEqual value: 'name', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties', 'support.constant.asciidoc.properties'] | ||
expect(tokens[1]).toEqual value: ' ', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties'] | ||
expect(tokens[2]).toEqual value: '=', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties', 'punctuation.separator.key-value.asciidoc.properties'] | ||
expect(tokens[3]).toEqual value: ' ', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties'] | ||
expect(tokens[4]).toEqual value: 'true', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties', 'constant.language.boolean.asciidoc.properties'] | ||
|
||
it 'have a value contains escaped double quote', -> | ||
{tokens} = grammar.tokenizeLine 'name = \\"foobar\\"' | ||
expect(tokens).toHaveLength 7 | ||
expect(tokens[0]).toEqual value: 'name', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties', 'support.constant.asciidoc.properties'] | ||
expect(tokens[1]).toEqual value: ' ', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties'] | ||
expect(tokens[2]).toEqual value: '=', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties', 'punctuation.separator.key-value.asciidoc.properties'] | ||
expect(tokens[3]).toEqual value: ' ', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties'] | ||
expect(tokens[4]).toEqual value: '\\"', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties', 'constant.character.escape.asciidoc.properties'] | ||
expect(tokens[5]).toEqual value: 'foobar', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties'] | ||
expect(tokens[6]).toEqual value: '\\"', scopes: ['source.asciidoc.properties', 'meta.value-pair.section-item.asciidoc.properties', 'constant.character.escape.asciidoc.properties'] |