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

World: r3wp

[Parse] Discussion of PARSE dialect

Pekr
1-Oct-2009
[4341]
but - the topic is probably more deep, because if it would be easy 
to make rebol tail recursive, it would already happen, no?
Ladislav
1-Oct-2009
[4342]
The fact is, that this has nothing to do with tail recursivity: neither 
of PAREN or BRACKET is tail-recursive. The only problem is, that 
the stack depth does not look sufficient to use recursive rules for 
moderately complicated cases.
Pekr
1-Oct-2009
[4343]
Is it runtime adjustable, or does it need to be tweaked for the compile/build 
time?
Ladislav
1-Oct-2009
[4344]
As far as I know, it is not adjustable yet, but Carl may have plans 
to improve that...
Gabriele
1-Oct-2009
[4345]
some of you guys has to teach me what makes my code unreadable, otherwise 
there's no way i'll ever fix it...
Pekr
1-Oct-2009
[4346x2]
will new parser enahncements help us to get better XML family support? 
:-)
I mean - we are not too strong with XML based stuff. Are new enhancements 
going to eventually simplify XML parsing? But maybe even R2 parser 
is good enough to have full XML support?
Chris
1-Oct-2009
[4348]
How can you simplify XML parsing?  What's simple about it?
Steeve
1-Oct-2009
[4349x2]
As a mirror of the [n BREAK] proposal, i suggest the [n FAIL] proposal. 

This would let you FAIL from n nested loops. Otherwise, it would 
be to FAIL out of n nested blocks.
Then,


[(p: 0) some [#"(" (++ p) | #")" if (1 <= -- p) then none | break] 
if (p = 0)]

could be remplaced by:

[(p: 0) some [if (p < 0) 2 fail | #"(" (++ p) | #")" (-- p)]]

A little more readable ?
Pekr
1-Oct-2009
[4351x4]
Since A84, AND is even more broken:

>> parse "abc" [and "a"]
** Script error: PARSE - syntax error in rule: op!
** Where: parse
** Near: parse "abc" [and "a"]
Steeve - no stuff, which uses recursion/nesting, will be ever better 
readable for user ...
From your example, it is not much obvisou, why you break/fail two 
levels? But - for more advanced parse gurus, n FAIL and n BREAK will 
surely be usefull ...
Ah, the above bug is not bug, I might know how it happened. I thought 
that we got STAY, and that AND is there too, albeit not working how 
we would like it to. But it seems that AND was just renamed to STAY, 
and so parser does not recognise AND keyword at all ...
Maxim
1-Oct-2009
[4355]
pekr, parsing an xml file itself is quite easy.  


Actually, its converting and validating the xml schema or DTD which 
is complex because, basically you have to compile a new parse rule 
out of misaligned parsing concepts.  this will never be easier, until 
someone builds (and makes public) a simple to use, *complete* interpretation 
of each XML-based spec.  XML schema, xpath, etc.
Steeve
1-Oct-2009
[4356]
I know it's an old topic, but have someone done a resolver for math 
expressions (parsing string input) ?
If not, it would be interesting to retry it with the new parse.
Sunanda
1-Oct-2009
[4357]
This (but it is not a pure-parse approach):
   http://www.rebol.org/view-script.r?script=calculese.r
Steeve
1-Oct-2009
[4358]
huge, a was expecting something tiny
Sunanda
1-Oct-2009
[4359]
Another approach here:
  http://www.rebol.com/docs/core23/rebolcore-15.html
Steeve
1-Oct-2009
[4360]
eheh, i was already reading that. A good start
Ladislav
2-Oct-2009
[4361x3]
re

    [...then none | break]

the "then none" part is unnecessary and can be safely omitted
generally, THEN can be omitted, if it is followed by a rule, that 
is known to succeed
one more note: in a rule like:

    any [... | break]


the "| break" part is totally unnecessary and can be safely removed
Steeve
2-Oct-2009
[4364x2]
Something wrong with CHANGE.

that's OK:
>> parse s: "(1)" [change "(1)" "(22)"] ?? s
s: "(22)"

that's OK too:
>> parse s: "(1)" [change "(1)" "(2)"] ?? s
s: "(2)"

That's not OK:
>> parse s: "(1)" [change "(1)" "()"] ?? s
s: "())"


If the replacement string is shorter than the matched string, then 
it fails.
A bug i mean...
Bug posted
Pekr
2-Oct-2009
[4366x2]
The result is imo OK
>> change s: "(1)" "()" s
== "())"
Steeve
2-Oct-2009
[4368x3]
why ? 
i want to change "(1)" not only "(1"
we are in parse here
it's a change/part which is performed
Pekr
2-Oct-2009
[4371x4]
simply put - you replace original string, right? You put new one 
into the string being replaced. If the new one is of the less length, 
then only such length is being replaced. If the new one is longer, 
then the string is shifted/extended.
But change/part just tells you, how many chars you replace, no? mmnt
>> change/part s: "(1)" "(2222222)"  4 s
== "(2222222)"
hmm ...
Steeve
2-Oct-2009
[4375]
change must replace the complete matched rule, it has nothing to 
do with the quality (length) of the replacement data.
I'm sure it's a bug
Pekr
2-Oct-2009
[4376x3]
then above R2 example is buggy too ...
/part -- Limits the amount to change to a given length or position.
         range -- (Type: number series port pair)
I thought that /part is there to allow us to set limit on number 
of chars being changed. Why in above case the original string got 
extended, when I limited it to 4 chars?
Steeve
2-Oct-2009
[4379]
We are in PARSE here, it has nothing to do with the behavior of CHANGE 
in normal rebol code
Pekr
2-Oct-2009
[4380x3]
Well, I might be confused as well ... not using 'change much ...
why do you repeat it? I try to point out, that it might share internal 
representation, and that might be buggy?
ah, it might be good. I don't know ...
Steeve
2-Oct-2009
[4383]
in parse, CHANGE is a shortcut for REMOVE INSERT.

>> parse s: "(1)" [change "(1)" "()"] ?? s
s: "())"

Should give the same result than:

>> parse s: "(1)" [remove "(1)" insert "()"] ?? s
s: "()"
Pekr
2-Oct-2009
[4384x2]
It clearly behaves as 'change func ...
I have a headache to find out, how 'change behaves in REBOL itself. 
Now if the parse version is supposed to behave even differently, 
then I am completly lost without the trial and error aproach in console, 
and it totally sucks ...
Steeve
2-Oct-2009
[4386]
it's not behaving the same way, if it was the same, we would not 
have this difference:

>> parse s: "(1)." [change "(1)" "(11)"] ?? s
s: "(11)."

>> head change "(1)." "(11)"
== "(11)"

In parse it's a change/part that is performed
Pekr
2-Oct-2009
[4387x2]
And as such, is correct, no?
>> head change/part "(1)." "(11)" 3
== "(11)."
Steeve
2-Oct-2009
[4389]
yep a change/part not a simple change
Pekr
2-Oct-2009
[4390]
damned, altme playing on my nerves ... another message lost ....