r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Parse] Discussion of PARSE dialect

Steeve
27-Jun-2007
[1939x3]
but if the entry is more complex like [a: 1 huge tight  b: 1] and 
that i want parse all this values in any order ?
and in your example , you don't test that we must encounter 'a and 
'b
i give another one example , more simple

i want to parse the serie "ABC" but it could be the serie "BCA" , 
"CBA" , "ACB" ... any combination

so if i could write parse "ABC" [all ["A" | "B" [ "C" ]]  , it should 
be more simple
btiffin
27-Jun-2007
[1942]
Again, I'm not a parser, but parse's support of alternates with some 
and any covers these cases no?
Steeve
27-Jun-2007
[1943x2]
no
if you write  parse "AB" [some ["A" |  "B" | "C"]]
btiffin
27-Jun-2007
[1945]
parse "ABC" [ 0 1 "A" | 0 1 "B" | 0 1 "C"] ?
Steeve
27-Jun-2007
[1946]
you get a true answer, but that not the case
btiffin
27-Jun-2007
[1947x2]
I think I'm clue'in to what you mean.  I'll leave this to the pros... 
 :)
like my use of 0 1 can be opt...  :)
Steeve
27-Jun-2007
[1949x2]
anyway, you're example just don't work ^^
*anyway your example just doesn't work (fewwww)
btiffin
27-Jun-2007
[1951]
Yep.  I'm out.  Not experienced enough to have piped up...  ;)
Steeve
27-Jun-2007
[1952x2]
and what is your mater ? ;-)
we can talk of rebcode if you want :-)
btiffin
27-Jun-2007
[1954]
Thinking about this one, you'd have to repeat all the alternatives. 
 Defeating the purpose...but I'll bet Chris or Geomol or Anton or... 
will have a workable solution posted before ya know it.
Steeve
27-Jun-2007
[1955]
i h'ave many alternatives (all comsuming lot of code)  that's not 
the point, i just think it could be more elegant to have such a command
btiffin
27-Jun-2007
[1956]
Maybe we could hold side bets on which rebol will come up with the 
solution first...I'd put money down on Oldes or Volker giving you 
a workable  :)
Steeve
27-Jun-2007
[1957]
if you say so, i  tried many alternatives, but they are all uggly
Brock
27-Jun-2007
[1958]
try this... parse "AB" [some ["A" |  "B" | "C"] | none 
]
Steeve
27-Jun-2007
[1959]
i don't want to parse "AB" but any combinations of "ABC"
btiffin
27-Jun-2007
[1960]
His works.  I tried it without the terminating  | none  and it spun 
out, so I didn't mention it  :)
Steeve
27-Jun-2007
[1961x2]
parse "AB" sould return false
not true
Brock
27-Jun-2007
[1963x2]
why would AB return false?
so it must be three characters?
Steeve
27-Jun-2007
[1965x2]
because i want parse the complete serie "ABC" in any combination
yes 3 characters
btiffin
27-Jun-2007
[1967]
What it you put 1 repeats inside the some?
Steeve
27-Jun-2007
[1968]
write it plz
btiffin
27-Jun-2007
[1969]
nevermind...  just tried it.   piping up out of turn again  :)
Steeve
27-Jun-2007
[1970x2]
i just don't understand what you mean
ah ok, it doesn't work :-)
Brock
27-Jun-2007
[1972]
do all three characters need to be present?
btiffin
27-Jun-2007
[1973]
I tried  parse "AB" [some [1 "A" | 1 "B" | 1 "C"] | none]   ...returns 
true
Brock
27-Jun-2007
[1974]
or can characters be duplicated?
Steeve
27-Jun-2007
[1975]
no Brock
Brock
27-Jun-2007
[1976]
the | none handles situations where the rule doesn't apply, so almost 
everything will return true
btiffin
27-Jun-2007
[1977]
Brock;  Without it it'll endless loop no?
Steeve
27-Jun-2007
[1978x2]
no
just never use an ''opt" rule in a some or any block
Brock
27-Jun-2007
[1980]
will it just be instances of A B & C?
Steeve
27-Jun-2007
[1981x6]
one instance of each in any order (but just one instance)
the awaiting result is 
a: b: c: false

parse "CAB" [some ["A" (a: true) | "B" (b: true) | "C" (c: true)]] 
if all [a b c ] [print "ok"]
*expecting result
except that this code is wrong for series with repeting characters 
like "AABCC"
(should increment a b and c instead using boolean)
anyway , that's not the point , i know how to do that, but i just 
 think it's ugly
btiffin
27-Jun-2007
[1987x2]
parse "ABC" [3 [1 "A" | 1 "B" | 1 "C"]]  ?
nevermind...  :)  AAA returns true