From 704308bb16c838ee8ab42858cec06ebeef71fd96 Mon Sep 17 00:00:00 2001 From: Bung Date: Mon, 11 Sep 2023 21:05:05 +0800 Subject: [PATCH] stdlib: temporarily add AST pattern matching (#882) ## Summary Add the `ast_pattern_matching` module to the experimental standard library. It implements pattern matching for `NimNode` AST and is copied from https://github.com/krux02/ast-pattern-matching. The first iteration of the language-server protocol (LSP) implementation is going to use the pattern matching, but it's likely that the module will be removed from the standard library again. ## Details A copy of the `ast-pattern-matching` implementation already existed within the `tests` directory, where it is used by the `tastpec.nim` test. The module is moved to the `lib/experimental` directory and the import is adjusted. --- .../lang_syntax => lib/experimental}/ast_pattern_matching.nim | 4 ++-- tests/lang_syntax/astspec/tastspec.nim | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename {tests/lang_syntax => lib/experimental}/ast_pattern_matching.nim (99%) diff --git a/tests/lang_syntax/ast_pattern_matching.nim b/lib/experimental/ast_pattern_matching.nim similarity index 99% rename from tests/lang_syntax/ast_pattern_matching.nim rename to lib/experimental/ast_pattern_matching.nim index d209493b6c0..53f11f04176 100644 --- a/tests/lang_syntax/ast_pattern_matching.nim +++ b/lib/experimental/ast_pattern_matching.nim @@ -1,5 +1,5 @@ -# this is a copy paste implementation of github.com/krux02/ast_pattern_matching -# Please provide bugfixes upstream first before adding them here. +## Implements pattern matching for ``NimNode`` AST. This module is copied +## from https://github.com/krux02/ast-pattern-matching. import macros, strutils, tables diff --git a/tests/lang_syntax/astspec/tastspec.nim b/tests/lang_syntax/astspec/tastspec.nim index 49db7decf87..30f49ecee9a 100644 --- a/tests/lang_syntax/astspec/tastspec.nim +++ b/tests/lang_syntax/astspec/tastspec.nim @@ -5,7 +5,7 @@ joinable: false # this test should ensure that the AST doesn't change slightly without it getting noticed. -import ../ast_pattern_matching +import experimental/ast_pattern_matching template expectNimNode(arg: untyped): NimNode = arg ## This template here is just to be injected by `myquote`, so that