-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNestedText.sublime-syntax
More file actions
executable file
·131 lines (102 loc) · 3.62 KB
/
NestedText.sublime-syntax
File metadata and controls
executable file
·131 lines (102 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
%YAML 1.2
---
# https://www.sublimetext.com/docs/3/syntax.html
name: NestedText
scope: source.nestedtext
version: 0.2
file_extensions:
- nt
variables:
ws: '[ \t]*' # Ref does not allow tabs. I do
wsnl: '([ \t\n])*'
c_indicator: '[-?:,\[\]{}#&*!|>''"%@`]'
# Used to detect the possible start of a key.
peek_key_start: '(?=[A-Za-z0-9_''"-])'
dot_peek_key: '{{ws}}(\.){{ws}}{{peek_key_start}}'
string_tag: '(> )|(>$)'
key_tag: '(: )|(:$)'
list_tag: '(- )|(-$)'
dictionary_tag: '[^\n\-\>\:\[\{].*:(?=.+$)'
# integer = [ "-" / "+" ] int
# int = DIGIT / digit1-9 1*( DIGIT / "_" DIGIT )
integer: '([\+\-]?) (?: [0-9] | [1-9] (?: [0-9] | _ [0-9] )+ )'
HEXDIG: '[0-9A-Fa-f]'
hex_int: '0x{{HEXDIG}}(?:{{HEXDIG}}|_{{HEXDIG}})*'
oct_int: '0o[0-7](?:[0-7]|_[0-7])*'
bin_int: '0b[0-1](?:[0-1]|_[0-1])*'
bool: |-
(?x:
y|Y|yes|Yes|YES|n|N|no|No|NO
|true|True|TRUE|false|False|FALSE
|on|On|ON|off|Off|OFF
)
contexts:
main:
- include: line-types
# - include: illegal
illegal:
- match: (.*) ## Invalid things -> everything unmatched
captures:
1: invalid.illegal.nestedtext
line-types:
- include: key-types # :␣ '(: )|(:$)'
- include: dictionary-types # :␣ '^[^\#\n\-\>\:\[\{].*(:)' /(?=.+$)
- include: list-types # -␣ '(- )|(-$)'
# - include: inline-types
- include: string-types # (-␣) OR (:␣), (>␣) OR (>↵),
- include: comments
################################################################################
# key-types:
################################################################################
dictionary-types:
- include: dictionary-item # :␣
- include: dictionary-multiline-item # :␣
dictionary-item:
- meta_scope: meta.tag.key.nestedtext
- match: '^[^\#\n\-\>\:\[\{](.*)(:)'
captures:
1: keyword.other.name.nestedtext
2: punctuation.separator.mapping.key-value.nestedtext
# push:
# - meta_scope: meta.mapping.value.json
# - include: value
# pop: 1
################################################################################
list-types:
- include: list-item # -␣
# list-item:
# - match: (-$)
################################################################################
string-types:
- include: restofline-string-item # (-␣) OR (:␣)
- include: multiline-string-item # (>␣) OR (>↵)
restofline-string-item:
- match: (- )
scope: punctuation.definition.string.begin.nestedtext
set:
- meta_scope: string.quoted.double.basic.nestedtext
- match: '\n'
scope: punctuation.definition.string.end.nestedtext
pop: true
multiline-string-item:
- match: (> )|(>$)
scope: punctuation.definition.string.begin.nestedtext
set:
- meta_scope: string.quoted.double.basic.nestedtext
- match: '\n'
scope: punctuation.definition.string.end.nestedtext
pop: true
################################################################################
comments:
# ## Based on https://github.com/jasonwilliams/sublime_toml_highlighting
# - match: '{{ws}}((#).*)'
# captures:
# 1: comment.line.number-sign.nestedtext
# 2: punctuation.definition.comment.nestedtext
## Based on https://github.com/sublimehq/Packages/blob/master/YAML/YAML.sublime-syntax#L686
- match: '#'
scope: punctuation.definition.comment.line.number-sign.nestedtext
set:
- meta_scope: comment.line.number-sign.nestedtext
- match: \n|\z
pop: true