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

World: r3wp

[Parse] Discussion of PARSE dialect

Gabriele
28-Jun-2007
[2088]
internally it would probably have to check flags or do the permutations 
on the fly.
Ladislav
28-Jun-2007
[2089]
this is possible, but my guess, that Steeve would call it ugly too:


>> once-only: func [rule] [use [rule'] copy/deep [rule': :rule [rule' 
(rule': [end skip])]]
]

>> rule: [(a': once-only a b': once-only b c': once-only c) 3 [a' 
| b' | c']]

== [(a': once-only a b': once-only b c': once-only c) 3 [a' | b' 
| c']]
Geomol
28-Jun-2007
[2090x3]
Ladislav, that's not ugly, it's beautiful! :-)

I have a question though. Do you need the skip at the end of once-only? 
Wouldn't it work just with
rule': [end]
To do block parsing, I suggest:

>> once-only: func [:rule] [use [rule'] copy/deep [rule': :rule [rule' 
(rule': [end])]]]

>> rule: [(a': once-only 'a b': once-only 'b c': once-only 'c) 3 
[a' | b' | c']]
>> parse [c b a] rule
== true
hmm, the block parsing give wrong result, if there are less than 
3 values to parse.
Ladislav
28-Jun-2007
[2093]
John: [end skip] is a rule that surely fails, while [end] may succeed 
(at end)
Geomol
28-Jun-2007
[2094]
I see. That's also why my block parsing give false result with less 
input. So for block-parsing, it should be:

>> once-only: func [:rule] [use [rule'] copy/deep [rule': :rule [rule' 
(rule': [end skip])]]]
Ladislav
28-Jun-2007
[2095x2]
why, my rule should be usable as-is even for block parsing?
(I don't like fetched arguments)
Geomol
28-Jun-2007
[2097]
>> once-only: func [rule] [use [rule'] copy/deep [rule': :rule [rule' 
(rule': [end skip])]]]

>> rule: [(a': once-only 'a b': once-only 'b c': once-only 'c) 3 
[a' | b' | c']]
>> parse [a b c] rule
** Script Error: Invalid argument: a
Ladislav
28-Jun-2007
[2098]
in that case you can use either:

    a': once-only first ['a]

or

    a': once-only ['a]
Geomol
28-Jun-2007
[2099]
Yup, works. Nice! :-)
Steeve
28-Jun-2007
[2100x2]
Once (again)

Rebol is amazing, i think i found a simple and elegant dialect

Currently, it's not allowing recursive once usage, but it's obvious 
to do with a stack.


take: func [r] [n: 0 once/1: (length? r) + 1 / 3 once/2/2: r replace/all 
r '.. '.]
.: [(n: n + 1)]
..: [(n: n + 1) end skip]
once: [0 [(if n > 0 [poke once/2/2 n - 1 * 3 + 1  '..] n: 0) []]]


rule: [. "a" | . "b" | . "c"]
parse "CBA" [ (take rule) once]
== true
parse  "BAC" [ (take rule) once]
== true
parse  "CBA" [ (take rule) once]
== true
parse  "BBC" [ (take rule) once]
== true
parse  "CA" [ (take rule) once]
== false
parse  "CABA"[ (take rule) once]
== false
rule2: [. "a" | . "a" | . "b" | . "c"]
parse "CABA"[ (take rule2) once]
== true
(correction) 
>>parse "BBC" [(take rule) once]
== false
Anton
28-Jun-2007
[2102x2]
gnarly
:)
Steeve
28-Jun-2007
[2104x2]
gnarly ?
ok,    http://www.urbandictionary.com/define.php?term=gnarly
Tomc
28-Jun-2007
[2106x2]
data: "cab"
>> c: charset "abc" parse data [3 c]
== true
?
Steeve
28-Jun-2007
[2108x2]
>>>parse "ccc" [3 c]
==true
we want any combination of "ABC"
Tomc
28-Jun-2007
[2110]
without repeats
Steeve
28-Jun-2007
[2111x2]
yep
and that works for any type of sub-rule, no only for constants
Tomc
28-Jun-2007
[2113x2]
one shot concept
>> data: "abc"
== "abc"

>> c: charset "abc" parse data [3 [here:  c  (c: difference c to 
bitset! first :here)]]
== true
>> data: "ccc"
== "ccc"

>> c: charset "abc" parse data [3 [here:  c  (c: difference c to 
bitset! first :here)]]
== false
>>
Steeve
28-Jun-2007
[2115]
hehe, doen't work if i check for any combinations of "AABC"
Tomc
28-Jun-2007
[2116]
I should read the thread  when I have a few minutes
Steeve
28-Jun-2007
[2117]
yes you should
Tomc
28-Jun-2007
[2118]
but I will amuses myself as I please in the meanwhile.
Steeve
28-Jun-2007
[2119]
huhu
Brock
28-Jun-2007
[2120x2]
Steve, wondering if your take function solution was coded in french, 
I can't understand it  without studying it a bit more.
;-)
Steeve
28-Jun-2007
[2122x2]
it's the french touch ;-)
hey Brock , still alive ?
Tomc
29-Jun-2007
[2124x2]
do rules: [
	set 'a "first rule "
	set 'b "second rule "
	set 'c "third rule "
]

rule: [ 
	[end (if empty? erode[here: back tail :here]) :here skip]| 
	[here: erode there: 
	(	all[
			token: copy/part :here :there
			word: find rules token
			word: first back word
			remove/part find erode word 2 
		]

  all[empty? erode not tail? there insert/only erode [] there: tail 
  there]
	)] :there
    rule
]

data: "first rule second rule third rule "
erode: [ a | b | c | a]  parse/all data rule
left expanded for clarity
Steeve
30-Jun-2007
[2126x5]
i would have to discuss what follow before posting it in Rambo
parse "  a" [copy r "a"]
>>r
== " a"
i think it should be r = "a" instead
*i would have speech
Tomc
30-Jun-2007
[2131x5]
>> parse/all " a" [any " " copy r "a"]
== true
>> r
== "a"
I try toi allways yse /all when I give a block of rules
and use pases by itself aith the none rule
r: parse " a" none
["a"]
Steeve
30-Jun-2007
[2136x2]
hi Toms, as always don't focus on the example i give but on the issue 
i suggest, another one example:
>>parse "ld   a  b" ["ld" "a" copy reg ["b" | "c"]]
>> r == " b" 
>> i just think it will be more logic to have r == "b"
(replace r by reg)