mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-11 11:15:24 +03:00
Merge pull request #617 from savetheclocktower/tree-sitter-toml
[modern-tree-sitter] Add TOML tree-sitter grammar
This commit is contained in:
commit
fc156b3a96
19
packages/language-toml/grammars/modern-tree-sitter-toml.cson
Normal file
19
packages/language-toml/grammars/modern-tree-sitter-toml.cson
Normal file
@ -0,0 +1,19 @@
|
||||
name: 'TOML'
|
||||
scopeName: 'source.toml'
|
||||
type: 'modern-tree-sitter'
|
||||
parser: 'tree-sitter-toml'
|
||||
|
||||
injectionRegex: '(toml|TOML)$'
|
||||
|
||||
treeSitter:
|
||||
grammar: 'tree-sitter-toml/tree-sitter-toml.wasm'
|
||||
highlightsQuery: 'tree-sitter-toml/highlights.scm'
|
||||
foldsQuery: 'tree-sitter-toml/folds.scm'
|
||||
tagsQuery: 'tree-sitter-toml/tags.scm'
|
||||
|
||||
fileTypes: [
|
||||
'toml'
|
||||
]
|
||||
|
||||
comments:
|
||||
start: '# '
|
@ -0,0 +1,6 @@
|
||||
|
||||
((table_array_element) @fold
|
||||
(#set! fold.endAt lastChild.endPosition))
|
||||
|
||||
((table) @fold
|
||||
(#set! fold.endAt lastChild.endPosition))
|
141
packages/language-toml/grammars/tree-sitter-toml/highlights.scm
Normal file
141
packages/language-toml/grammars/tree-sitter-toml/highlights.scm
Normal file
@ -0,0 +1,141 @@
|
||||
|
||||
; COMMENTS
|
||||
; ========
|
||||
|
||||
(comment) @comment.line.number-sign.toml
|
||||
((comment) @punctuation.definition.comment.toml
|
||||
(#set! adjust.endAfterFirstMatchOf "^#"))
|
||||
|
||||
|
||||
; SECTIONS
|
||||
; ========
|
||||
|
||||
((table "[" (_) "]") @entity.name.section.table.toml
|
||||
(#set! adjust.endAt firstNamedChild.nextSibling.endPosition))
|
||||
|
||||
((table_array_element "[[" (_) "]]") @entity.name.section.table-array-element.toml
|
||||
(#set! adjust.endAt firstNamedChild.nextSibling.endPosition))
|
||||
|
||||
|
||||
; KEYS
|
||||
; ====
|
||||
|
||||
(pair
|
||||
. [(bare_key) (quoted_key) (dotted_key)]) @meta.pair.key.toml
|
||||
|
||||
((bare_key) @variable.other.key.toml
|
||||
(#set! test.onlyIfDescendantOfType pair))
|
||||
((quoted_key) @variable.other.key.quoted.toml
|
||||
(#set! test.onlyIfDescendantOfType pair))
|
||||
|
||||
(dotted_key "." @keyword.operator.accessor.toml)
|
||||
|
||||
|
||||
; STRINGS
|
||||
; =======
|
||||
|
||||
(string "\"") @string.quoted.double.toml
|
||||
(string "'") @string.quoted.single.toml
|
||||
|
||||
(string "\"\"\"") @string.quoted.double.block.toml
|
||||
(string "'''") @string.quoted.single.block.toml
|
||||
|
||||
(string
|
||||
["\"" "'"] @punctuation.definition.string.begin.toml
|
||||
(#set! test.onlyIfFirst true))
|
||||
|
||||
(string
|
||||
["\"" "'"] @punctuation.definition.string.end.toml
|
||||
(#set! test.onlyIfLast true))
|
||||
|
||||
; WORKAROUND: There seems to be a bug with multi-line strings where only the
|
||||
; opening delimiters are exposed. Let's use adjustments to mark these
|
||||
; delimiters.
|
||||
|
||||
((string "\"\"\"") @punctuation.definition.string.begin.toml
|
||||
(#set! adjust.endAfterFirstMatchOf "^\"\"\""))
|
||||
|
||||
((string "\"\"\"") @punctuation.definition.string.end.toml
|
||||
(#set! adjust.startBeforeFirstMatchOf "\"\"\"$"))
|
||||
|
||||
((string "'''") @punctuation.definition.string.begin.toml
|
||||
(#set! adjust.endAfterFirstMatchOf "^'''"))
|
||||
|
||||
((string "'''") @punctuation.definition.string.end.toml
|
||||
(#set! adjust.startBeforeFirstMatchOf "'''$"))
|
||||
|
||||
(escape_sequence) @constant.character.escape.toml
|
||||
|
||||
; NUMBERS
|
||||
; =======
|
||||
|
||||
((integer) @constant.numeric.hexadecimal.toml
|
||||
(#match? @constant.numeric.hexadecimal.toml "^0x"))
|
||||
|
||||
((integer) @constant.numeric.octal.toml
|
||||
(#match? @constant.numeric.octal.toml "^0o"))
|
||||
|
||||
((integer) @constant.numeric.binary.toml
|
||||
(#match? @constant.numeric.binary.toml "^0b"))
|
||||
|
||||
((integer) @constant.numeric.decimal.integer.toml
|
||||
(#set! test.shy true))
|
||||
|
||||
; Not sure why `inf` and `nan` are parsed as `float`s, but there you have it.
|
||||
((float) @constant.numeric.infinity.toml
|
||||
(#match? @constant.numeric.infinity.toml "^[+-]?inf$"))
|
||||
|
||||
((float) @constant.numeric.nan.toml
|
||||
(#match? @constant.numeric.nan.toml "^[+-]?nan$"))
|
||||
|
||||
((float) @constant.numeric.decimal.float.toml
|
||||
(#set! test.shy true))
|
||||
|
||||
|
||||
; DATES
|
||||
; =====
|
||||
|
||||
; Without much guidance from other grammars, let's treat dates as numeric
|
||||
; constants.
|
||||
|
||||
(local_date) @constant.numeric.date.toml
|
||||
(local_time) @constant.numeric.time.toml
|
||||
(local_date_time) @constant.numeric.date-time.toml
|
||||
(offset_date_time) @constant.numeric.date-time.offset.toml
|
||||
|
||||
|
||||
; BOOLEANS
|
||||
; ========
|
||||
|
||||
(boolean) @constant.language.boolean._TEXT_.toml
|
||||
|
||||
|
||||
; OPERATORS
|
||||
; =========
|
||||
|
||||
(pair "=" @keyword.operator.assignment.toml)
|
||||
|
||||
; PUNCTUATION
|
||||
; ===========
|
||||
|
||||
(array
|
||||
"[" @punctuation.definition.array.begin.bracket.square.toml
|
||||
"]" @punctuation.definition.array.end.bracket.square.toml)
|
||||
|
||||
(array "," @punctuation.separator.array.comma.toml)
|
||||
|
||||
(table
|
||||
"[" @punctuation.definition.table.begin.bracket.square.toml
|
||||
"]" @punctuation.definition.table.end.bracket.square.toml)
|
||||
|
||||
(inline_table
|
||||
"{" @punctuation.definition.inline-table.begin.bracket.curly.toml
|
||||
"}" @punctuation.definition.inline-table.end.bracket.curly.toml)
|
||||
|
||||
(inline_table
|
||||
"," @punctuation.separator.inline-table.comma.toml)
|
||||
|
||||
|
||||
(table_array_element
|
||||
"[[" @punctuation.definition.table-array-element.begin.bracket.square.toml
|
||||
"]]" @punctuation.definition.table-array-element.end.bracket.square.toml)
|
@ -0,0 +1,5 @@
|
||||
(table_array_element
|
||||
[(dotted_key) (bare_key)] @name)
|
||||
|
||||
(table
|
||||
[(dotted_key) (bare_key)] @name)
|
BIN
packages/language-toml/grammars/tree-sitter-toml/tree-sitter-toml.wasm
Executable file
BIN
packages/language-toml/grammars/tree-sitter-toml/tree-sitter-toml.wasm
Executable file
Binary file not shown.
24
packages/language-toml/lib/main.js
Normal file
24
packages/language-toml/lib/main.js
Normal file
@ -0,0 +1,24 @@
|
||||
exports.activate = () => {
|
||||
|
||||
const TODO_PATTERN = /\b(TODO|FIXME|CHANGED|XXX|IDEA|HACK|NOTE|REVIEW|NB|BUG|QUESTION|COMBAK|TEMP|DEBUG|OPTIMIZE|WARNING)\b/;
|
||||
const HYPERLINK_PATTERN = /\bhttps?:/
|
||||
|
||||
atom.grammars.addInjectionPoint('source.toml', {
|
||||
type: 'string',
|
||||
language(node) {
|
||||
return HYPERLINK_PATTERN.test(node.text) ? 'hyperlink' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
|
||||
atom.grammars.addInjectionPoint('source.toml', {
|
||||
type: 'comment',
|
||||
language(node) {
|
||||
return TODO_PATTERN.test(node.text) ? 'todo' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
|
||||
};
|
@ -1,10 +1,15 @@
|
||||
{
|
||||
"name": "language-toml",
|
||||
"version": "0.20.0",
|
||||
"main": "lib/main",
|
||||
"description": "Syntax highlighting for Tom's Obvious, Minimal Language (TOML).",
|
||||
"repository": "https://github.com/pulsar-edit/pulsar",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"atom": "*"
|
||||
"atom": "*",
|
||||
"node": ">=14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tree-sitter-toml": "^0.5.1"
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ describe "TOML grammar", ->
|
||||
atom.packages.activatePackage("language-toml")
|
||||
|
||||
runs ->
|
||||
atom.config.set('core.useTreeSitterParsers', false)
|
||||
grammar = atom.grammars.grammarForScopeName('source.toml')
|
||||
|
||||
it "parses the grammar", ->
|
||||
|
Loading…
Reference in New Issue
Block a user