为新语言编写Visual Studio Code语法高亮插件
发布日期:2021-06-29 15:30:28 浏览次数:2 分类:技术文章

本文共 2048 字,大约阅读时间需要 6 分钟。

本文源码库:

语法高亮是一个开发环境的基本功能. 此文尝试为之前的"圈4"语言(详见)编写一个高亮插件, 仅为演示之用. 参考的是Visual Studio Code官方文档: . 首先创建插件如下, 为".圈4"的源文件添加高亮:

$ yo code     _-----_     ╭──────────────────────────╮    |       |    │   Welcome to the Visual  │    |--(o)--|    │   Studio Code Extension  │   `---------´   │        generator!        │    ( _´U`_ )    ╰──────────────────────────╯    /___A___\   /     |  ~  |        __'.___.'__    ´   `  |° ´ Y ` ? What type of extension do you want to create? New Language SupportEnter the URL (http, https) or the file path of the tmLanguage grammar or press ENTER to start with a new grammar.? URL or file to import, or none for new: ? What's the name of your extension? 圈4高亮? What's the identifier of your extension? quan4-highlighter? What's the description of your extension? 圈4语言的VS Code插件? What's your publisher name (more info: https://code.visualstudio.com/docs/tools/vscecli#_publishing-extensions)? nobodyEnter the id of the language. The id is an identifier and is single, lower-case name such as 'php', 'javascript'? Language id: quan4Enter the name of the language. The name will be shown in the VS Code editor mode selector.? Language name: 圈4Enter the file extensions of the language. Use commas to separate multiple entries (e.g. .ruby, .rb)? File extensions: .圈4Enter the root scope name of the grammar (e.g. source.ruby)? Scope names: source.圈4   create quan4-highlighter/syntaxes/quan4.tmLanguage.json   create quan4-highlighter/.vscode/launch.json   create quan4-highlighter/package.json   create quan4-highlighter/README.md   create quan4-highlighter/CHANGELOG.md   create quan4-highlighter/vsc-extension-quickstart.md   create quan4-highlighter/language-configuration.json   create quan4-highlighter/.vscodeignore   create quan4-highlighter/.gitignoreYour extension quan4-highlighter has been created!

默认语法文件syntaxes/quan4.tmLanguage.json中, 关键词的模式匹配为:

"match": "\\b(if|while|for|return)\\b"

直接改为:

"match": "求约数"

运行插件后(F5新运行, Command+R可以在插件修改后刷新)实现:

很明显它是最直接的正则表达式匹配. 还不确定是否能做到空格敏感, 以及语法检验.

这只是第一步, 之后还需对语法定义格式()进行深入学习.

转载地址:https://codeinchinese.blog.csdn.net/article/details/85844612 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:手机编程环境初尝试-用AIDE开发Android应用
下一篇:日语编程语言"抚子"-第三版实现初探

发表评论

最新留言

不错!
[***.144.177.141]2024年04月25日 02时15分27秒