|
Introduction
OmniMark's pattern matcher is greedy -- it consumes any character it matches. Where you want to match text up to a certain pattern but not consume that pattern the lookahead
keyword is useful. The functionality of lookahead can be packaged up in a neat macro that lets you match "upto" a given pattern. The "upto" macro can be used as follows:
find "begin" upto("end") => middle output middle find "end" output "fin"
This code outputs everything between, but not including, "begin" and "end". "end" is not consumed by the first rule, so it will be matched by the second rule, which will output "fin".
macro upto (arg pat) is ((lookahead not (pat)) any)+ macro-end
---- |