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

World: r3wp

[Parse] Discussion of PARSE dialect

Oldes
2-Dec-2010
[5419]
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
[5421x2]
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.
I understand the principe, but as I say, on real file it stops.
Ladislav
2-Dec-2010
[5423x3]
may be a Parse bug, e.g.
so, it is worth testing
What does "stops" mean, BTW?
Oldes
2-Dec-2010
[5426]
you can test real data as well:)

print "loading data"
data: read/string http://www.imagemagick.org/api/magick-image.php
ask "parsing version 1"
parse/all data [
	some [
	    thru {<h2><a} thru ">" copy name to {<}
	    doc-start: to {^/ </div>} doc-end: :doc-start
		[
	        thru {<pre class="code">} copy code to {</pre} (
	            probe name
	            probe code
	        )
	        any [
	            thru {<h5>}
				here: if (lesser? index? here index? doc-end)
				copy arg to {<}
	            thru {<ol><p>} copy arg-desc to {</p></ol>}
	            (printf ["  * " 10 " - "] reduce [arg arg-desc])
	        ] 
	    ]
	    :doc-end
	]
]
ask "parsing version 2"
parse/all data [
	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
	]
]
Ladislav
2-Dec-2010
[5427x2]
aha, it needs to be written this way:

parse/all data [
	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
		; we need OPT to be able switch back
		:doc opt [
	        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
	]
]
since OPT was needed, it is provable, that the "inner parse" fails 
sometimes, which does not look desirable, and may provoke your attention, 
Oldes
Oldes
2-Dec-2010
[5429x2]
I've got it.. there is missing <pre> in the third doc so that's why 
Steeve's version fails.
(I wonder what they use to document the ImageMagick project.. it 
does not look like fully automated documentation. There are also 
some typos in the spec names.)
Steeve
14-Jan-2011
[5431]
I'm working on an incremental lexer able to perform line-by-line 
analysis of any plain text documents.

the idea is to allow editing without having to reparse all the document.

The syntactical rules will be regular parse rules easy to understand 
and to modify, to facilitate
the creation of different model of document.

Of course, the first target is a rebol parser, but the make-doc format 
is also in my short range.

If anyone already have deep thoughts about the subject, please share 
your opinions.
I will come with a proto soon enough.
BrianH
14-Jan-2011
[5432x2]
Will the REBOL parser be using the R3 incremental parser, TRANSCODE 
?
Btw, if you are using PARSE for incremental parsing, watch out for 
this: http://issue.cc/r3/1787
shadwolf
14-Jan-2011
[5434]
what is the equivalent in R3  of disarm ?
BrianH
14-Jan-2011
[5435x2]
Nothing, it's unnecessary in R3.
You have to DO an error explicitly to trigger it. Otherwise, you 
can just reference it directly as if it were an object.
shadwolf
14-Jan-2011
[5437]
value: disarm :value 
 how i translate that ?
Steeve
14-Jan-2011
[5438]
you  don't need to, just use the /error refinemeent with transcode.
>> transcode/next/error
and you get an error object if any
Sunanda
14-Jan-2011
[5439]
[!REBOL3 Parse group now exists for specific R3 Parse discussions]
Steeve
14-Jan-2011
[5440]
ok thx
shadwolf
14-Jan-2011
[5441x3]
steeve it's in the colorize function code of area tc ...
either error? :value [
                        value: disarm :value
how do I adapt that ?
BrianH
14-Jan-2011
[5444]
value: disarm :value 
Just get rid of the line.
shadwolf
14-Jan-2011
[5445x2]
ok ...
and this how i use transcode in it ? instead of load/next here ? 
>> error? set/any [value end] try [load/next start]
Steeve
14-Jan-2011
[5447]
Shad, I will do it if you wait a little
shadwolf
14-Jan-2011
[5448x2]
I can do it now either way i need to understand the way R3 handle 
things
since the disarm is gone this like don't work anymore either value/arg2/1
BrianH
14-Jan-2011
[5450]
It depends on the circumstances. Once an error is triggered it can't 
be referred to again until it is caught by TRY, which disarms it.
Oldes
15-Jan-2011
[5451x2]
You don't need disarm in R3:

>> if error? set/any 'err try [1 / 0][ probe err true]
make error! [
    code: 400
    type: 'Math
    id: 'zero-divide
    arg1: none
    arg2: none
    arg3: none
    near: [/ 0]
    where: [/ try]
]
== true
Do we need the set/any or is enough just:
	if error? err: try [1 / 0][ probe err true]
TomBon
15-Feb-2011
[5453x3]
how to copy a parsed stream into a object instead a string var?
this fails
parse page [thru <tag1>  copy obj-buffer/result   to <tag2>]
** Script Error: Invalid argument: obj-buffer/result
ok, looks like this is working.


parse page [thru <tag1>  copy a  to <tag2> (obj-buffer/result : copy 
a)]
Pekr
22-Feb-2011
[5456]
Common parse patterns request - http://www.rebol.com/article/0508.html
james_nak
22-Feb-2011
[5457]
Thanks Pekr for drawing that to my attention.
Gregg
26-Feb-2011
[5458]
If it's a patterns page, it shouldn't be R3 specific. If patterns 
require different implementations in R2 and R3, those can be filled 
in, or stubbed out with a note as to why it is either not needed 
or not worth the effort in one version or the other.
BrianH
26-Feb-2011
[5459x3]
Every pattern should have an R2 and R3 version, with explanations.
Also, every new R3 operation should have an R2 equivalent in the 
pattern list. The parse proposals page can be mined for examples.
IIRC there's only one new R3 op that doesn't have an R2 equivalent, 
but it might not be implemented yet. Let me check.
Gregg
26-Feb-2011
[5462]
I just didn't want to remove the R3-only comments without some discussion, 
in case there was a reason for them being there.
BrianH
26-Feb-2011
[5463]
Yup, agreed. Just checked, LIMIT, the one proposal with no R2 equivalent 
hasn't been implemented yet.
Geocaching
11-Mar-2011
[5464x2]
Hello
Hello, I am struggling to build a parser of equation. The idea is 
a function who would take sth like "SQRT(1-x^2)/(1-x)^3" and return 
a block of rebol code: [divide square-root subtract 1 power x 2 power 
subtract 1 x 3].
Anyone has done it already?
Gregg
11-Mar-2011
[5466]
I know Gabriele has done something along those lines, and I'm sure 
others have as well. I don't know of any that return REBOL code. 
Can you be more specific about what problems you're having?
Ladislav
11-Mar-2011
[5467x2]
Geocachi, see

http://www.fm.tul.cz/~ladislav/rebol/evaluate.r
(can return Rebol code)