nim-works/nimskull

Refactor `.cfg` file processing

開放

#159 建立於 2022年1月16日

 (0 則留言) (0 個反應) (0 位負責人)Nim (39 個分叉)auto 404
good first issuerefactor

倉庫指標

星標
 (346 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

The current implementation of the .cfg file processing does not have any form of AST and instead evaluates code directly during lexing, mutating the global configuration values in-place. Refactoring the .cfg file parser would allow:

  • make testing simpler - instead of mutating whole global configuration in-place, test can be separated into parser (can test and assert structure of the AST) and evaluation (can properly assert changed values).

  • Together with https://github.com/nim-works/nimskull/issues/158 .cfg parser can now be seen as a simple function of the input (config: string, oldOptions: ActiveOptions) -> ActiveOptions

  • std/parsecfg can be used in regular code, but the compiler has nonstandard implementation that cannot be used or understood by external tooling, requiring full reimplementation. Having proper AST will address this issue at least as far as reading is concerned

  • Compiler implementation uses nim lexer to "save space and work", which causes more syntax discrepancies: path=$config/test is valid in one syntax, but for .cfg you need to use `path="$config/test" only

  • Testament uses parsecfg with support for ''' for multiline string literals implemented via s.substr(a, b-1).multiReplace({"'''": tripleQuote, "\\31": "\31"})

  • Changes can be made either by improving the current std/parsecfg parser to include events for @if, @command etc., or rewriting the current nimconf.nim to use the implementation from parsecfg - in that case new module can be added into experimental/parsecfg and used only for compiler needs for the time being.

貢獻者指南