0

我开发了一种名为PTL. 我想在 Atom 中为它突出显示语法,所以我按照相应的指南为它创建了一个工作的 tree-sitter 解析器。通过大量的调试,我设法将解析器安装为 Atom 可以读取的包。

语言包

解析器包

我使用以下文件测试了解析器 input.ptl

==================
ptlExample
==================
#define myvar 4
#define myvartwo 2
GlobalSettings
{
    Display
    {
        debugLevel = $(myvar)
        debugLevelzap = 3
    }
    Memory
    {
        allowStackAllocation = false
    }
}
Domain
{
    blockDim = [1, 2, 2]
    coolio = @sqrt($(myvartwo))
}
//parallel
---
(source_file
    (preprocessor_definition
        (preprocessor_name
            (string_identifier)
        )
        (rvalue_statement
            (basic_identifier
                (number_identifier)
            )
        )
    )
    (preprocessor_definition
        (preprocessor_name
            (string_identifier)
        )
        (rvalue_statement
            (basic_identifier
                (number_identifier)
            )
        )
    )
    (section_identifier
        (string_identifier)
        (section_identifier
            (string_identifier)
            (assignment
                (string_identifier)
                (assign_sym)
                (rvalue_statement
                    (variable_invocation
                        (variable_invoke_sym)
                        (rvalue_statement
                            (basic_identifier
                                (string_identifier)
                            )
                        )
                    )
                )
            )
            (assignment
                (string_identifier)
                (assign_sym)
                (rvalue_statement
                    (basic_identifier
                        (number_identifier)
                    )
                )
            )
        )
        (section_identifier
            (string_identifier)
            (assignment
                (string_identifier)
                (assign_sym)
                (rvalue_statement
                    (basic_identifier
                        (boolean_identifier)
                    )
                )
            )
        )
    )
    (section_identifier
        (string_identifier)
        (assignment
            (string_identifier)
            (assign_sym)
            (rvalue_statement
                (vector
                    (rvalue_statement
                        (basic_identifier
                            (number_identifier)
                        )
                    )
                    (rvalue_statement
                        (basic_identifier
                            (number_identifier)
                        )
                    )
                    (rvalue_statement
                        (basic_identifier
                            (number_identifier)
                        )
                    )
                )
            )
        )
        (assignment
            (string_identifier)
            (assign_sym)
            (rvalue_statement
                (function_invocation
                    (function_invocation_sym)
                    (string_identifier)
                    (parameter_list
                        (rvalue_statement
                            (variable_invocation
                                (variable_invoke_sym)
                                (rvalue_statement
                                    (basic_identifier
                                        (string_identifier)
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )
    (comment
        (string_identifier)
    )
)

测试是成功的,所以我相信 tree-sitter 正在捕获完整的语法树。但是,在安装之后,当我在 atom 中打开我的确切文件时(只有内容,没有像标题和预期语法树这样的树保姆额外内容),没有任何东西是正确的,并且整个文件都有ptl范围。我有以下范围:

scopes:
  'comment > string_identifier': 'comment.line.double-slash.ptl'

所以至少,应该拿起最后的评论。它不是。我已经看到这个线程描述了完全相同的问题,但修复涉及更新 Atom 的语法获取功能以识别树保姆语法。我正在运行更新版本的 Atom,所以这不是原因。我该如何调试呢?

编辑:我在控制台中发现了一个错误:

Uncaught (in promise) RangeError: Incompatible language version. Compatible range: 9 - 10. Got: 12
    at Parser.setLanguage (/usr/share/atom/reso…sitter/index.js:248)
    at TreeSitterLanguageMode.parse (/usr/share/atom/reso…tatic/<embedded>:11)
    at LanguageLayer._performUpdate (/usr/share/atom/reso…tatic/<embedded>:11)
    at LanguageLayer.update (/usr/share/atom/reso…tatic/<embedded>:11)
    at new TreeSitterLanguageMode (/usr/share/atom/reso…tatic/<embedded>:11)
    at GrammarRegistry.languageModeForGrammarAndBuffer (/usr/share/atom/reso…tatic/<embedded>:11)
    at grammarScoresByBuffer.forEach (/usr/share/atom/reso…tatic/<embedded>:11)
    at Map.forEach (<anonymous>)
    at GrammarRegistry.grammarAddedOrUpdated (/usr/share/atom/reso…tatic/<embedded>:11)
    at GrammarRegistry.addGrammar (/usr/share/atom/reso…tatic/<embedded>:11)
    at TreeSitterGrammar.activate (/usr/share/atom/reso…tatic/<embedded>:11)
    at Package.loadGrammarsSync (/usr/share/atom/reso…tatic/<embedded>:11)
    at Workspace.deserialize (/usr/share/atom/reso…tatic/<embedded>:11)
    at AtomEnvironment.deserialize (/usr/share/atom/reso…static/<embedded>:1)
<embedded>:11 Uncaught (in promise) TypeError: Cannot read property 'rootNode' of null
    at LanguageLayer._populateInjections (/usr/share/atom/reso…tatic/<embedded>:11)
    at e.injectionRegex.currentParsePromise.currentParsePromise.then (/usr/share/atom/reso…tatic/<embedded>:11)

基于,看起来我需要使用不同版本的 tree-sitter 重建我的包,尽管我不知道 tree-sitter Atom 使用哪个版本。这是否意味着我需要更新 Atom 的 tree-sitter 版本(似乎更可取),还是需要降级我在包中使用的 tree-sitter 版本?

4

1 回答 1

0

我最终将 atom 升级到最新版本,然后按照我用来达到上述状态的相同过程。

于 2020-12-19T00:13:07.313 回答