File: tinvalidnewseq.nim

package info (click to toggle)
nim 2.2.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,951,164 kB
  • sloc: sh: 24,599; ansic: 1,771; python: 1,493; makefile: 1,013; sql: 298; asm: 141; xml: 13
file content (24 lines) | stat: -rw-r--r-- 717 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
discard """
  errormsg: "type mismatch: got <array[0..6, string], int literal(7)>"
  file: "tinvalidnewseq.nim"
  line: 15
"""
import re, strutils

type
  TURL = tuple[protocol, subdomain, domain, port: string, path: seq[string]]

proc parseURL(url: string): TURL =
  #([a-zA-Z]+://)?(\w+?\.)?(\w+)(\.\w+)(:[0-9]+)?(/.+)?
  var pattern: string = r"([a-zA-Z]+://)?(\w+?\.)?(\w+)(\.\w+)(:[0-9]+)?(/.+)?"
  var m: array[0..6, string] #Array with the matches
  newSeq(m, 7) #ERROR
  discard re.match(url, re(pattern), m)

  result = (protocol: m[1], subdomain: m[2], domain: m[3] & m[4],
            port: m[5], path: m[6].split('/'))

var r: TUrl

r = parseUrl(r"http://google.com/search?var=bleahdhsad")
echo(r.domain)