Skip to content

Instantly share code, notes, and snippets.

@optik-aper
Created October 30, 2017 02:30
Show Gist options
  • Save optik-aper/67419f071a026107879b0d54b07f8f8a to your computer and use it in GitHub Desktop.
Save optik-aper/67419f071a026107879b0d54b07f8f8a to your computer and use it in GitHub Desktop.
Difficulties with nre proc
# Code adapted from the captures tests
# nim/tests/stdlib/nre/captures.nim
import nre
echo("abc".match(re"(?<letter>\w)").captures["letter"])
@optik-aper
Copy link
Author

Compiler output:

$ nim compile --verbosity:2 -r testing_stuff.nim 
config/nim.cfg(42, 3) Hint: added path: '/home/michael/.nimble/pkgs/nake-1.9' [Path]
config/nim.cfg(42, 3) Hint: added path: '/home/michael/.nimble/pkgs/vimwiki_gitlab-0.0.1' [Path]
config/nim.cfg(42, 3) Hint: added path: '/home/michael/.nimble/pkgs/' [Path]
config/nim.cfg(44, 5) Hint: added path: '/opt/nimble/pkgs/' [Path]
Hint: used config file '/usr/src/nim-0.17.2/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: testing_stuff [Processing]
Hint: nre [Processing]
Hint: pcre [Processing]
Hint: util [Processing]
Hint: tables [Processing]
Hint: hashes [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: math [Processing]
Hint: algorithm [Processing]
Hint: options [Processing]
Hint: typetraits [Processing]
Hint: unicode [Processing]
testing_stuff.nim(3, 36) Error: type mismatch: got (Option[nre.RegexMatch])
but expected one of: 
proc captures(pattern: RegexMatch): Captures

  echo("abc".match(re"(?<letter>\w)").captures["letter"])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment