英文:
In Monaco Editor, how to get the actual value from a Token?
问题
我使用了 monaco.editor.tokenize
并得到了一个 token[][]
的结果。
var tokens = monaco.editor.tokenize(text, "myLanguage");
但是这些令牌只包含了语言、偏移和类型属性。我想知道如何获取每个令牌的实际值?或者是否有其他方法可以找到令牌化令牌的值?
我查看了 Monaco 的文档,但没有找到任何有助于的方法。
英文:
I used monaco.editor.tokenize and received a result of token[][].
var tokens = monaco.editor.tokenize(text, "myLanguage");
I but the token only contains properties of language, offset and type. I would like to know how can I get the actual value of each token? Or is there any other ways of find the values of tokenized tokens?
I looked around the documentaiton of Monaco but I don't find any way that will help.
答案1
得分: 1
每个标记条目都有一个偏移成员,因此您可以通过减去此标记的偏移量和下一个标记的偏移量来获取其位置和长度。将其与原始文本一起使用,以获取标记文本的子串。
英文:
Each token entry has an offset member, so you can get its position and its length (by subtracting the offset of this token from that of the following token). Use that with the original text to get a substring as token text.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论