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

World: r3wp

[Parse] Discussion of PARSE dialect

Ladislav
1-Dec-2010
[5372]
I have seen that proposed, but it is not available currently (I would 
support such a proposal, though)
Steeve
1-Dec-2010
[5373x2]
Ladislav, It's working in R3 currently
since a while
Ladislav
1-Dec-2010
[5375]
Checking
BrianH
1-Dec-2010
[5376]
That's what I thought. I originally proposed that kind of input switching 
in 2000. It can cause problems with backtracking though, so a sub-parse 
in an IF operation can be safer.
Steeve
1-Dec-2010
[5377]
Lot of back tracking problems may arrise in a lot of way when you 
do parsing.
I'm not sure it's an argument :-)
BrianH
1-Dec-2010
[5378]
There are no backtracking problems with COPY x TO thing IF (parse 
x rule). But that was the original reason we didn't have input switching. 
The reason I requested input switching in the first place was to 
make it easier to implement the continuous parsing that Pekr was 
requesting at the time :)
Steeve
1-Dec-2010
[5379]
I don'"t see where is the problem, you just have to switch back the 
original serie if the sub-rule fail, no need of if (parse ...) thing
BrianH
1-Dec-2010
[5380]
Originally, only position was reset, not series reference. I would 
welcome tests that show what the current behavior is. Ladislav?
Steeve
1-Dec-2010
[5381x2]
I didn't say the reference was restored automaticly , you have to 
do it yourself.
....
restore: [:switch-serie sub-rule | :restore]
BrianH
1-Dec-2010
[5383]
If it is not restored automatically on failure, backtracking and 
alternation, then that is a problem that needs a ticket submitted 
for it.
Steeve
1-Dec-2010
[5384x2]
Agreed, It would be a nice improvment
but it may slow down parse, no ?
BrianH
1-Dec-2010
[5386]
Not much, just one more pointer assignment at alternation.
Steeve
1-Dec-2010
[5387]
Ladislav, are you  lost in translation ?
Or are you crying :-)
BrianH
1-Dec-2010
[5388x4]
It fails. Here is the test code that I will put in the ticket:
>> a: "a" b: "b" parse a [:b "b" (print true) fail | "a"]
true
== false  ; should be true
>> a: "a" b: "b" parse a [:b "b" (print true) fail | "b"]
true
== true  ; should be false
So, half of the request succeeds: You can set the position to another 
series. I wonder if you can change series types from string to block.
Yup, you can.
It is not a simple problem though, as not only would you have to 
add a series reference to the fallback state but you would need to 
make those series references visible to the garbage collector so 
they won't be freed; backtracking to a freed series would be bad.
Steeve
1-Dec-2010
[5392x2]
parse is freeing is own allocated ressources currenlty, what would 
that be a problem to pursue ?
*why would that be...
BrianH
1-Dec-2010
[5394]
What if someone runs RECYCLE in a paren? It would need to know what 
to not collect.
Steeve
1-Dec-2010
[5395]
I mean, Parse must use a sort of stack to keep the backtracking references. 
The series will not be freed until parse destroy his stack
BrianH
1-Dec-2010
[5396]
Right now it is a stack of integers (position) and a single pointer 
(series reference). To do this it would need to be a stack of series 
references too, and the collector would need to be informed of its 
exdistence so it could scan it for references.
Steeve
1-Dec-2010
[5397]
That's why I said previously, it may slown down the whole process.
BrianH
1-Dec-2010
[5398]
Yup. The ticket needs to be made either way. If it is rejected it 
will serve as documentation of the issue.
Ladislav
1-Dec-2010
[5399x2]
It can cause problems with backtracking though
 - actually, it can't, as can be demonstrated easily
(when implemented properly, of course)
BrianH
1-Dec-2010
[5401]
Submitted as #1787, with the "when implemented properly" workarounds 
that Ladislav was mentioning. Note: Just because there is a solution 
to a problem doesn't make it not a problem - it just makes it a problem 
that can be solved.
Ladislav
1-Dec-2010
[5402]
aha, so, now the get-words can set parse to a different series (INTO 
does that as well!), but, what is restored, is just the index, not 
the series... (except for the return from INTO, when the series is 
restored as well
BrianH
1-Dec-2010
[5403x2]
Yup. A half-solution, but we have workarounds for the other half 
:)
One interesting thing is that you can switch from string to block 
parsing and back mid-rule using series switching :)
Ladislav
1-Dec-2010
[5405]
Well, since it has been solved for INTO, it should suffice to use 
the already existing INTO solution
BrianH
1-Dec-2010
[5406x2]
Yup, that would be preferred. And please mention that in a ticket 
comment to #1787 :)
Otherwise I will mention this in a comment and attribute the idea 
to you :)
Ladislav
1-Dec-2010
[5408]
so, Oldes, you should try this, which should be the exact equivalent 
of your rule, except for the fact, that it does not call Parse recursively:

some [
    thru {<h2><a} thru ">" copy name to {<}
    ; copy the DOC
    copy doc to {^/ </div>}
	; remember the DOC-END
	doc-end:
	; switch to DOC parsing
	:doc
    thru {<pre class="code">} copy code to {</pre} (
        probe name
        probe code
	)
    any [
        thru {<h5>} copy arg to {<}
        thru {<ol><p>} copy arg-desc to {</p></ol>}
        (printf ["  * " 10 " - "] reduce [arg arg-desc])
    ]
    ; switch to original input
    :doc-end
]
BrianH
1-Dec-2010
[5409]
Thanks, Ladislav :)
Steeve
2-Dec-2010
[5410]
Submitted as #1787, with the 

when implemented properly" workarounds that Ladislav was mentioning. 
Note: Just because there is a solution to a problem doesn't make 
it not a problem - it just makes it a problem that can be solved."


Geez, I'm not a Sissy ,But I pointed the workaround  from the beginning. 
Sometimes I just have the weird feeling I'm not trusted enough.
Sorry, I stop the whinning now :-)
Ladislav
2-Dec-2010
[5411x4]
Yes, Steeve, I know, that this has been discussed a while ago. Nevertheless, 
it is worth the effort to have it in a comment to the ticket.
(does not matter much to me who puts it in, though)
I just wanted to make sure to point at INTO, since it is already 
implemented, and working fine.
(and doing the same thing, at least in principle)
BrianH
2-Dec-2010
[5415x3]
Yes, and a good point it was too.
Steeve, I'm sure that the reason it was so easy for me to come up 
with workarounds off the top of my head on a weak-brain day was because 
I had seen them before when you pointed them out and didn't remember 
it directly. In any case, I'm sure your stuff was great.
The ticket was for documentation purposes, as well as a request. 
It was to summarize the conversation from before.
Oldes
2-Dec-2010
[5418x2]
Steeve, Ladislav... sorry, but your version is not working. The main 
SOME rule finds only one match and than stops. Maybe I should give 
you a simple test string so you could test it first.
hm.. it works on simple test, don't know why it stops for my real 
data.
Ladislav
2-Dec-2010
[5420]
that is interesting, (my version differs from Steeve's), but should 
be as similar to your version as possible
Oldes
2-Dec-2010
[5421]
My simplified test is:
parse test: {[{1}{2}][{3}{4}][]} [
	some [
	    thru {[} 
	    ; copy the DOC
	    copy doc to {]}
		; remember the DOC-END
		doc-end:
		; switch to DOC parsing
		:doc
		(print "start")
		any [
			thru "{" copy n to "}" (probe n)
		]
	    ; switch to original input
	    (print "end")
	    :doc-end
	]
]
that's working as expected.