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
[4327x4]
>> parse d: "abc" [change skip 123]
>> d
== "123bc"
Isn't it weird? I would expect a123
hmm, maybe it is correct, just need a bit more of thought. Skip is 
not skipping "a", it is "matching" "a", hence defining, what should 
be replaced ...
The stack limit is so lame, almost unusable:

REBOL level recursion:

>> cnt: 0 recursion: does [++ cnt recursion] recursion
** Internal error: stack overflow

>> cnt
== 4004

Parse level recursion:

>> cnt: 0 rule: [(++ cnt) rule] parse "123" [some rule]
** Internal error: internal limit reached: parse

>> cnt
== 512
Henrik
1-Oct-2009
[4331]
I never bumped into the stack limit in R2 with parse. Is it smaller 
in R3?
Pekr
1-Oct-2009
[4332x3]
will try ...
no, it is exactly the same ...
But function example gives me == 14265 .... so - is function recursion 
stack lower in R3?
Henrik
1-Oct-2009
[4335]
I think it varies with the OS platform used. I get 1335 in OSX.
Graham
1-Oct-2009
[4336]
sounds plenty for parse
Ladislav
1-Oct-2009
[4337]
Graham: your "plenty" and my "plenty" are not the same, as it looks 
;-)
Henrik
1-Oct-2009
[4338]
But can it be controlled? I figured this is something controlled 
by the OS.
Ladislav
1-Oct-2009
[4339]
Pekr: the original rule was a little bit more complicated: paren: 
[any [#"(" paren #")"]], but still much simpler, than the above hell. 
Which is nothing compared to a trial to do the same in the case of:

bracket: [any [#"(" bracket #")" | #"[" bracket #"]"]]
Pekr
1-Oct-2009
[4340x2]
Ladislav - your recursive example reads so cleanly, whereas flat 
variant starts to remind us of regexp :-) Well, it is kinda still 
nice, that with flat variant stuff like that is possible, but that 
should not be used as an excuse, that REBOL non ability to properly 
recurse sucks ...
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
[4376]
then above R2 example is buggy too ...