vscode 文件高亮插件_为新语言编写Visual Studio Code语法高亮插件

本文档介绍了如何根据Visual Studio Code官方文档,为自定义的'圈4'语言创建一个语法高亮插件。通过运行yo code生成新插件,设置插件名称、标识符、描述、作者、语言ID和扩展名等信息,并修改默认的tmLanguage.json文件以匹配'圈4'的关键词。最后,通过正则表达式实现关键词高亮,并讨论了可能的空格敏感性和语法检查功能。
摘要由CSDN通过智能技术生成

语法高亮是一个开发环境的基本功能. 此文尝试为之前的"圈4"语言(详见编程语言试验之Antlr4+JavaScript实现"圈4")编写一个高亮插件, 仅为演示之用. 参考的是Visual Studio Code官方文档: Add Themes, Snippets and Colorizers to 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 Support

Enter 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)? nobody

Enter the id of the language. The id is an identifier and is single, lower-case name such as 'php', 'javascript'

? Language id: quan4

Enter the name of the language. The name will be shown in the VS Code editor mode selector.

? Language name: 圈4

Enter the file extensions of the language. Use commas to separate multiple entries (e.g. .ruby, .rb)

? File extensions: .圈4

Enter 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/.gitignore

Your extension quan4-highlighter has been created!

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

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

直接改为:

"match": "求约数"

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值