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

World: r3wp

[Parse] Discussion of PARSE dialect

BrianH
8-Nov-2008
[3060]
Rewrite rules usually work this way.
Steeve
8-Nov-2008
[3061]
about your proposal i just will say that is not an high request but 
if it's free i take it
BrianH
8-Nov-2008
[3062]
I think it will be better to include this in the tracing infrastructure.
Steeve
8-Nov-2008
[3063x3]
ok another proposal
currently when we parsing a serie we can't mix constant string! and 
constant binaries together
we have to choose depending of the type of the serie
BrianH
8-Nov-2008
[3066x3]
That will be moreso in R3 because string! and binary! aren't compatible 
any more.
Unicode changes. A binary is a series of bytes, a string is a series 
of codepoints.
AS-STRING and AS_BINARY are gone.
Steeve
8-Nov-2008
[3069]
but at certain point a string can be converted to a binary an vice 
versa
BrianH
8-Nov-2008
[3070x2]
Yes, but that is a real conversion, with encoding and decoding.
Just like converting from a .jpg to an image! and back.
Steeve
8-Nov-2008
[3072]
when u say 'real' u mean a large time consuming conversion ?
BrianH
8-Nov-2008
[3073x2]
Hopefully not time-consuming but definitely large, depending on the 
size of the string.
The Unicode changes were pretty significant and deep.
Steeve
8-Nov-2008
[3075x3]
not the subject, but speaking of consuming operations, what about 
the old idea to have subset of serie (range) without the need to 
copy/part series ?
Carl spoken of that in the past
*abouty
BrianH
8-Nov-2008
[3078]
It was rejected as a base type because it was deemed unnecessary, 
but could be added as a UDT.
Steeve
8-Nov-2008
[3079x3]
UDT ?
about proposals, currently we have only one atom operation to control 
advance in the serie: [skip].
We could had some other atom operations, like DROP,SWAP,ROT,DUP.
(any reference to FORTH language are intentional)
don't ask me an usage, it's only because i'm currently working on 
a FORTH engine
BrianH
8-Nov-2008
[3082x3]
UDT = user-defined datatype!, a planned feature of R3. Yes, this 
includes user-defined function types in theory.
DROP, SWAP, ROT and DUP are stack modification operations, not parse 
advancement operations like SKIP. Don't forget REVERSE and matching 
operations - they advance too.
My bad: REVERSE doesn't advance.
Steeve
8-Nov-2008
[3085x6]
i know what they are (trust me) it was a sort of transposition to 
parse
image just that parsing a serie is like working with a stack, the 
analogy is not as bad as you think
*imagine
in an other way, SWAP, ROT, DUP or DROP are not just advance operations 
, they modify the serie too.
... I really don't what could be their usage, forget that...
*don't know
Anton
8-Nov-2008
[3091]
Just some ideas for possible usage.


[[item1 item2 | item2 item1 SWAP] ]   ; Put previous two matched 
items in order.
==> [item1 item2]  ; Always sorted.


[ROT [a b c d e]] ;  Rotate items matched by next subrule, if it 
matches. 
==> [b c d e a]  ; 


[start: a [b c] DUP start]  ; Duplicate items from start to current 
parse index.
==>  [a b c a b c]


[a DROP [b c]] ; If next subrule matches, then remove items matched, 
and set parse index back to the beginning of the remove.
==>  [a]

(DROP is just like REMOVE, so not really needed, I think. Just doing 
the exercise to see.)

The above can be categorized by how they fetch their arguments:
- Take two previously matched items/subrules (like SWAP).
- Match the next subrule (like ROT, DROP).
- Use a variable to take the parse index (like DUP).
Steeve
8-Nov-2008
[3092]
well done Anton. To have a more genralized form, all these operations 
could work on an Index, like your DUP
Anton
8-Nov-2008
[3093x2]
We can implement DUP today using our own function (not a parse command). 
The equivalent to above DUP example would be:

[start: a [b c] finish: (DUP start finish length: finish - start) 
skip length]
or maybe

[start: a [b c] finish: (DUP start 'finish) :finish]  ; (where DUP 
modifies 'finish)
So that's what the DUP command would save us.
Pekr
9-Nov-2008
[3095]
BrianH: as for parse catching infinite loops - don't you think that 
ppl would always want to be protected by such a feature? So why not 
make it standard? How usefull is parse, if it loops infinitely? Your 
app hangs, or crashes anyway ...
Oldes
9-Nov-2008
[3096]
not always. if you need maximal speed. and you  trust the data and 
rules.
Henrik
9-Nov-2008
[3097]
Hanging parsers to me is usually a problem when developing them.
Anton
9-Nov-2008
[3098x4]
Steve said in r3-alpha world:

Sometimes some of my parse rules can take overnight to resolve on 
some complex random files...and I would like to be able to set a 
time limit in parse so that if it is recursively grinding on time, 
that I can halt it
So Steve needs to leave his parse rule unattended for long periods.
And when he returns, if it timed out, he wants to see where it got 
up to.
I think this can be done by precompiling the parse rule, so that 
every step also does a profiling test. This will slow down the parse 
a bit, but hey, you get your information.
Pekr
9-Nov-2008
[3102]
... you can as well use profiler to see, where your parse hangs.
Anton
9-Nov-2008
[3103x3]
Paul, in the Parse blog comments section:
http://www.rebol.net/cgi-bin/r3blog.r?view=0155#comments

you wrote: "I would like to see Parse be able to return true on Datatype! 
value."
Could you clarify this ?
I think PARSE does this already:
	parse reduce [integer!] [datatype!] ;== true
Maybe you wanted not to have to reduce.  eg:

	parse reduce [ 'integer! integer! ] [ datatype! datatype! ]


would return true, even though only one of the two input values is 
of type datatype!

If that is the case, then I think this came up already some time 
in the past. I think, as then, that it was a bad idea, because it 
causes a distinguishability problem. PARSE would sometimes not be 
able to distinguish between a word! and a datatype!. This would cause 
problems when parsing code, because you would have to test if words 
looked like datatypes, and treat them specially.
[unknown: 5]
9-Nov-2008
[3106]
Anton, trying creating a word string! and a datatype! string! value 
and insert into a block.  [string! string!]  and then do your testing. 
 I remember discussing this with BrianH when I ran into the issue. 
 I don't have REBOL on the computer I'm currently working from right 
now so I can't present any test at the moment and I'm turning this 
laptop back in to the company soon.
Anton
9-Nov-2008
[3107]
That's essentially the same as the example above, isn't it ?
You want this to return true:

	parse reduce [ 'string! string! ] [ datatype! datatype! ]

?
[unknown: 5]
9-Nov-2008
[3108x2]
Yes, I believe we didn't want to reduce.
I don't think there is a way around it at this time without digging 
into parse code itself.