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

本文共 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应用
下一篇:日语编程语言"抚子"-第三版实现初探

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2024年04月10日 01时56分42秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

【经验分享】RT-Thread UART设备驱动框架初体验(中断方式接收带\r\n的数据) 2019-04-29
单片机里面的CPU使用率是什么鬼? 2019-04-29
推荐一个优质Linux技术公众号-作者都是一线Linux代码贡献者们哦 2019-04-29
RT-Thread 编程风格指南 2019-04-29
95后高校电子教师,软硬兼修有趣有料! 2019-04-29
使用 STM32 通用 Bootloader ,让 OTA 更加 Easy 2019-04-29
Cache 的基本概念与工作原理 2019-04-29
装机量超亿台 RISC-V +IoT OS!中科蓝讯与RT-Thread战略合作,共推自主物联网生态发展 2019-04-29
Android程序员必备!面试一路绿灯Offer拿到手软,Android面试题及解析 2019-04-29
Android程序员的春天!12个View绘制流程高频面试题,分享PDF高清版 2019-04-29
深入交流安卓!新鲜出炉的Android面试真题集锦我给你们整理出来了!Android面试题及解析 2019-04-29
深入浅出Android开发!你会的还只有初级工程师的技术吗?一线互联网公司面经总结 2019-04-29
深度剖析原理!超全Android中高级面试复习大纲,含BATJM大厂 2019-04-29
温故而知新!Android开发者该学习哪些东西提高竞争力?成功入职阿里 2019-04-29
火爆知乎的Android面试题-Android-App的设计架构经验谈,大厂内部资料 2019-04-29
看完直接怼产品经理!Android多进程从头讲到尾,跳槽薪资翻倍 2019-04-29
快速从入门到精通!面试的时候突然遇到答不上的问题怎么办?已拿到offer 2019-04-29
Android开发知识体系!腾讯+字节+阿里面经真题汇总,成功入职阿里 2019-04-29
android开发语言!大厂经典高频面试题体系化集合,移动架构师成长路线 2019-04-29
typescript学习(进阶) 2019-04-29