-
Notifications
You must be signed in to change notification settings - Fork 588
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
Syntax Development Tips/Advice #757
Comments
Check for Scope DoublingThe characters |
Stateful ChainingDon't Over-Use
Push Your First StateWhile it is absolutely possible to have a contexts:
main:
- match: a
scope: first
push: expect-b
- match: \d+
scope: constant.numeric
expect-b:
- match: b
scope: second
set: expect-c
expect-c:
- match: c
scope: third
pop: true Notice how Lookahead Push for Meta-ScopingSometimes you need to apply a meta-scope to an entire stateful chunk. When this is the case, you almost certainly want your contexts:
main:
- match: (?=a)
push: expect-a
- match: \d+
scope: constant.numeric
expect-a:
- meta_scope: meta.abc
- match: a
scope: first
set: expect-b
expect-b:
- meta_scope: meta.abc
- match: b
scope: second
set: expect-c
expect-c:
- meta_scope: meta.abc
- match: c
scope: third
pop: true Bail OutsAlways remember that you're writing a parser for a set of partially valid syntax fragments. The normal mode of operation is that someone is actively typing new text. For this reason, you need to make sure that any and all stateful contexts you use have aggressive "bail-outs" for when something goes wrong. As a rule of thumb, if there's a case where a compiler's parser would have produced an error, your syntax mode should handle that case by Consider the example from above. Imagine the user is typing typing into the following buffer:
Even if the user is actively typing contexts:
main:
- match: (?=a)
push: expect-a
- match: \d+
scope: constant.numeric
bail-out:
- match: (?=\S)
pop: true
expect-a:
- meta_scope: meta.abc
- match: a
scope: first
set: expect-b
- include: bail-out
expect-b:
- meta_scope: meta.abc
- match: b
scope: second
set: expect-c
- include: bail-out
expect-c:
- meta_scope: meta.abc
- match: c
scope: third
pop: true
- include: bail-out Now, when the user starts with the following buffer:
They can place the cursor on the second line and type Test Partially-Valid BuffersDon't just test that correctly-written constructs were scoped appropriately. Test that partial fragments also scope in a reasonable way. Test that unrelated constructs which come lexically after these partially-valid constructs are also scoped correctly. OrganizeThere are no bonus points (or bonus performance) for brevity. Organize your |
Use the StackLong chains of contexts:
else-pop:
- match: (?=\S)
pop: true
function-body:
- match: \{
scope: punctuation.section.braces.begin.js
set:
- meta-function-body
- expect-closing-brace
- statements
- directives
meta-function-body:
- meta_scope: meta.function.body.js
- include: else-pop
expect-closing-brace:
- match: \}
scope: punctuation.section.braces.end.js
pop: true
- include: else-pop
statements:
- match: (?=\})
pop: true
- ...
directives:
- match: "'use (?:strict|asm)';"
scope: keyword.other.directive.js
- include: else-pop As an added benefit, most of these scopes can be reused: statements:
...
- match: \{
scope: punctuation.section.braces.begin.js
push:
- meta-block
- expect-closing-brace
- statements
...
meta-block:
- meta_scope: meta.block.js
- include: else-pop And they can be easily composed: expression:
...
- match: \bfunction\b
scope: meta.function storage.type.function.js
set:
- function-body
- function-parameters // Implementations omitted
- function-name
... As a bonus, states stacked this way are implicitly optional. If one is omitted, the highlighter will move on to the next without interruption. For instance, in the last example, the construction will be parsed correctly whether or not the author supplies a function name. (At first, I was concerned about the efficiency of all of the stack manipulation and context switching, but in practice it seems to be just as fast as the traditional method. The JS+Babel+React+Flow syntax I've developed this architecture for runs about 15% faster than the stock JS syntax.) |
Preprocessing with YAML MacrosSyntax definitions can have a lot of repetitive elements to them. Sometimes, these elements are simple enough that you can simple contexts:
else-pop:
- match: (?=\S)
pop: true
order-expression:
- match: (?i)\b(?:ASC|DESC|NULLS|FIRST|LAST)\b
scope: keyword.other.sql
- include: else-pop But this example contains another common SQL idiom: keywords are always case-insensitive and surrounded by word breaks, so the syntax will contain many repetitions of the order-expression:
- match: !word ASC|DESC|NULLS|FIRST|LAST
scope: keyword.other.sql
- include: else-pop The macro: # macros.py
def word(match):
return r'(?i)\b(?:%s)\b' % match The engine: # build.py
import yaml, sys
from os import path
filename = sys.argv[1]
output_path, extension = path.splitext(path.basename(filename))
if extension != '.source': raise "Not a .source file!"
input_file = open(filename, 'r')
output_file = open(output_path, 'w')
import macros
PREAMBLE = '%YAML 1.2\n---\n'
def apply_transform(loader, node, transform):
try:
if isinstance(node, yaml.ScalarNode):
return transform(loader.construct_scalar(node))
elif isinstance(node, yaml.SequenceNode):
return transform(*loader.construct_sequence(node))
elif isinstance(node, yaml.MappingNode):
return transform(**loader.construct_mapping(node))
except TypeError as e:
print('Failed to transform node: {}\n{}'.format(str(e), node))
def get_constructor(transform):
return lambda loader, node: apply_transform(loader, node, transform)
for name, transform in macros.__dict__.items():
if callable(transform):
yaml.add_constructor(
'!'+name.lstrip('_'),
get_constructor(transform)
)
syntax = yaml.load(input_file)
output_file.write(PREAMBLE)
yaml.dump(syntax, output_file) Another example: def meta(name):
return [
{ 'meta_scope': 'meta.%s.sql' % name, },
{ 'match': '', 'pop': True },
] block:
- match: !word BEGIN
scope: keyword.control.sql
push:
- !meta block
- statements We can go further. In Oracle SQL, any identifier may be wrapped in optional double quotes: create table mytable ... ;
create table "mytable" ... ; Implementing both versions is possible: expect-table-name:
- match: \b{{ident}}\b
scope: entity.name.table.sql
pop: true
- match: (")([^"]+)(")
captures:
1: punctuation.definition.string.begin.sql
2: entity.name.table.sql
3: punctuation.definition.string.end.sql
pop: true
- include: else-pop But then we have to do this for every single type of identifier -- procedure names, aliases, variables, etc. So we write a macro for it: def expect_identifier(scope):
return [
{ 'match': r'\b{{ident}}\b', 'scope': scope, 'pop': True },
{
'match': r'(")([^"]+)(")',
'scope': 'string.quoted.double.sql',
'captures': {
'1': 'punctuation.definition.string.begin.sql',
'2': scope,
'3': 'punctuation.definition.string.end.sql',
},
'pop': True,
},
{ 'match': r'(?=\S)', 'pop': True },
] Define all of these scopes the same way: expect-table-name: !expect_identifier entity.name.table.sql
expect-alias: !expect_identifier entity.name.alias.sql Or just use the macro inline: declarations:
...
- match: !word TYPE
scope: storage.type.sql
push:
- !meta declaration.type
- type-definition-value
- !expect_keyword IS
- !expect_identifier entity.name.type.sql
... Using macros, you can define very complicated constructs in a compact fashion that is easy to understand and reasonably robust against invalid input: - match: !word FOR
scope: keyword.control.sql
push:
- !meta control.for
- !expect_keyword LOOP
- !expect_keyword END
- statements
- !expect_keyword LOOP
- expression
- !expect [ \.\., keyword.operator.other ]
- expression
- !expect_keyword REVERSE
- !expect_keyword IN
- !expect_identifier variable.other.sql |
Keep matches conciseWhere possible, avoid match patterns like Why? Because sometimes the syntax could get embedded in another syntax, and that syntax might want to use For example, if you have a language that defines line comments like this: comments:
- match: (//).*$\n?
scope: comment.line.double-slash.example
captures:
1: punctuation.definition.comment.example and then want to include it in HTML, for example using a well-known example of PHP style markers: embed:
- match: '<\?'
scope: punctuation.section.embedded.begin.example
push: [end_embed, scope:base.scope.for.example.above]
with_prototype:
- match: '(?=\?>)'
pop: true
end_embed:
- match: '\?>'
scope: punctuation.section.embedded.end.example
pop: true then you will find code like:
where the So the proper way to declare the comments:
- match: '//'
scope: punctuation.definition.comment.example
push:
- meta_scope: comment.line.double-slash.example
- match: $\n? # Consume the newline so that completions aren't shown at the end of the line when typing comments
pop: true |
Unusual Syntaxes and Their PitfallsLately I've started working on a syntax file for an Interactive Fiction (text adventures) programming language which tries to hide the complexity of programming and look like natural English as much as possible. Because of its scarse use of punctuations, I've found myself facing some unexpected problems — the full story here:
Particularly, I was struggling in handling closing block statement of the type Forceful PoppingFirst of all, I faced the problem of how to pop out of the stack in certain (unavoidable) situations. And I was kindly introduced to the The main problem was tied to uncosumed whitespace: the Also, another problem was the Here here is the code of how I've managed to workaround the problem: class:
- match: (?i)\bEVERY\b
scope: storage.type.class.alan
set: [class_body, class_identifier]
class_body:
- meta_scope: meta.class.alan
- include: class_head
- include: class_tail
class_head:
- match: (?i)\bIsA\b
scope: storage.modifier.extends
push: inherited_class_identifier
# TODO: inheritance
class_tail:
# ===========================
# END EVERY => no ID & no `.`
# ===========================
# When END EVERY is not followed by neither ID or dot, we must capture it
# separately to avoid stray scopes after it...
- match: (?i)\b(END\s*EVERY)\b(?=\s*)$
captures:
1: keyword.control.alan
pop: true
# ==========================
# END EVERY => ID and/or `.`
# ==========================
- match: (?i)\b(END\s*EVERY)\b\s* # <= must consume all whitespace!
captures:
1: keyword.control.alan
set:
- meta_content_scope: meta.class.alan
- include: class_tail_identifier
- include: terminator
- include: force_POP
terminator:
- match: '\.'
scope: punctuation.terminator.alan It might not be the best solution, but it doesn't have to either: I'm in the early stages of creating this syntax, and sometimes you just need to get the job done and carry on drafting — and things can turn out frustrating when you can't pinpoint what is breaking the expected behavior. Watchlist of Common Newbie-MistakesThe lesson I've learned from tackling with this problem is, which might help better understand which context(s) are causing the problem:
I've learned these small lessons the hard way, by running in circles for hours because I wasn't mind-tracking correctly the stack levels. Also, I struggled a lot with When starting to deal with lots of reusable contexts, and contexts nestings, it can quickly become a complex task to keep a clear mental picture of what is actually going on at the parser level. Unfortunately, we can't escape the unpleasant task of having to mentally track what RegEx patterns are capturing, consuming, discarding and how the various stacked contexts loop until they pop out. Surely, as experience in working with syntaxes starts to set it one eventually develops a right mind frame on how to start out laying the foundations of the syntax with the right foot. The problem is that if the whole experience gets frustrating and no solutions seems possible, one might just give in and never reach that required experience (after all, experience breeds on sucesses, as well as failures). A Syntax CLI Simulator/Debugger Would Be InvaluableAnother lesson I've learned: If ST had a way to expose to the user the syntax parser's stack state, its ques, and some debug info about the text being processed, the regexs matches and failures, it would be much easier to trace where our custom syntaxes fail. Any chance that (somewhere in the future) ST might also ship with a command line tool to debug syntax definitions? A console app that takes a syntax file and a source test-files as input and spits out two files: a scoped version of the souce file (an XML like doc tree) and a log file listing all the innerworkings of the parser engine. This would be an invaluable tool to both learn how to build syntaxes as well as to fix problems. Learning to create custom syntaxes should be a pleasant experience, not a frustrating one. The official documentation on the topic is not exactly "exhaustive" (far from it), and most existing syntaxes are usually too large to be used as learning examples to start with. Syntect: A Fallback Debugger@kingkeith (which I believe might be @keith-hall here on GitHub) pointed out to me the availability of syntect, a "Rust library for syntax highlighting using Sublime Text syntax definitions" which offers debugging features via its While there is no assurance that its syntax parser follows 100% that of ST (and small edge cases could cause difference in behavior), it seems to support ST syntax files very well, which means it can be a valuable tool for debugging syntaxes inner workings (pending a dedicate debug tool from ST3). |
I know that I ought not consume space in this thread for comments; but I can't refrain from thanking enough @djspiewak for his "Stateful Chaining" advise — after reading it I've managed to correct my syntax draft to handle code fragments without breaking the user experience (while before I was working on the assumption that all code would be always wellformed), and it allowed me to handle better the stack and reusable contexts. I really wish that I had found a link to this Issue in ST documentation on syntaxes — it would have saved me hours of attempts, and spared me stress-induced psychosomatic complications. I must thank @kingkeith for having brought it to my attention (and for kindly helping me out, along with @ThomSmith, to work my way through the empasses of my first big syntax creation). I'd also like to add a further tip on Stack POPping tricks. Stack Popping TricksI've found the tricks in this thread on how to pop out of the stack very useful, and I'd like to add another variant which I ended up needing in some contexts, and some comments to the RegEx. Force POPWherever included, this context will pop immediately. force_POP:
- match: ''
pop: true My understanding is that this is a RegEx that doesn't do anything (no match, no consumption) and always returns Else POPAs already mentioned above by @Thom1729 (equivalent to @djspiewak's else_POP:
- match: (?=\S)
pop: true this context is great as an "else" condition for popping out of a context that could loop forever. Unlike Its RegEx pattern matches nothing followed by non-whitespace — since it's a lookhead assertion, it doesn't consume anything either. My understanding is that it's just a lookahead operation carried out at the current position of the highlighter's buffer. Therefore, if there is some whitespace ahead this doesn't pop out. If my understanding is correct, the difference in behavior between this and End-of-Line POPI've come across some situation in which neither eol_POP:
- match: '$'
pop: true This is useful in situations when you need to pop your way out of the current context/Stack when the end of line is reached. Usually it works well with syntaxes where line breaks are not optional, and where a number of optional elements might follow; or just to handle incomplete code fragments.
|
Syntax Test FilesSyntax Test Files are a great functionality for automating syntax tests. Unfortunately, ST official documentation on the topic doesn't cover in depth Scope Selectors. While the examples are all there, I've found the following link to Textmate's documentation quite useful: Specifically, I've learned more about the syntax for excluding or grouping scope selectors, via documented examples. Testing Against Scope SpillingsI've learned how to use syntax files to check that scopes don't spill over to neighbouring elements and/or whitespace. For example, in this syntax example I'm defining a class in Alan language:
Where everything from While working on it, I had to deal with scopes that where eating up the trailing whitespace. I've learned to test for those spills using scope selectors subtraction:
The above test-file example snippet checks that the class name scope of Textmate's documentation on the topic states:
Testing Meta Scope ExitingAs a further example, I'll show how to test if the meta scope for the class has been duely exited when expected:
Here we're checking that everything up to the terminator dot (included) is scoped as Note that the following two scope selectors are equivalent:
... except that Also note that you can also test with carets (
... in the above example the |
Note that it's mostly pointless to check the "base" scope, unless you're embedding another syntax, so |
Thanks for the clarification @keith-hall , I didn't realize you could actually subtract without declaring a base scope. I'll edit the example to clarify this, but at the same time I think is worth leaving in the example also a full |
Changing Regex Mode in VariablesWhen declaring variables, don't use Making Variables AtomicRelated to the above, and I'm not sure if this has already been mentioned (I didn't find it with a quick search, but am on mobile and didn't try too hard), but it is also useful to wrap variable declarations in a non-capturing group, so that when referencing them with behavior like i.e. |
In addition to the suggestion to use Use the chomping indicator in block scalarsWhen using block scalars for your regular expressions, make it a habit to always use |
Syntax Tests: Use of & Operator in ScopesWhile working on syntax tests, I discovered an undocumented feature, i.e. that it's possible to use the
where without the I've found this rather useful, especially to keep same scopes aligned with themselves for easy reading the test sources. I wonder if there are other operators beside |
Syntax tests work with normal scope selectors and thus all its available operators. |
`push` followed by `include` statements were not working as expected, due to unconsumed white-space characters. See <https://forum.sublimetext.com/t/syntax-definitions-how-to-force-pop-out-of-the-stack/36376/4>. This patch implements one of the [sublimehq/Packages#757] advices, which is to use both a popping and pop-less versions of the same reusable context. See <sublimehq/Packages#757 (comment)> from @tajmone. Such "new" contexts will be annotated as `_expect-${POPLESS-CONTEXT-NAME}` in `Nftables`. It also fixes other usages of `force-pop`, that had ended up badly working.
Basically gleaned from sublimehq/Packages#757
Rule loop processing order within a contextAs the documentation states, "When a context has multiple patterns (rules), the leftmost one will be found.". It's also important to add that the rule loop is reset when the pattern (rule) matches. So with an example context like: line:
- match: A # 1
scope: meta.A
- match: B # 2
scope: meta.B and a line:
The parser will try rule So you can't think of rules as being processed unconditionally from top to bottom and assume, for example, that this would allow for matching tokens in a specific order by arranging the rules in a certain way. Rule handling around the beginning/end of the lineOnce all characters on the line are consumed, and there aren't any more characters to match on that line, the engine will run through the loop once again, matching against a special end-of-line "character". This character can't be explicitly consumed so the only way to get past it is to let the engine go through all the rules for it to be consumed (the rules can still match the end-of-line with patterns like Example: line:
- match: '$' # 1
scope: meta.eol
- match: 'A' # 2
scope: meta.A with line:
Engine steps:
|
Edit: This has turned out to be not true, as evident by the following syntax definition marking everything as
|
It would make sense to move these tips into a |
A good solution would be to create a project Wiki for this repository (see my proposal at #1522), and then move the tips into the Wiki. The advantage of using a Wiki is that it allows to organize the topics into multiple pages, and it can be set to be editable by anyone. The only downside I can think of is that although repo Wikis are repositories, only collaborators can push changes, so page editing by non-collaborators has to be done via the WebUI. Also worth mentioning, the following repository was recently (Mar. 2020) created to address scope naming guidelines: https://github.com/SublimeText/ScopeNamingGuidelines But as of today the project seems stale (three commits only). Another older (and stale) project along those lines: https://github.com/gwenzek/sublime-syntax-manifesto I think that using the Wiki of this project would be preferable, since this is an official ST repository, whereas third party repositories might not receive the same attention. |
Most scope naming "issues" are tagged with |
There was work in a pull request which I have just merged, if you want to check it out. It could definitely move faster, but it not meant to take the tips and advices of this issue here. Instead, I would rather add them to the community docs at https://github.com/sublimetext-io/docs.sublimetext.io in a more orderly fashion, or, as you suggested, as a page on the wiki here. I think that the cdocs would be more appropriate, since the tips apply to syntax definition development in general and not the default packages specifically. |
Use plural names for non-popping contexts and signgular for popping contexts. Plural makes clear an included context can handle multiple tokens without popping or setting away from current context. (It may push another context onto stack though. Singular makes clear the current context to be left as soon as a single token is matched, either by popping or setting another context onto stack. By doing so, context names such as Example 1 A literal-double-quoted-strings:
- match: \"
scope: punctuation.definition.string.begin
push: literal-double-quoted-string-body
literal-double-quoted-string-body:
- meta_include_prototype: false
- meta_scope: meta.string string.quoted.double
- match: \"
scope: punctuation.definition.string.end
pop: 1
- include: illegal-newline
- include: literal-string-escapes Example 2 The following context (singular) is to handle a single statement (method declaration) by matching each possible term one after another. member-maybe-method:
- meta_include_prototype: false
- match: ''
set:
- method-block
- method-attribute
- method-array-modifier
- method-signature
- method-modifier |
Use primarily (only) named contexts. Reasons:
When creating contexts ask your self, what you'd expect from a syntax if you'd need to inherit from it to create your own extended variant. Is it easy to override certain rules? Which contexts must exclude possible prototypes? ( Does your syntax support string interpolation? Can an inherited syntax easily implement it? |
Use variables for large lists of fixed tokens (builtin functions etc.), because
See: CSS.sublime-syntax for reference. |
- Split `JSON.sublime-syntax` into ... using inheritance: - `JSON (Basic).sublime-syntax` with `scope:source.json.basic` - `JSON.sublime-syntax` with `scope:source.json` - `JSONC.sublime-syntax` with `scope:source.json.jsonc` - `JSON5.sublime-syntax` with `scope:source.json.json5` - Although the base syntax does not define a `prototype`, we add `meta_include_prototype: false` to the base syntax, to prevent inheriting syntaxes from injecting rules. - make use of `variables` - Add many more file extensions for `JSON` and `JSONC` - Significantly extend tests to cover more parts of the syntaxes defined: - Split original test file into logical parts - Add indentation tests for: - `JSON`, `JSONC` - `mapping` (objects), `sequence` (arrays) - leave `JSON` headers in `Markdown` as json only, but split up fenced code blocks into `json` and `jsonc` to behave similarly to `GitHub Flavored Markdown` - fix tests for `meta.mapping meta.mapping.*` - make `mapping.*` contexts more modular - fix sublimehq#285 as requested by Jon - address sublimehq#757 and use tips to fix line comments for `JSONC` - address sublimehq#2430 and use sort-order as requested by deathaxe - address sublimehq#2852 and use tips to fix scopes of curly braces & square brackets in `JSON` Co-authored-by: Ashwin Shenoy <Ultra-Instinct-05@users.noreply.github.com> Co-authored-by: Jack Cherng <jfcherng@users.noreply.github.com> Co-authored-by: Janos Wortmann <jwortmann@users.noreply.github.com> Co-authored-by: Jon Skinner <jps@sublimetext.com> Co-authored-by: FichteFoll <FichteFoll@users.noreply.github.com> Co-authored-by: Keith Hall <keith-hall@users.noreply.github.com> Co-authored-by: Michael B. Lyons <michaelblyons@users.noreply.github.com> Co-authored-by: Rafał Chłodnicki <rchl@users.noreply.github.com> Co-authored-by: deathaxe <deathaxe@users.noreply.github.com>
- Split `JSON.sublime-syntax` into ... using inheritance: - `JSON (Basic).sublime-syntax` with `scope:source.json.basic` - `JSON.sublime-syntax` with `scope:source.json` - `JSONC.sublime-syntax` with `scope:source.json.jsonc` - `JSON5.sublime-syntax` with `scope:source.json.json5` - Although the base syntax does not define a `prototype`, we add `meta_include_prototype: false` to the base syntax, to prevent inheriting syntaxes from injecting rules. - make use of `variables` - Add many more file extensions for `JSON` and `JSONC` - Significantly extend tests to cover more parts of the syntaxes defined: - Split original test file into logical parts - Add indentation tests for: - `JSON`, `JSONC` - `mapping` (objects), `sequence` (arrays) - leave `JSON` headers in `Markdown` as json only, but split up fenced code blocks into `json` and `jsonc` to behave similarly to `GitHub Flavored Markdown` - fix tests for `meta.mapping meta.mapping.*` - make `mapping.*` contexts more modular - fix sublimehq#285 as requested by Jon - address sublimehq#757 and use tips to fix line comments for `JSONC` - address sublimehq#2430 and use sort-order as requested by deathaxe - address sublimehq#2852 and use tips to fix scopes of curly braces & square brackets in `JSON` Co-authored-by: Ashwin Shenoy <Ultra-Instinct-05@users.noreply.github.com> Co-authored-by: Jack Cherng <jfcherng@users.noreply.github.com> Co-authored-by: Janos Wortmann <jwortmann@users.noreply.github.com> Co-authored-by: Jon Skinner <jps@sublimetext.com> Co-authored-by: FichteFoll <FichteFoll@users.noreply.github.com> Co-authored-by: Keith Hall <keith-hall@users.noreply.github.com> Co-authored-by: Michael B. Lyons <michaelblyons@users.noreply.github.com> Co-authored-by: Rafał Chłodnicki <rchl@users.noreply.github.com> Co-authored-by: deathaxe <deathaxe@users.noreply.github.com>
- Split `JSON.sublime-syntax` into ... using inheritance: - `JSON (Basic).sublime-syntax` with `scope:source.json.basic` - `JSON.sublime-syntax` with `scope:source.json` - `JSONC.sublime-syntax` with `scope:source.json.jsonc` - `JSON5.sublime-syntax` with `scope:source.json.json5` - Although the base syntax does not define a `prototype`, we add `meta_include_prototype: false` to the base syntax, to prevent inheriting syntaxes from injecting rules. - make use of `variables` - Add many more file extensions for `JSON` and `JSONC` - Significantly extend tests to cover more parts of the syntaxes defined: - Split original test file into logical parts - Add indentation tests for: - `JSON`, `JSONC` - `mapping` (objects), `sequence` (arrays) - leave `JSON` headers in `Markdown` as json only, but split up fenced code blocks into `json` and `jsonc` to behave similarly to `GitHub Flavored Markdown` - fix tests for `meta.mapping meta.mapping.*` - make `mapping.*` contexts more modular - fix sublimehq#285 as requested by Jon - address sublimehq#757 and use tips to fix line comments for `JSONC` - address sublimehq#2430 and use sort-order as requested by deathaxe - address sublimehq#2852 and use tips to fix scopes of curly braces & square brackets in `JSON` Co-authored-by: Ashwin Shenoy <Ultra-Instinct-05@users.noreply.github.com> Co-authored-by: Jack Cherng <jfcherng@users.noreply.github.com> Co-authored-by: Janos Wortmann <jwortmann@users.noreply.github.com> Co-authored-by: Jon Skinner <jps@sublimetext.com> Co-authored-by: FichteFoll <FichteFoll@users.noreply.github.com> Co-authored-by: Keith Hall <keith-hall@users.noreply.github.com> Co-authored-by: Michael B. Lyons <michaelblyons@users.noreply.github.com> Co-authored-by: Rafał Chłodnicki <rchl@users.noreply.github.com> Co-authored-by: deathaxe <deathaxe@users.noreply.github.com>
- Split `JSON.sublime-syntax` into ... using inheritance: - `JSON (Basic).sublime-syntax` with `scope:source.json.basic` - `JSON.sublime-syntax` with `scope:source.json` - `JSONC.sublime-syntax` with `scope:source.json.jsonc` - `JSON5.sublime-syntax` with `scope:source.json.json5` - Although the base syntax does not define a `prototype`, we add `meta_include_prototype: false` to the base syntax, to prevent inheriting syntaxes from injecting rules. - make use of `variables` - Add many more file extensions for `JSON` and `JSONC` - Significantly extend tests to cover more parts of the syntaxes defined: - Split original test file into logical parts - Add indentation tests for: - `JSON`, `JSONC` - `mapping` (objects), `sequence` (arrays) - leave `JSON` headers in `Markdown` as json only, but split up fenced code blocks into `json` and `jsonc` to behave similarly to `GitHub Flavored Markdown` - fix tests for `meta.mapping meta.mapping.*` - make `mapping.*` contexts more modular - fix sublimehq#285 as requested by Jon - address sublimehq#757 and use tips to fix line comments for `JSONC` - address sublimehq#2430 and use sort-order as requested by deathaxe - address sublimehq#2852 and use tips to fix scopes of curly braces & square brackets in `JSON` Co-authored-by: Ashwin Shenoy <Ultra-Instinct-05@users.noreply.github.com> Co-authored-by: Jack Cherng <jfcherng@users.noreply.github.com> Co-authored-by: Janos Wortmann <jwortmann@users.noreply.github.com> Co-authored-by: Jon Skinner <jps@sublimetext.com> Co-authored-by: FichteFoll <FichteFoll@users.noreply.github.com> Co-authored-by: Keith Hall <keith-hall@users.noreply.github.com> Co-authored-by: Michael B. Lyons <michaelblyons@users.noreply.github.com> Co-authored-by: Rafał Chłodnicki <rchl@users.noreply.github.com> Co-authored-by: deathaxe <deathaxe@users.noreply.github.com>
- Split `JSON.sublime-syntax` into ... using inheritance: - `JSON (Basic).sublime-syntax` with `scope:source.json.basic` - `JSON.sublime-syntax` with `scope:source.json` - `JSONC.sublime-syntax` with `scope:source.json.jsonc` - `JSON5.sublime-syntax` with `scope:source.json.json5` - Although the base syntax does not define a `prototype`, we add `meta_include_prototype: false` to the base syntax, to prevent inheriting syntaxes from injecting rules. - make use of `variables` - Add many more file extensions for `JSON` and `JSONC` - Significantly extend tests to cover more parts of the syntaxes defined: - Split original test file into logical parts - Add indentation tests for: - `JSON`, `JSONC` - `mapping` (objects), `sequence` (arrays) - leave `JSON` headers in `Markdown` as json only, but split up fenced code blocks into `json` and `jsonc` to behave similarly to `GitHub Flavored Markdown` - fix tests for `meta.mapping meta.mapping.*` - make `mapping.*` contexts more modular - fix sublimehq#285 as requested by Jon - address sublimehq#757 and use tips to fix line comments for `JSONC` - address sublimehq#2430 and use sort-order as requested by deathaxe - address sublimehq#2852 and use tips to fix scopes of curly braces & square brackets in `JSON` Co-authored-by: Ashwin Shenoy <Ultra-Instinct-05@users.noreply.github.com> Co-authored-by: Jack Cherng <jfcherng@users.noreply.github.com> Co-authored-by: Janos Wortmann <jwortmann@users.noreply.github.com> Co-authored-by: Jon Skinner <jps@sublimetext.com> Co-authored-by: FichteFoll <FichteFoll@users.noreply.github.com> Co-authored-by: Keith Hall <keith-hall@users.noreply.github.com> Co-authored-by: Michael B. Lyons <michaelblyons@users.noreply.github.com> Co-authored-by: Rafał Chłodnicki <rchl@users.noreply.github.com> Co-authored-by: deathaxe <deathaxe@users.noreply.github.com>
- Using inheritance split up `JSON.sublime-syntax` into: - `JSON (Basic).sublime-syntax` with `scope:source.json.basic` - `JSON.sublime-syntax` with `scope:source.json` - `JSONC.sublime-syntax` with `scope:source.json.jsonc` - `JSON5.sublime-syntax` with `scope:source.json.json5` - Add many more file extensions for `JSON` & `JSONC`: - add doc links to exensions where applicable as a reference to be able to more quickly verify that they (still) use said syntax flavor - Add JSON5 with support for: - explicitly pos numbers, hexadecimal ints, Infinity and NaN - single quoted strings - more escape chars for strings - Only allow objects or arrays at the top level - add `meta.toc-list` scope to top level object keys to add them to the symbol list (also add tests, see below) - Make use of newer syntax features including those only available in `version: 2` syntaxes - Make use of `variables` - Highlighting speed improvements for empty objects and empty arrays - Significantly improve number highlighting - Correctly scope number signs with `constant.numeric.sign` instead of `keyword.operator.arithmetic` - Significantly extend tests to cover more parts of the syntaxes defined: - Split original test file into logical parts - Add indentation tests for: - `json`, `jsonc` & `json5` - `mapping` (objects), `sequence` (arrays) - Add symbols tests for: - scope: `meta.toc-list.json | meta.toc-list.json5` - languages: `json`, `jsonc` & `json5` - Fix tests for `meta.mapping meta.mapping.*` - Make `mapping.*` contexts more modular - Leave `JSON` headers in `Markdown` as `json` only, but split up fenced code blocks into `json`, `jsonc` & `json5` to behave similarly to `GitHub Flavored Markdown` BREAKING CHANGES: - scopes for number signs have changed from being `keyword.operator.arithmetic` to `constant.numeric.sign` - fix sublimehq#285 as requested by Jon - address sublimehq#757 using tips to fix line comments for `JSONC` - address sublimehq#2430 using sort-order as requested by deathaxe - address sublimehq#2852 using tips to fix scopes of curly braces & square brackets in `JSON` Co-authored-by: Ashwin Shenoy <Ultra-Instinct-05@users.noreply.github.com> Co-authored-by: Jack Cherng <jfcherng@users.noreply.github.com> Co-authored-by: Janos Wortmann <jwortmann@users.noreply.github.com> Co-authored-by: Jon Skinner <jps@sublimetext.com> Co-authored-by: FichteFoll <FichteFoll@users.noreply.github.com> Co-authored-by: Keith Hall <keith-hall@users.noreply.github.com> Co-authored-by: Michael B. Lyons <michaelblyons@users.noreply.github.com> Co-authored-by: Rafał Chłodnicki <rchl@users.noreply.github.com> Co-authored-by: deathaxe <deathaxe@users.noreply.github.com>
- Using inheritance split up `JSON.sublime-syntax` into: - `JSON (Basic).sublime-syntax` with `scope:source.json.basic` - `JSON.sublime-syntax` with `scope:source.json` - `JSONC.sublime-syntax` with `scope:source.json.jsonc` - `JSON5.sublime-syntax` with `scope:source.json.json5` - Add many more file extensions for `JSON` & `JSONC`: - add doc links to exensions where applicable as a reference to be able to more quickly verify that they (still) use said syntax flavor - Add JSON5 with support for: - explicitly pos numbers, hexadecimal ints, Infinity and NaN - single quoted strings - more escape chars for strings - Only allow objects or arrays at the top level - add `meta.toc-list` scope to top level object keys to add them to the symbol list (also add tests, see below) - Make use of newer syntax features including those only available in `version: 2` syntaxes - Make use of `variables` - Highlighting speed improvements for empty objects and empty arrays - Significantly improve number highlighting - Correctly scope number signs with `constant.numeric.sign` instead of `keyword.operator.arithmetic` - Significantly extend tests to cover more parts of the syntaxes defined: - Split original test file into logical parts - Add indentation tests for: - `json`, `jsonc` & `json5` - `mapping` (objects), `sequence` (arrays) - Add symbols tests for: - scope: `meta.toc-list.json | meta.toc-list.json5` - languages: `json`, `jsonc` & `json5` - Fix tests for `meta.mapping meta.mapping.*` - Make `mapping.*` contexts more modular - Leave `JSON` headers in `Markdown` as `json` only, but split up fenced code blocks into `json`, `jsonc` & `json5` to behave similarly to `GitHub Flavored Markdown` BREAKING CHANGES: - scopes for number signs have changed from being `keyword.operator.arithmetic` to `constant.numeric.sign` - fix sublimehq#285 as requested by Jon - address sublimehq#757 using tips to fix line comments for `JSONC` - address sublimehq#2430 using sort-order as requested by deathaxe - address sublimehq#2852 using tips to fix scopes of curly braces & square brackets in `JSON` Co-authored-by: Ashwin Shenoy <Ultra-Instinct-05@users.noreply.github.com> Co-authored-by: Jack Cherng <jfcherng@users.noreply.github.com> Co-authored-by: Janos Wortmann <jwortmann@users.noreply.github.com> Co-authored-by: Jon Skinner <jps@sublimetext.com> Co-authored-by: FichteFoll <FichteFoll@users.noreply.github.com> Co-authored-by: Keith Hall <keith-hall@users.noreply.github.com> Co-authored-by: Michael B. Lyons <michaelblyons@users.noreply.github.com> Co-authored-by: Rafał Chłodnicki <rchl@users.noreply.github.com> Co-authored-by: deathaxe <deathaxe@users.noreply.github.com>
- Using inheritance split up `JSON.sublime-syntax` into: - `JSON (Basic).sublime-syntax` with `scope:source.json.basic` - `JSON.sublime-syntax` with `scope:source.json` - `JSONC.sublime-syntax` with `scope:source.json.jsonc` - `JSON5.sublime-syntax` with `scope:source.json.json5` - Add many more file extensions for `JSON` & `JSONC`: - add doc links to extensions where applicable as a reference to be able to more quickly verify that they (still) use said syntax flavor - JSON: - (correctly formatted) JSON code can now be prettified or minified via the context menu or the command palette - highlight leading, trailing & multiple commas as invalid - only allow exactly one structure (object, array) or value (constant, number, string) at top level (thanks to Keith) - JSONC: - highlight some files by default as `JSONC` (as decided by Jon in sublimehq#285) - highlight leading & multiple commas as invalid, trailing as valid - JSON5: - explicitly pos numbers, hexadecimal ints, Infinity and NaN - single quoted strings - more escape chars for strings - ECMA identifierName as object keys (thanks to Thomas) - scoped as plain unquoted strings - line continuation in strings (with tests thanks to Keith) - Objects: - Add `meta.toc-list` scope to top level object keys to add them to the symbol list (also add tests, see below) - Highlighting speed improvements for empty objects (thanks to FichteFoll) - Make `mapping.*` contexts more modular - Arrays: - Highlighting speed improvements for empty arrays (thanks to FichteFoll) - Numbers: - Correctly scope number signs with `constant.numeric.sign` instead of `keyword.operator.arithmetic` - Significantly improve number highlighting (thanks to deathaxe) - Syntaxes: - Make use of newer syntax features including those only available in `version: 2` syntaxes - Make use of `variables` (with optimizations provided by deathaxe and regex patterns provided by Thomas) - Tests: - Significantly extend tests to cover more parts of the syntaxes defined. - Split original test file into logical parts - Add indentation tests for: - `json`, `jsonc` & `json5` - `mapping` (objects), `sequence` (arrays) - Add symbols tests for: - scope: `meta.toc-list.json | meta.toc-list.json5` - languages: `json`, `jsonc` & `json5` - Fix tests for `meta.mapping meta.mapping.*` - Leave `JSON` headers in `Markdown` as `json` only, but split up fenced code blocks into `json`, `jsonc` & `json5` to behave similarly to `GitHub Flavored Markdown` BREAKING CHANGES: - JSON does not have values that can be set via an inline calculation with the help of operators, but only simple number values. Scopes for number signs have changed from being `keyword.operator.arithmetic` to `constant.numeric.sign`. Color scheme authors should add this, should it be missing. - The `JSON.sublime-syntax` now marks comments as `invalid`, third party plugin authors should target `JSONC.sublime-syntax` instead to have the same user experience as before. - fix sublimehq#285 - address sublimehq#481 to remove incompatible regex patterns according to Will - address sublimehq#757 to fix line comments for `JSONC` (thanks to Keith) - address sublimehq#2430 using sort-order (as requested by deathaxe) - address sublimehq#2852 to fix scopes of curly braces & square brackets in `JSON` (thanks to Thomas) - address sublimehq/sublime_text#3154 and add symbol tests Co-authored-by: Ashwin Shenoy <Ultra-Instinct-05@users.noreply.github.com> Co-authored-by: Jack Cherng <jfcherng@users.noreply.github.com> Co-authored-by: Janos Wortmann <jwortmann@users.noreply.github.com> Co-authored-by: Jon Skinner <jps@sublimetext.com> Co-authored-by: FichteFoll <FichteFoll@users.noreply.github.com> Co-authored-by: Keith Hall <keith-hall@users.noreply.github.com> Co-authored-by: Michael B. Lyons <michaelblyons@users.noreply.github.com> Co-authored-by: Rafał Chłodnicki <rchl@users.noreply.github.com> Co-authored-by: Thomas Smith <Thom1729@users.noreply.github.com> Co-authored-by: Will Bond <wbond@users.noreply.github.com> Co-authored-by: deathaxe <deathaxe@users.noreply.github.com>
- Using inheritance split up `JSON.sublime-syntax` into: - `JSON.sublime-syntax` with `scope:source.json` - `JSONC.sublime-syntax` with `scope:source.json.jsonc` - `JSON5.sublime-syntax` with `scope:source.json.json5` - `JSON_dotNET.sublime-syntax` with `scope:source.json.json-dotnet` - Add many more file extensions for `JSON` & `JSONC`: - add doc links to extensions where applicable as a reference to be able to more quickly verify that they (still) use said syntax flavor - JSON: - Make use of newer syntax features including those only available in `version: 2` syntaxes - Make use of `variables` (with optimizations provided by @deathaxe and regex patterns provided by @Thom1729) - Context names now more closely match the naming scheme of other (recently re-written) default syntaxes - (correctly formatted) JSON code can now be prettified or minified via the context menu or the command palette. JSON code can optionally be auto-prettified on pre save events. - highlight leading, trailing & multiple commas as invalid - only allow exactly one structure (object, array) or value (constant, number, string) at top level (thanks to @keith-hall) - links (`meta.link.inet`) and email addresses (`meta.link.email`) are scoped the same as in Markdown (thanks to @deathaxe) - JSONC: - highlight some files by default as `JSONC` (as decided by @jskinner in sublimehq#285) - highlight leading & multiple commas as invalid, trailing as valid - scope empty block comments as such - support syntax based folding of ST4131+, compare sublimehq#3291 - JSON5: - explicitly pos numbers, hexadecimal ints, Infinity and NaN - single quoted strings - more escape chars for strings - ECMA identifierName as object keys (regexes thanks to @Thom1729) - scoped as plain unquoted strings (thanks to @Thom1729) - support string interpolation (thanks to @deathaxe) - line continuation in strings (with tests thanks to @keith-hall) - JSON.NET: - support requested by @keith-hall, built with feedback from @michaelblyons - Objects: - Highlighting speed improvements for empty objects (thanks to @FichteFoll) - Make `mapping.*` contexts more modular - Arrays: - Highlighting speed improvements for empty arrays (thanks to @FichteFoll) - Numbers: - Correctly scope number signs with `constant.numeric.sign` instead of `keyword.operator.arithmetic` - Significantly improve number highlighting (thanks to @deathaxe) - Completions: - completions have been added for language constants, including kind info and details (with links to docs) - `null`, `false`, `true` for JSON - `Infinity` and `NaN` for JSON5 - Settings: - a `default_extension` is now set for all JSON flavors - Symbol index: - with an object structure at the top-level, only top-level keys within now show up in the index (including tests for symbols and syntax) - Tests: - test files now test the base scope - Significantly extend tests to cover more parts of the syntaxes - Split original test file into logical parts - Add indentation tests for: - `json`, `json5` & `jsonc` - `mapping` (objects), `sequence` (arrays) - Add symbols tests for: - top-level keys of object structures (thanks to deathaxe) - languages: `json`, `json5` & `jsonc` - Fix tests for `meta.mapping meta.mapping.*` - Leave `JSON` headers in `Markdown` as `json` only, but split up fenced code blocks into `json`, `json5` & `jsonc` to behave similarly to `GitHub Flavored Markdown` BREAKING CHANGES: - JSON does not have values that can be set via an inline calculation with the help of operators, but only simple number values. Scopes for number signs have changed from being `keyword.operator.arithmetic` to `constant.numeric.sign`. Color scheme authors should add this, should it be missing. - The `JSON.sublime-syntax` now marks comments as `invalid`, third party plugin authors should instead target `JSONC.sublime-syntax` to keep the user experience as-is. - Indexed symbols (i.e. top-level keys in JSON object structures) are scoped as `source.json meta.mapping.key - (meta.mapping.value meta.mapping.key | meta.sequence.list meta.mapping.key)`. Color scheme authors should add special highlighting to differentiate them from other keys. - fix sublimehq#285 - address sublimehq#421 (thanks to @FichteFoll) - address sublimehq#481 to remove incompatible regex patterns according to @wbond - address sublimehq#757 to fix line comments for `JSONC` (thanks to @keith-hall) - address sublimehq#2430 using sort-order (as requested by @deathaxe) - address sublimehq#2711 with regards to `constant.language.null` vs. `constant.language.empty` (thanks to @FichteFoll) - address sublimehq#2852 to fix scopes of curly braces & square brackets in `JSON` (thanks to @Thom1729) - address sublimehq#3228 to fix `punctuation.separator` scopes, compare sublimehq#3270 - address sublimehq/sublime_text#3154 and add symbol tests Co-authored-by: Ashwin Shenoy <Ultra-Instinct-05@users.noreply.github.com> Co-authored-by: Jack Cherng <jfcherng@users.noreply.github.com> Co-authored-by: Janos Wortmann <jwortmann@users.noreply.github.com> Co-authored-by: Jon Skinner <jps@sublimetext.com> Co-authored-by: FichteFoll <FichteFoll@users.noreply.github.com> Co-authored-by: Keith Hall <keith-hall@users.noreply.github.com> Co-authored-by: Michael B. Lyons <michaelblyons@users.noreply.github.com> Co-authored-by: Rafał Chłodnicki <rchl@users.noreply.github.com> Co-authored-by: Thomas Smith <Thom1729@users.noreply.github.com> Co-authored-by: Will Bond <wbond@users.noreply.github.com> Co-authored-by: deathaxe <deathaxe@users.noreply.github.com>
- Using inheritance split up `JSON.sublime-syntax` into: - `JSON.sublime-syntax` with `scope:source.json` - `JSONC.sublime-syntax` with `scope:source.json.jsonc` - `JSON5.sublime-syntax` with `scope:source.json.json5` - `JSON_dotNET.sublime-syntax` with `scope:source.json.json-dotnet` - Add many more file extensions for `JSON` & `JSONC`: - add doc links to extensions where applicable as a reference to be able to more quickly verify that they (still) use said syntax flavor - JSON: - Make use of newer syntax features including those only available in `version: 2` syntaxes - Make use of `variables` (with optimizations provided by @deathaxe and regex patterns provided by @Thom1729) - Context names now more closely match the naming scheme of other (recently re-written) default syntaxes - (correctly formatted) JSON code can now be prettified or minified via the context menu or the command palette. JSON code can optionally be auto-prettified on pre save events. - highlight leading, trailing & multiple commas as invalid - only allow exactly one structure (object, array) or value (constant, number, string) at top level (thanks to @keith-hall) - links (`meta.link.inet`) and email addresses (`meta.link.email`) are scoped the same as in Markdown (thanks to @deathaxe) - JSONC: - highlight some files by default as `JSONC` (as decided by @jskinner in sublimehq#285) - highlight leading & multiple commas as invalid, trailing as valid - scope empty block comments as such - support syntax based folding of ST4131+, compare sublimehq#3291 - JSON5: - explicitly pos numbers, hexadecimal ints, Infinity and NaN - single quoted strings - more escape chars for strings - ECMA identifierName as object keys (regexes thanks to @Thom1729) - scoped as plain unquoted strings (thanks to @Thom1729) - support string interpolation (thanks to @deathaxe) - line continuation in strings (with tests thanks to @keith-hall) - JSON.NET: - support requested by @keith-hall, built with feedback from @michaelblyons - Objects: - Highlighting speed improvements for empty objects (thanks to @FichteFoll) - Make `mapping.*` contexts more modular - Arrays: - Highlighting speed improvements for empty arrays (thanks to @FichteFoll) - Numbers: - Correctly scope number signs with `constant.numeric.sign` instead of `keyword.operator.arithmetic` - Significantly improve number highlighting (thanks to @deathaxe) - Completions: - completions have been added for language constants, including kind info and details (with links to docs) - `null`, `false`, `true` for JSON - `Infinity` and `NaN` for JSON5 - Settings: - a `default_extension` is now set for all JSON flavors - Symbol index: - with an object structure at the top-level, only top-level keys within now show up in the index (including tests for symbols and syntax) - Tests: - test files now test the base scope - Significantly extend tests to cover more parts of the syntaxes - Split original test file into logical parts - Add indentation tests for: - `json`, `json5` & `jsonc` - `mapping` (objects), `sequence` (arrays) - Add symbols tests for: - top-level keys of object structures (thanks to deathaxe) - languages: `json`, `json5` & `jsonc` - Fix tests for `meta.mapping meta.mapping.*` - Leave `JSON` headers in `Markdown` as `json` only, but split up fenced code blocks into `json`, `json5` & `jsonc` to behave similarly to `GitHub Flavored Markdown` BREAKING CHANGES: - JSON does not have values that can be set via an inline calculation with the help of operators, but only simple number values. Scopes for number signs have changed from being `keyword.operator.arithmetic` to `constant.numeric.sign`. Color scheme authors should add this, should it be missing. - The `JSON.sublime-syntax` now marks comments as `invalid`, third party plugin authors should instead target `JSONC.sublime-syntax` to keep the user experience as-is. - Indexed symbols (i.e. top-level keys in JSON object structures) are scoped as `source.json meta.mapping.key - (meta.mapping.value meta.mapping.key | meta.sequence.list meta.mapping.key)`. Color scheme authors should add special highlighting to differentiate them from other keys. - fix sublimehq#285 - address sublimehq#421 (thanks to @FichteFoll) - address sublimehq#481 to remove incompatible regex patterns according to @wbond - address sublimehq#757 to fix line comments for `JSONC` (thanks to @keith-hall) - address sublimehq#2430 using sort-order (as requested by @deathaxe) - address sublimehq#2711 with regards to `constant.language.null` vs. `constant.language.empty` (thanks to @FichteFoll) - address sublimehq#2852 to fix scopes of curly braces & square brackets in `JSON` (thanks to @Thom1729) - address sublimehq#3228 to fix `punctuation.separator` scopes, compare sublimehq#3270 - address sublimehq/sublime_text#3154 and add symbol tests Co-authored-by: Ashwin Shenoy <Ultra-Instinct-05@users.noreply.github.com> Co-authored-by: Jack Cherng <jfcherng@users.noreply.github.com> Co-authored-by: Janos Wortmann <jwortmann@users.noreply.github.com> Co-authored-by: Jon Skinner <jps@sublimetext.com> Co-authored-by: FichteFoll <FichteFoll@users.noreply.github.com> Co-authored-by: Keith Hall <keith-hall@users.noreply.github.com> Co-authored-by: Michael B. Lyons <michaelblyons@users.noreply.github.com> Co-authored-by: Rafał Chłodnicki <rchl@users.noreply.github.com> Co-authored-by: Thomas Smith <Thom1729@users.noreply.github.com> Co-authored-by: Will Bond <wbond@users.noreply.github.com> Co-authored-by: deathaxe <deathaxe@users.noreply.github.com>
- Using inheritance split up `JSON.sublime-syntax` into: - `JSON.sublime-syntax` with `scope:source.json` - `JSONC.sublime-syntax` with `scope:source.json.jsonc` - `JSON5.sublime-syntax` with `scope:source.json.json5` - `JSON_dotNET.sublime-syntax` with `scope:source.json.json-dotnet` - Add many more file extensions for `JSON` & `JSONC`: - add doc links to extensions where applicable as a reference to be able to more quickly verify that they (still) use said syntax flavor - JSON: - Make use of newer syntax features including those only available in `version: 2` syntaxes - Make use of `variables` (with optimizations provided by @deathaxe and regex patterns provided by @Thom1729) - Context names now more closely match the naming scheme of other (recently re-written) default syntaxes - (correctly formatted) JSON code can now be prettified or minified via the context menu or the command palette. JSON code can optionally be auto-prettified on pre save events. - highlight leading, trailing & multiple commas as invalid - only allow exactly one structure (object, array) or value (constant, number, string) at top level (thanks to @keith-hall) - links (`meta.link.inet`) and email addresses (`meta.link.email`) are scoped the same as in Markdown (thanks to @deathaxe) - JSONC: - highlight some files by default as `JSONC` (as decided by @jskinner in sublimehq#285) - highlight leading & multiple commas as invalid, trailing as valid - scope empty block comments as such - support syntax based folding of ST4131+, compare sublimehq#3291 - JSON5: - explicitly pos numbers, hexadecimal ints, Infinity and NaN - single quoted strings - more escape chars for strings - ECMA identifierName as object keys (regexes thanks to @Thom1729) - scoped as plain unquoted strings (thanks to @Thom1729) - support string interpolation (thanks to @deathaxe) - line continuation in strings (with tests thanks to @keith-hall) - JSON.NET: - support requested by @keith-hall, built with feedback from @michaelblyons - Objects: - Highlighting speed improvements for empty objects (thanks to @FichteFoll) - Make `mapping.*` contexts more modular - Arrays: - Highlighting speed improvements for empty arrays (thanks to @FichteFoll) - Numbers: - Correctly scope number signs with `constant.numeric.sign` instead of `keyword.operator.arithmetic` - Significantly improve number highlighting (thanks to @deathaxe) - Completions: - completions have been added for language constants, including kind info and details (with links to docs) - `null`, `false`, `true` for JSON - `Infinity` and `NaN` for JSON5 - Settings: - a `default_extension` is now set for all JSON flavors - Symbol index: - with an object structure at the top-level, only top-level keys within now show up in the index (including tests for symbols and syntax) - Tests: - test files now test the base scope - Significantly extend tests to cover more parts of the syntaxes - Split original test file into logical parts - Add indentation tests for: - `json`, `json5` & `jsonc` - `mapping` (objects), `sequence` (arrays) - Add symbols tests for: - top-level keys of object structures (thanks to deathaxe) - languages: `json`, `json5` & `jsonc` - Fix tests for `meta.mapping meta.mapping.*` - Leave `JSON` headers in `Markdown` as `json` only, but split up fenced code blocks into `json`, `json5` & `jsonc` to behave similarly to `GitHub Flavored Markdown` BREAKING CHANGES: - JSON does not have values that can be set via an inline calculation with the help of operators, but only simple number values. Scopes for number signs have changed from being `keyword.operator.arithmetic` to `constant.numeric.sign`. Color scheme authors should add this, should it be missing. - The `JSON.sublime-syntax` now marks comments as `invalid`, third party plugin authors should instead target `JSONC.sublime-syntax` to keep the user experience as-is. - Indexed symbols (i.e. top-level keys in JSON object structures) are scoped as `source.json meta.mapping.key - (meta.mapping.value meta.mapping.key | meta.sequence.list meta.mapping.key)`. Color scheme authors should add special highlighting to differentiate them from other keys. - fix sublimehq#285 - address sublimehq#421 (thanks to @FichteFoll) - address sublimehq#481 to remove incompatible regex patterns according to @wbond - address sublimehq#757 to fix line comments for `JSONC` (thanks to @keith-hall) - address sublimehq#2430 using sort-order (as requested by @deathaxe) - address sublimehq#2711 with regards to `constant.language.null` vs. `constant.language.empty` (thanks to @FichteFoll) - address sublimehq#2852 to fix scopes of curly braces & square brackets in `JSON` (thanks to @Thom1729) - address sublimehq#3228 to fix `punctuation.separator` scopes, compare sublimehq#3270 - address sublimehq/sublime_text#3154 and add symbol tests Co-authored-by: Ashwin Shenoy <Ultra-Instinct-05@users.noreply.github.com> Co-authored-by: Jack Cherng <jfcherng@users.noreply.github.com> Co-authored-by: Janos Wortmann <jwortmann@users.noreply.github.com> Co-authored-by: Jon Skinner <jps@sublimetext.com> Co-authored-by: FichteFoll <FichteFoll@users.noreply.github.com> Co-authored-by: Keith Hall <keith-hall@users.noreply.github.com> Co-authored-by: Michael B. Lyons <michaelblyons@users.noreply.github.com> Co-authored-by: Rafał Chłodnicki <rchl@users.noreply.github.com> Co-authored-by: Thomas Smith <Thom1729@users.noreply.github.com> Co-authored-by: Will Bond <wbond@users.noreply.github.com> Co-authored-by: deathaxe <deathaxe@users.noreply.github.com>
- Using inheritance split up `JSON.sublime-syntax` into: - `JSON.sublime-syntax` with `scope:source.json` - `JSONC.sublime-syntax` with `scope:source.json.jsonc` - `JSON5.sublime-syntax` with `scope:source.json.json5` - `JSON_dotNET.sublime-syntax` with `scope:source.json.json-dotnet` - Add many more file extensions for `JSON` & `JSONC`: - add doc links to extensions where applicable as a reference to be able to more quickly verify that they (still) use said syntax flavor - JSON: - Make use of newer syntax features including those only available in `version: 2` syntaxes - Make use of `variables` (with optimizations provided by @deathaxe and regex patterns provided by @Thom1729) - Context names now more closely match the naming scheme of other (recently re-written) default syntaxes - (correctly formatted) JSON code can now be prettified or minified via the context menu or the command palette. JSON code can optionally be auto-prettified on pre save events. - highlight leading, trailing & multiple commas as invalid - only allow exactly one structure (object, array) or value (constant, number, string) at top level (thanks to @keith-hall) - links (`meta.link.inet`) and email addresses (`meta.link.email`) are scoped the same as in Markdown (thanks to @deathaxe) - JSONC: - highlight some files by default as `JSONC` (as decided by @jskinner in sublimehq#285) - highlight leading & multiple commas as invalid, trailing as valid - scope empty block comments as such - support syntax based folding of ST4131+, compare sublimehq#3291 - JSON5: - explicitly pos numbers, hexadecimal ints, Infinity and NaN - single quoted strings - more escape chars for strings - ECMA identifierName as object keys (regexes thanks to @Thom1729) - scoped as plain unquoted strings (thanks to @Thom1729) - support string interpolation (thanks to @deathaxe) - line continuation in strings (with tests thanks to @keith-hall) - JSON.NET: - support requested by @keith-hall, built with feedback from @michaelblyons - Objects: - Highlighting speed improvements for empty objects (thanks to @FichteFoll) - Make `mapping.*` contexts more modular - Arrays: - Highlighting speed improvements for empty arrays (thanks to @FichteFoll) - Numbers: - Correctly scope number signs with `constant.numeric.sign` instead of `keyword.operator.arithmetic` - Significantly improve number highlighting (thanks to @deathaxe) - Completions: - completions have been added for language constants, including kind info and details (with links to docs) - `null`, `false`, `true` for JSON - `Infinity` and `NaN` for JSON5 - Settings: - a `default_extension` is now set for all JSON flavors - Symbol index: - with an object structure at the top-level, only top-level keys within now show up in the index (including tests for symbols and syntax) - Tests: - test files now test the base scope - Significantly extend tests to cover more parts of the syntaxes - Split original test file into logical parts - Add indentation tests for: - `json`, `json5` & `jsonc` - `mapping` (objects), `sequence` (arrays) - Add symbols tests for: - top-level keys of object structures (thanks to deathaxe) - languages: `json`, `json5` & `jsonc` - Fix tests for `meta.mapping meta.mapping.*` - Leave `JSON` headers in `Markdown` as `json` only, but split up fenced code blocks into `json`, `json5` & `jsonc` to behave similarly to `GitHub Flavored Markdown` BREAKING CHANGES: - JSON does not have values that can be set via an inline calculation with the help of operators, but only simple number values. Scopes for number signs have changed from being `keyword.operator.arithmetic` to `constant.numeric.sign`. Color scheme authors should add this, should it be missing. - The `JSON.sublime-syntax` now marks comments as `invalid`, third party plugin authors should instead target `JSONC.sublime-syntax` to keep the user experience as-is. - Indexed symbols (i.e. top-level keys in JSON object structures) are scoped as `source.json meta.mapping.key - (meta.mapping.value meta.mapping.key | meta.sequence.list meta.mapping.key)`. Color scheme authors should add special highlighting to differentiate them from other keys. - fix sublimehq#285 - address sublimehq#421 (thanks to @FichteFoll) - address sublimehq#481 to remove incompatible regex patterns according to @wbond - address sublimehq#757 to fix line comments for `JSONC` (thanks to @keith-hall) - address sublimehq#2430 using sort-order (as requested by @deathaxe) - address sublimehq#2711 with regards to `constant.language.null` vs. `constant.language.empty` (thanks to @FichteFoll) - address sublimehq#2852 to fix scopes of curly braces & square brackets in `JSON` (thanks to @Thom1729) - address sublimehq#3228 to fix `punctuation.separator` scopes, compare sublimehq#3270 - address sublimehq/sublime_text#3154 and add symbol tests Co-authored-by: Ashwin Shenoy <Ultra-Instinct-05@users.noreply.github.com> Co-authored-by: Jack Cherng <jfcherng@users.noreply.github.com> Co-authored-by: Janos Wortmann <jwortmann@users.noreply.github.com> Co-authored-by: Jon Skinner <jps@sublimetext.com> Co-authored-by: FichteFoll <FichteFoll@users.noreply.github.com> Co-authored-by: Keith Hall <keith-hall@users.noreply.github.com> Co-authored-by: Michael B. Lyons <michaelblyons@users.noreply.github.com> Co-authored-by: Rafał Chłodnicki <rchl@users.noreply.github.com> Co-authored-by: Thomas Smith <Thom1729@users.noreply.github.com> Co-authored-by: Will Bond <wbond@users.noreply.github.com> Co-authored-by: deathaxe <deathaxe@users.noreply.github.com>
If you've spent some time writing syntaxes, take a moment here and share any revelations you've had, or tips on this to test or look for.
The text was updated successfully, but these errors were encountered: