examples from the talk part of test suite
This commit is contained in:
parent
a0b82db402
commit
2f0671eb79
9 changed files with 153 additions and 3 deletions
23
examples/talk/hoisting.nim
Normal file
23
examples/talk/hoisting.nim
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
type
|
||||
Regex = distinct string
|
||||
|
||||
const maxSubpatterns = 10
|
||||
|
||||
proc re(x: string): Regex =
|
||||
result = Regex(x)
|
||||
|
||||
proc match(s: string, pattern: Regex, captures: var openArray[string]): bool =
|
||||
true
|
||||
|
||||
template optRe{re(x)}(x: string{lit}): Regex =
|
||||
var g {.global.} = re(x)
|
||||
g
|
||||
|
||||
template `=~`(s: string, pattern: Regex): bool =
|
||||
when not definedInScope(matches):
|
||||
var matches {.inject.}: array[maxSubPatterns, string]
|
||||
match(s, pattern, matches)
|
||||
|
||||
for line in lines("input.txt"):
|
||||
if line =~ re"(\w+)=(\w+)":
|
||||
echo "key-value pair; key: ", matches[0], " value: ", matches[1]
|
||||
Loading…
Add table
Add a link
Reference in a new issue