Replies: 2 comments 2 replies
-
Good!
Yes!
I would suggest not to do that, unless you develop a plugin for a specific domain with known rules.
Good question. I completely forgot to include this point in the specification. Will do that soon.
Yes, these should be treated as invalid.
Yes. BTW: It would be useful to assign a different scope/color to extension nodes (whose names are prefixed with
Great!
That's very cool, indeed! Supports the DRY principle.
Awesome.
That's unfortunate, indeed. Maybe it's better to first provide this kind of extensions for VSCode, for the simple reason that more people use VSCode than ST.
|
Beta Was this translation helpful? Give feedback.
-
This is now specified. |
Beta Was this translation helpful? Give feedback.
-
@pdml-lang, I wanted to share with you some thoughts on the PDML package, its design and potential features.
Most of the considerations found here apply to any modern editor for which we could build a PDML syntax.
Basic vs Advanced Scoping
In my first Syntax draft, I tried to treat the PDML syntax as JSON, using the
meta
scopes for key-value mappings. This is how the syntax test looked like in commit cc37bbf:The scopes
meta.mapping
,meta.mapping.key
andmeta.mapping.value
were borrowed from the way the native JSON syntax uses them.Initially, I started looking at how ST handles JSON, XML and YAML, in order to gain insight on how these different syntax are handled, since they all relate to PDML somehow.
Below are the summary findings on how these three syntaxes get scoped, with some comments on the pros and cons of each approach.
Native JSON Syntax Example
This pseudo-test illustrates how ST's natively scopes JSON:
Note how nesting works: complex values are always inside
meta.mapping.value
, since they are part of the value of their parent key, someta.mapping.*
scopes stack up.I'm not entirely sure what the practical benefits of these scopes are, but I guess that they allow advanced manipulation via plug-ins, finer control over auto-completions, snippets, etc., and possibly affect interactions with settings (these being the two reasons and goals behind
meta
scopes).In any case, JSON (actually jsonc, JSON with Comments) is one of ST's natively employed settings formats, so I'm pretty sure there are valid reasons behind these scopes — and probably by looking into the ST native plug-ins we'll see them referenced too.
Native XML Syntax Example
XML is treated quite differently from JSON, as you can see from the pseudo-test below:
There isn't a distinction between opening and closing tags, and tags contents don't receive any special scoping either (just
text.xml
).Also interesting to note that, unlike JSON which receives the
source.json
base scope, XML is treated as text (text.xml
).Native YAML Syntax Example
Finally, YAML, where keys are scopes as tags, their names as unquoted strings, and values depending on their types (string, numbers, constants, etc.).
The interesting part of YAML is how scopes variations are employed to handle different types of strings:
which I guess has practical applications in ST settings and plug-ins, since YAML is one of the formats natively used by ST.
PDML Scoping...
Ultimately, after the initial tests I opted to keep things simple and just stick to focusing on the actual nodes, scoping them as tags and tracking their opening and closing brackets, ignoring their contents altogether. This still allows ST to correctly match each opening tag with its closing
]
, which means that users can easily control their selection via the predefined key-shortcuts to expand or shrink a selection to include the parent node, or shrink down the tree, which is pretty useful, along with usual native features like jumping to the beginning or end of a tag, etc.By keeping it simple, it will be very easy to create PDML package for other editors, e.g. VSCode, etc. The simple syntax boils down to just a few lines:
And if we were to use anonymous contexts and drop the variables, it would probably boil down to 10 lines of YAML in total. ST can even export a syntax to the old XML-based format or JSON, which should be usable in TextMate and VSCode, respectively, with minor adjustments.
But the reason I brought up the PDML vs JSON, XML and YAML comparisons was to focus on the hybrid nature of PDML, which can be used as a key-value mapping syntax, along the lines of JSON and YAML, or a markup syntax like XML.
So, I was wondering whether there could be benefits in adopting the
meta.mapping
scopes when dealing with key-values, and in that case how to handle valueless keys. But then this would introduce some complications, like the whitespace handling issues mentioned in pdml-lang/basic-specification#2 — and right now we might not want to get entangled with any of that...Invalid PDML Elements
I have a question regarding elements outside the PDML tree, which is not addressed in the Specs or documentation.
It seems reasonable to expect that any
.pdml
document should contain only PDML nodes, which begs the question of how to handle any stray contents before and after the root node. E.g.Should the text
Leading noise.
andTrailing noise.
be ignored by the PDML syntax? or should they be scoped asinvalid
? While scoping them as invalid might seem an obvious solution, bear in mind that the syntax should be tolerant for whitespace noise — e.g. leading and trailing new lines, since these might be found in a.pdml
document due to editor/IDE settings, or the presence of an.editroconfig
file.So it might be preferable to ignore whitespace noise, but could capture anything else preceding and following the root node.
Another useful addition would be to intercept stray brackets — e.g. a closing
]
before the root node, or an unmatched]
following the PDML tree.I'm not sure that it would be possible to visually distinguish between invalid characters noise and stray brackets though, since the
invalid
scope is only guaranteed to cover two different cases in colour schemes:invalid.illegal
andinvalid.deprecated
, where only the former applies to PDML.Beyond Basic PDML: Extensions via Syntax Inheritance
Another reason to keep the Basic PDML syntax simple and straightforward is that I was thinking that when new officially sanctioned PDML extensions are added to PDML, we could include them in the ST package too.
Although
*.pdml
files will always be associated with the Basic PDML syntax, the package could also provide additional syntaxes extending the basic one, which users could select manually via the command palette (Set syntax as PDML >some extension name<, etc.).ST4 introduced a cool new syntax feature: inheritance:
Thanks to this, it will be very easy to include support for any number of PDML extensions in the package. I was thinking that official PDML extensions should be included to this package, whereas third party extensions could be packaged separately, and users could install them according to need.
Of course, end users can also create a custom extension of the PDML syntax locally, in their
User/
subfolder of ST packages directory, yet still leverage inheritance to extend the PDML Basic syntax (or any other official extension being supported).Extended Features
We briefly mentioned en passant about adding to PDML packages for editors some extra functionality like prettifying or minifying the Tree, serializing to/from JSON, XML, YAML, and other useful stuff which might render these packages more appealing than just providing basic syntax highlighting for PDML documents.
In ST, plug-ins are written in Python. It's been quite a while since I had a brush with Python, and I'm not entirely sure how custom plug-ins can integrate third party Python modules (e.g. to parse/serialize JSON, XML, etc.) into a ST package, but my guess is that you can't rely on
pip
since ST uses the bundled Python runtime and not a full Python installation on the user machine.ST does provide its own API, but I have no idea if this include JSON, YAML and XML serializing, although these formats are used in the various settings files natively supported by ST — I'll need to check that, for any serializing built-in functionality could come handy here.
Unfortunately, any work in Python won't be reusable on VSCode, which uses JS/TypeScript instead, which kind of sucks really.
Anyhow, I would like to ear your ideas and thoughts on potential uses of editors' plug-ins for managing PDML documents, since you have a clearer vision of where PDML is heading for in the future.
Beta Was this translation helpful? Give feedback.
All reactions