haltcase / glob

Pure Nim library for matching file paths against Unix style glob patterns.
https://glob.bolingen.me
MIT License
61 stars 5 forks source link

Error: cannot evaluate at compile time: pattern #34

Closed timotheecour closed 6 years ago

timotheecour commented 6 years ago
when defined(case1):
  # Error: cannot evaluate at compile time: pattern
  # EDIT: now works!
  import pkg/glob
  let pattern = "foo"
  let a = re(pattern)

when defined(case2):
  # ok
  import std/nre
  let pattern = "foo"
  let a = re(pattern)

# EDIT: added
when defined(case3):
  import std/re
  let pattern = "foo"
  let a = re(pattern)

# EDIT: added
when defined(case4):
  # Error: cannot evaluate at compile time: pattern
  import pkg/regex
  let pattern = "foo"
  let a = re(pattern)

nre supports runtime regex, but not glob EDIT: root cause is nim-regex

haltcase commented 6 years ago

This is actually not a glob issue it's the underlying regex package. Could you move this over there?

https://github.com/nitely/nim-regex/issues

haltcase commented 6 years ago

Also it works if you declare pattern as a const rather than a let.

timotheecour commented 6 years ago

Also it works if you declare pattern as a const rather than a let.

let was intentional; eg if value known at runtime, not CT.

This is actually not a glob issue it's the underlying regex package. Could you move this over there?

just out of curiosity: do you know how much work (doesn't mean by "you" necessarily btw :) ) to use nre instead of nim-regex /cc @nitely

This is actually not a glob issue it's the underlying regex package. Could you move this over there?

indeed; done: https://github.com/nitely/nim-regex/issues/22

nitely commented 6 years ago

@timotheecour why would you prefer nre over nim-regex?

haltcase commented 6 years ago

just out of curiosity: do you know how much work (doesn't mean by "you" necessarily btw :) ) to use nre instead of nim-regex

Use it for what, glob? If so I think the API is different but the actual regex pattern syntax is probably the same.

why would you prefer nre over nim-regex?

I'm also curious about those reasons

timotheecour commented 6 years ago

why would you prefer nre over nim-regex? I'm also curious about those reasons

precisely the OP: allowing using regex at RT instead of CT; but it's all being sorted out ; it's possible with toPattern and soon via re too (see my PR https://github.com/nitely/nim-regex/pull/27)

timotheecour commented 6 years ago

it now works now that nitely/nim-regex#27 was merged; just edited OP