Skip to content

core: Fix GitHub syntax highlighting#205

Merged
ingydotnet merged 1 commit intoyaml:ys-highlightfrom
danielbayley:gitattributes
Dec 22, 2024
Merged

core: Fix GitHub syntax highlighting#205
ingydotnet merged 1 commit intoyaml:ys-highlightfrom
danielbayley:gitattributes

Conversation

@danielbayley
Copy link
Contributor

@danielbayley danielbayley commented Dec 20, 2024

Force GitHub to highlight *.ys files as YAML.

@ingydotnet
Copy link
Member

Awesome. I didn't know about this.

I can apply this for now but we should possibly look at other syntaxes.

Weirdly, highlighting as powershell works pretty good in vscode...

@danielbayley
Copy link
Contributor Author

we should possibly look at other syntaxes.

Ideally, a YAMLScript: entry would be added to linguist here, the library responsible for syntax highlighting on here… But I think they have minimum constraints around popularity/usage, so the project will probably need to grow a lot more before they would accept a PR…

Weirdly, highlighting as powershell works pretty good in vscode...

PowerShell is also listed, so you could change this to the following, if that would render better highlighting…

*.ys linguist-language=powershell

@ingydotnet
Copy link
Member

do you know if *.ys applies to code sections like

```ys
!yamlscript/v0
say: 42
```

@danielbayley
Copy link
Contributor Author

do you know if *.ys applies to code sections like

```ys
!yamlscript/v0
say: 42
```

I think that would only work after a merged PR entry to linguist… Until then, would have to just do:

``` yaml
!yamlscript/v0
say: 42
```

or

~~~ yaml
!yamlscript/v0
say: 42
~~~

@ingydotnet
Copy link
Member

I can certainly test it out on a branch,,,

@ingydotnet ingydotnet changed the base branch from main to devel December 22, 2024 15:42
@ingydotnet
Copy link
Member

I realized that I can retarget the PR myself.
Retargeted to devel.

@ingydotnet
Copy link
Member

@danielbayley do you have any experience creating a new syntax highlighter for linguist?

@ingydotnet ingydotnet changed the base branch from devel to ys-highlight December 22, 2024 23:15
@ingydotnet ingydotnet merged commit c4ad95c into yaml:ys-highlight Dec 22, 2024
@ingydotnet
Copy link
Member

Merged into a branch intended for 0.1.88

@ingydotnet
Copy link
Member

YAML syntax highlighting is fine for now, but I'd like to get real ys token highlighting.

@danielbayley
Copy link
Contributor Author

@danielbayley do you have any experience creating a new syntax highlighter for linguist?

@ingydotnet Iv'e done plenty of parsing stuff, but not really much in the context of syntax highlighting—apart from minor related things in Atom packages… I imagine Linguist probably uses something like TextMate grammars, or something RegEx-based.

I'd like to get real ys token highlighting.

Yeah ideally! I will say for sure, the much better approach would be the Tree-sitter/AST route…

@danielbayley danielbayley deleted the gitattributes branch December 23, 2024 19:19
@ingydotnet
Copy link
Member

I've also done a bunch with parsing including creating the Pegex grammar language: https://github.com/pegex-parser
and also a little bit of syntax highlighting for CodeMirror, but not much.

I think the big thing that YS needs first is a language server.`
The YAMLScript compiler is perfectly postured to work as an LSP implementation for YAML and YS.

Here's a visual of the comilper in action:

$ ys -cde 'say: 2 + 3'
*** parse     *** 0.211807 ms

({:+ "+MAP", :! "yamlscript/v0/code"}
 {:+ "=VAL", := "say"}
 {:+ "=VAL", := "2 + 3"}
 {:+ "-MAP"}
 {:+ "-DOC"})

*** compose   *** 0.005074 ms

{:! "yamlscript/v0/code", :% [{:= "say"} {:= "2 + 3"}]}

*** resolve   *** 0.042651 ms

{:xmap [{:expr "say"} {:expr "2 + 3"}]}

*** build     *** 0.108232 ms

{:xmap [{:Sym say} {:Lst [{:Sym add+} {:Int 2} {:Int 3}]}]}

*** transform *** 0.027301 ms

{:xmap [{:Sym say} {:Lst [{:Sym add+} {:Int 2} {:Int 3}]}]}

*** construct *** 0.051574 ms

{:Top [{:Lst [{:Sym say} {:Lst [{:Sym add+} {:Int 2} {:Int 3}]}]}]}

*** print     *** 0.004313 ms

"(say (add+ 2 3))"

(say (add+ 2 3))

The output of the build stage should have all the info we need, except for input position (line/col).
The parser that YS uses does report that information but it is currently ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants