The following code used to compile in nim 0.19:
result = newSeq[string]()
...
var tokens = li.match(re"\s*(\S+)\s*(?:>\s*(\S.*\S))?\s*").get.captures.toSeq()
# Add to the list of list values
result.add(tokens[ITEM_NAME])
Now, I get the following error:
G:\src\nim\vim256\opts.nim(281, 19) Error: type mismatch: got <seq[string], Option[system.string]>
but expected one of:
proc add[T](x: var seq[T]; y: openArray[T])
first type mismatch at position: 2
required type for y: openArray[T]
but expression 'tokens[0]' is of type: Option[system.string]
proc add[T](x: var seq[T]; y: T)
first type mismatch at position: 2
required type for y: T
but expression 'tokens[0]' is of type: Option[system.string]
9 other mismatching symbols have been suppressed; compile with --showAllMismatches:on to see them
As I have "been away" from nim for a relatively long period, I would appreciate some hint as how to remedy this...
According to your error message, it seems tokens[ITEM_NAME] is Option[system.string] type and you are trying to add it to seq[string] type result variable.
You might need to read this document and learn how to get a value from an Option type. https://nim-lang.org/docs/options.html
Sorry for my late reply, and thanks for the answer. However I didn't find a solution for the following problem:
import nre
var
tokens = newSeq[string]()
tokens = "abc > def".match(re"\s*(\S+)\s*(?:>\s*(\S.*\S))?\s*").get.captures.toSeq() # ERROR
echo tokens[0]
tokens[0] = "ghi"
The nre docs state:
Note: If you love sequtils.toSeq we have bad news for you. This library doesn't work with it due to documented compiler limitations."
Suppose, this is still the problem... Is there a simpler workaround than to enumerate the captures, get the values, and assign to tokens? - as e.g. in
caps = "abc > def".match(re"\s*(\S+)\s*(?:>\s*(\S.*\S))?\s*").get.captures
for cap in caps:
tokens.add(cap.get)