Reputation: 766
I need a rule, let call it AT-BEGIN, that matches the begin of input.
Maybe it exists, or how to implement it?
EXAMPLES I WANT TO WORK:
MOTIVATION:
I'm try parsing some markdown-like patterns, where an '*' starts emphasis, but only if after a space, or at beginning of text: [space | at-begin] emphasis
Using @hostilefork solution I could write:
[to "*" pos: [if (head? pos) | (pos: back pos) :pos space] skip ...]
Upvotes: 2
Views: 148
Reputation: 139
Maybe not exactly what you want, but finding the first match can be done by the following.
You have to search for the pattern of complement to "b" followed by "a".
>> text-to-searh: "jjjj ball adran"
>> b*: complement charset "b"
>> parse/all text-to-search [ any [ b* #"a" | "a" hit: to end | skip ] ]
>> probe hit
"ll adran"
Needs some modification to also match the case that first char is "a".
hit
will be positioned at the character following the "a".
Upvotes: 0
Reputation: 33607
There's no such rule. But if there were, you'd have to define if you specifically want to know if it's at the beginning of a series...or at the beginning of where you were asked to start the parse from. e.g. should this succeed or fail?
parse (next "cab") [to "a" begin skip "b"]
It's not at the beginning of the series but the parse position has not moved. Does that count as the beginning?
If you want a test just for the beginning of the series:
[to "a" pos: if (head? pos) ...]
You'd have to capture the position at the beginning or otherwise know it to see if the parse position had advanced at all:
[start: to "a" pos: if (pos = start) ...]
Upvotes: 1