all repos — min @ 66db4625882a303b9847f316f0030fa37612095a

A small but practical concatenative programming language.

Implemented regex matching (untested).
h3rald h3rald@h3rald.com
Mon, 08 Dec 2014 21:16:51 +0100
commit

66db4625882a303b9847f316f0030fa37612095a

parent

135ba8c32b3f64602a322f42c2bb5dc22e03cb23

1 files changed, 25 insertions(+), 2 deletions(-)

jump to
M trex.nimtrex.nim

@@ -63,6 +63,29 @@ proc getsubexpcount*(exp: ptr TRex): cint

proc getsubexp*(exp: ptr TRex; n: cint; subexp: ptr TRexMatch): TRexBool # High level API - proc regex(expr: string): ptr TRex = + proc match(exp: string, str: string): bool = + var error = "INVALID_REGEX" + var regex = compile(expre, error) + # TODO raise error if regex invalid + let res = regex.match(str) + regex.free + if res == 1: return true else: return false + + proc submatch(exp: string, n: int): string = + var error = "INVALID_REGEX" + var regex = compile(expre, error) + # TODO raise error if regex invalid + var sub = TRexMatch() + let res = regex.getsubexp(n, sub) + regex.free + # TODO raise error if no submatch + return sub + + proc submatches(exp: string): int = var error = "INVALID_REGEX" - return compile(expre, error) + var regex = compile(expre, error) + # TODO raise error if regex invalid + let res = regex.getsubexpcount() + regex.free + # TODO raise error if no submatch + return res