Hi, This is my first post, so Hello and Sorry if my question is already covered in the docs somewhere. I try to read as much as possible while trying to write as much as (practical) nim code as possible. But in this case I cannot find a answer.
Nim has a unique combination of features, but seems also like a pretty large language. Therefore I use Nimscript is because it is very beginner friendly and because I can use the code I write today for all my everyday scripting needs.
The problem is that it seems like it is not possible to use regular expression (re) in Nimscript.. Here is the error when importing re:
usr/local/Cellar/nim/1.4.0/nim/lib/impure/re.nim(125, 3) Error: undeclared identifier: 'copyMem'
Does somebody has more information on this issue? Regular expressions are pretty important while shell scripting ...
Thanks Ben
Not everything works on NimScript.
You can check here stuff thats known to work: https://nim-lang.github.io/Nim/nims.html
thanks for link
I was aware of that page, but now when reading more carefully, two things are noticeable:
I've come to the same conclusion, trying this regex library, but I get a ~/.choosenim/toolchains/nim-1.6.4/lib/system/nimscript.nim(205, 6) Error: cannot evaluate at compile time: mode constantly, when trying to use the library.
I tried several methods. Using std/os, removing it again, etc. None worked. The only way to make the error disappear is not using that regex library.
Running on Nim 1.6.4, i.e. current stable.
I expiremented a bit, and my conclusion is, that using the regex library in Nimscript will always work, except you are invoking nimscript's exec proc. (Or any other proc using nimscript's log template.) If that exec proc wouldn't use nimscript's log template, then it would all work.
exec
proc exec*(command: string) {.
raises: [OSError], tags: [ExecIOEffect, WriteIOEffect].} =
## Executes an external process. If the external process terminates with
## a non-zero exit code, an OSError exception is raised.
##
## **Note:** If you need a version of `exec` that returns the exit code
## and text output of the command, you can use `system.gorgeEx
## <system.html#gorgeEx,string,string,string>`_.
log "exec: " & command:
if rawExec(command) != 0:
raise newException(OSError, "FAILED: " & command)
checkOsError()
log
template log(msg: string, body: untyped) =
if mode in {ScriptMode.Verbose, ScriptMode.Whatif}:
echo "[NimScript] ", msg
if mode != ScriptMode.Whatif:
body
mode
var
mode*: ScriptMode ## Set this to influence how mkDir, rmDir, rmFile etc.
## behave
Thanks for the answer.
Do you mean checking manually for compliance with Semver, without using a Regex?
I copied the Regex from some website. I didn't care how it looks, I just wanted it to work correctly.
Could you please tell me why reSemver = re"..." is not good code? How could I improve that?
i was composing a long diatribe about how it's an abomination
but it turns out it's the officially recommended regex: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string