nim-works/nimskull

Refactor `.cfg` file processing

Open

#159 opened on Jan 16, 2022

 (0 comments) (0 reactions) (0 assignees)Nim (39 forks)auto 404
good first issuerefactor

Repository metrics

Stars
 (346 stars)
PR merge metrics
 (PR metrics pending)

Description

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.

Contributor guide