Skip to content
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 highlighting for ucode #178

Open
eric-j-ason opened this issue Oct 30, 2023 · 6 comments
Open

Syntax highlighting for ucode #178

eric-j-ason opened this issue Oct 30, 2023 · 6 comments

Comments

@eric-j-ason
Copy link

I'd like to get support for ucode in syntax highlighters such as Chroma (which is used by Gitea) and Pygments, perhaps by starting with their Javascript definitions and modifying them. Is there a specification of what keywords and other token types exist in ucode?

For reference:

@eric-j-ason
Copy link
Author

And in nano, of course, included in OpenWrt!

@eric-j-ason
Copy link
Author

A pull request for introducing ucode in Chroma has been created.

@jow-
Copy link
Owner

jow- commented Nov 8, 2023

I added a pull request to include syntax highlighting in OpenWrt's nano package:
openwrt/packages#22623

@jow-
Copy link
Owner

jow- commented Nov 9, 2023

@eric-j-ason - I suggest to use the nano highlighting I submitted in the other PR as authoritative source for the supported syntax keywords.

See also https://github.com/jow-/ucode/blob/master/lexer.c#L47

There's some special cases like as and from which are syntax elements in import statements but otherwise no reserved identifier (see recently fixed bug at 1468cc4).

Another complication is that ucode may run in template mode where by default the file source is uninterpreted plain text and actual ucode logic only appears in {{ ... }} or {% ... %} expression blocks. (See the grey text in screenshot https://user-images.githubusercontent.com/2528802/281428096-478dddef-fe44-4c01-ac3e-63fa6c605f6e.png for illustration)

@eric-j-ason
Copy link
Author

@eric-j-ason - I suggest to use the nano highlighting I submitted in the other PR as authoritative source for the supported syntax keywords.

See also https://github.com/jow-/ucode/blob/master/lexer.c#L47

Yes, good idea. Those lines in lexer.c was actually what I used to figure out the list of keywords.

There's some special cases like as and from which are syntax elements in import statements but otherwise no reserved identifier (see recently fixed bug at 1468cc4).

Oh, I see. Does it work the same in JavaScript, or is it different? In what I did for Chroma, I just took JavaScript as the starting point, and adjusted the list of keywords. I'm afraid I don't know how to do anything more complicated in Chroma or any other highlighter.

Another complication is that ucode may run in template mode where by default the file source is uninterpreted plain text and actual ucode logic only appears in {{ ... }} or {% ... %} expression blocks. (See the grey text in screenshot https://user-images.githubusercontent.com/2528802/281428096-478dddef-fe44-4c01-ac3e-63fa6c605f6e.png for illustration)

Yes, also this I didn't know how to do, so I had to leave it out. It's nice that you did it for nano.

I haven't quite figured out how highlighting works on GitHub. Perhaps they use a complete parser, enabling additional features such as getting the definition of a variable by clicking it. This is what they say: "We use Linguist to perform language detection and to select third-party grammars for syntax highlighting. You can find out which keywords are valid in the languages YAML file."

@eric-j-ason
Copy link
Author

I added a pull request to include syntax highlighting in OpenWrt's nano package: openwrt/packages#22623

I have noticed that these highlighting rules assume that the file is a template, and breaks on a pure ucode file.

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

No branches or pull requests

2 participants