本文源码库: program-in-chinese/quan4-highlighter

语法高亮是一个开发环境的基本功能. 此文尝试为之前的"圈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可以在插件修改后刷新)实现:

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

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

2017-12-24 为新语言编写Visual Studio Code语法高亮插件的更多相关文章

  1. 新成员!Visual Studio Code --跨平台的开发工具(支持OSX, Linux 和 Windows)

    原文出处:新成员!Visual Studio Code --跨平台的开发工具(支持OSX, Linux 和 Windows) 这是我的文章备份  http://www.dotblogs.com.tw/ ...

  2. Visual studio code离线安装插件

    Visual studio code离线安装插件 公司研发区不能连接公网,使用Visual studio code(vsc)写Golang代码需要安装Go插件,下面介绍下,vsc离线安装插件的步骤.以 ...

  3. 2017-12-04 编写Visual Studio Code插件初尝试

    参考官方入门: Your First Visual Studio Code Extension - Hello World 源码在: program-in-chinese/vscode_helloWo ...

  4. Visual Studio Code 通过 Chrome插件Type Script断点调试Angular 2

    1. 下载Visual Studio Code (https://code.visualstudio.com/) 2. 安装插件Debugger for chrome 3. 确定tsconfig.js ...

  5. Visual Studio Code IDE开发插件配置

    [PHP通用集成环境] PHP Extension Pack #PHP拓展包,PHP开发最重要的拓展 PHP Intelephense #PHP自动补全工具 PHP IntelliSense #PHP ...

  6. Visual Studio Code 使用 Git插件报错 - Permission denied (publickey)

    在使用GitHub的时候,为了避免每次输入用户名密码,都会使用SSH方式代替Https. 按网上教程,大多数使用SSH-KeyGen生成公私钥对,而后上传公钥至Github,并切换Repositori ...

  7. Visual Studio Code如何编写运行C、C++

    Visual Studio Code如何编写运行C.C++ 作者:知乎用户链接:https://www.zhihu.com/question/30315894/answer/154979413来源:知 ...

  8. 在Visual Studio Code中开发Office Add-in

    作者:陈希章 发表于 2017年7月13日 上一篇 我介绍了如何在Visual Studio中开发Office Add-in,因为有标准的项目模板,一系列配套的工具,尤其是自带的一键调试功能,可以让开 ...

  9. [翻译]使用Visual Studio Code怎样调试Rust

    我将 Visual Studio Code 作为Rust首选编辑器.遗憾的是 VS Code 不能非常好地完成 Rust 的调试. 配置调试器不难,但仍然需要几个步骤.我已经完整配置了好几次.我正在写 ...

随机推荐

  1. Angular使用总结 ---以密码确认为例实现模版驱动表单的自定义校验

    上一篇 总结了模版驱动表单的基本用法,示例中的校验使用的是原生HTML5的校验方式,本文补上自定义校验的部分. HTML5原生的表单校验属性(必填,长度限制,取值间隔,正则表达式等等)可以满足普通的校 ...

  2. SwaggerUI--SosoApi

    1.SwaggerUI是什么? Swagger UI是一款RESTFUL接口的文档在线自动生成+功能测试功能软件. Swagger-UI 的官方地址:http://swagger.io/ Github ...

  3. css的div垂直居中的方法,百分比div垂直居中

    前言 我们都知道,固定高宽的div在网页中垂直居中很简单,相信大家也很容易的写出来,但是不是固定高宽的div如何垂直居中呢?我们在网页布局,特别是手机等web端网页经常是不固定高宽的div,那么这些d ...

  4. GraphicsMagick+im4java实现高质量大图的处理

    http://www.open-open.com/lib/view/open1355754261963.html 做网站往往需要处理各种各样的图片,对于jdk自带的一套图片处理库,他的特点是稳定简单, ...

  5. css布局-双飞翼布局

    <div class="header">Header</div> <div class="bd"> <div clas ...

  6. session会话管理

    session会话和cookie一起被称为会话跟踪技术,主要通过保存在服务器端的session数据和客户端浏览器的cookie数据共同完成用户访问服务器的足迹记录. 1. 什么是会话 会话sessio ...

  7. yum 出问题了

    今天用yum 安装ntp 的过程中用了 Ctrl+ z, 然后yum 再也不能使用了: error: rpmdb: BDB0113 Thread/process 6589/14060193936774 ...

  8. ubuntu下dpkg、phantomjs安装包下载地址

    dpkg下载地址 http://download.chinaunix.net/download/0003000/2377.shtml phantomjs下载地址 https://bitbucket.o ...

  9. 安装vmtools之后任然不能在虚拟机和主机之间复制粘贴的问题

    安装vmtools之后任然不能在虚拟机和主机之间复制粘贴的问题 都是因为这个进程没有启动起来,你只需要在启动后在终端输入 "/usr/bin /vmware-user" 就可以手动 ...

  10. 查询订阅某topic的所有consumer group(Java API)

    在网上碰到的问题,想了下使用现有的API还是可以实现的. 首先,需要引入Kafka服务器端代码,比如加入Kafka 1.0.0依赖: Maven <dependency> <grou ...