简体   繁体   English

我的vscode扩展名中有语法。 我想以编程方式标识TextLine或TextDocument对象中的注释

[英]I have a grammar in my vscode extension. I want to programmatically identify comments in a TextLine or TextDocument object

I'm working on a VSCode extension for the ChucK music programming language. 我正在为ChucK音乐编程语言开发VSCode扩展。 I have released a version which just does syntax highlighting using a .tmLanguage.json file. 我发布了一个仅使用.tmLanguage.json文件进行语法高亮显示的版本。 Now I'm working on a syntax checker. 现在,我正在研究语法检查器。

The syntax error location identified by ChucK is a bit confusing, and it would clearer if I extended the range to just past the end of the previous statement or block, which would mean looking backwards for the previous ; ChucK标识的语法错误位置有些混乱,如果我将范围扩展到前一个语句或块的末尾,这将更清楚,这意味着向后看前一个; or } character. }字符。

This would be simple, except for the fact I need to skip comments. 这很简单,除了我需要跳过评论的事实。 ChucK has C++ style comments, with both // line comments and /* */ block comments. ChucK具有C ++样式的注释,并带有//行注释和/* */块注释。 These are correctly highlighted by my grammar file. 这些由我的语法文件正确突出显示。

Is there any way I can get at the syntax information the grammar has already produced to identify these comments? 我有什么办法可以获取语法所产生的语法信息来识别这些注释? Scanning the docs, it appears that I may be able to grab visual attributes like text color, but that seems theme-dependent and error-prone. 扫描文档后,看来我也许能够抓住诸如文字颜色之类的视觉属性,但这似乎与主题相关且容易出错。 How can my code get directly at how the grammar has identified a particular character or region? 我的代码如何直接了解语法如何识别特定字符或区域?

If you want to do error checking for a custom language you will have to write a full parser for that. 如果要对自定义语言进行错误检查,则必须为此编写一个完整的解析器。 Many extension authors have done that (or use an external parser like clang for C++). 许多扩展作者已经做到了这一点(或者使用外部解析器,例如C ++的clang)。 Once you got the syntax structure it is easy to find certain ranges of syntactic elements and the parser will give you the error location (if there's an error). 一旦获得了语法结构,就很容易找到一定范围的语法元素,并且解析器将为您提供错误位置(如果有错误)。

I successfully used ANTLR4 (via the antlr4ts typescript runtime) to parse and process a custom language (in my case ANTLR4 grammars). 我成功地使用了ANTLR4(通过antlr4ts打字稿运行时)来解析和处理自定义语言(以我的情况为ANTLR4语法)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的 vscode 在我运行扩展时总是显示构建? - Why my vscode always show building when I run extension? 如何解决我在安装 vscode 以测试我的扩展程序时遇到的错误? - How to resolve an error which i am getting when installing vscode for testing my extension? 我想从我的 MatTableDataSource 中删除所有具有 montoDonar ==0 的行 - I want to remove all rows from my MatTableDataSource that have montoDonar ==0 当我有一个嵌套接口并且我只想获取 object 时,如何在 function 的参数中定义? - How do I define in a argument of a function when I have a nested interface and I want to get only the object? 我想为使用TypeScript创建的所有对象或引用创建扩展方法 - I want to create an extension method to all object or reference that are created using TypeScript 如何在vscode扩展中获取对象? - How to get the object in a vscode extension? VSCode 扩展 - 如何编辑工作区全局配置? - VSCode extension - How do I edit workspace global config? 我有json对象,我想找到具有父级索引值的id - I have json object I want find the id with index value of the parent 我在数组 object 下面有数据,想转换另一个数组 object 格式 - I have data in below array object and want to convert another array object format 如何计算 vscode 扩展中文件夹中的文件数? - How do I count files in a folder in a vscode extension?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM