At 11:41 PM 11/18/99 +0100, you wrote:
>I've got a little parse problem. I try to parse something like
>a1=1, a2=2, a3=3, a4
>where a1 to a3 have to be present, a4 may or may not be there,
>it is unspecified, which is at which position, and they may be
>on subsequent lines, without the commas seperating them.
>
>Any ideas on how to best parse this, to get the values for a1 
>to a3 and the presence of a4, respectively? 

Assuming that the digits after the equal can be any digit 0..9, but only
single digits, and that we are interested in the value of a4, this works:

result: make block! []

a: #"a"
equal: #"="
index: charset "123"
index-4: #"4"

digits: charset "0123456789"

items: [a index equal copy value digits (append result value)]
item-4: [a index-4 equal copy value digits (append result value)]

rule: [some items | item-4 | skip]

pairs: "a1=1, a2=2, a3=3"

pairs-and-4: "a1=1, a2=2, a3=3, a4=4"

>> parse/all pairs [(clear result) some rule]
== true
>> print result
1 2 3
>> parse/all pairs-and-4 [(clear result) some rule]
== true
>> print result
1 2 3 4

Elan

Reply via email to