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

World: r3wp

[Parse] Discussion of PARSE dialect

eFishAnt
22-Nov-2008
[3251x3]
That page of Wiki is very good to beg my case, thanks!
I remember another cool console that someone did in a web page that 
was very slick...sorry, my mind associates things that it shouldn't...my 
parser is too massively parallel...;-)
It's like closing the loop on Chris's make-doc-anywhere...but REBOL 
can be the most elegant here for that Heredoc.
BrianH
22-Nov-2008
[3254x2]
eFishAnt, the {} nesting rules only apply to strings entered in {}, 
not "". They are also only a REBOL syntax trick. Strings that you 
construct or read from somewhere don't have any special escaping 
rules or syntax.
REBOL doesn't lose what you type, but if what you are typing is treated 
as REBOL syntax, then it is interpreted as such, not lost.
Robert
23-Nov-2008
[3256x2]
I have a problem with sub-rule parsing I have:

myrules: [
	any [
		set src path! set des path! (?? src ?? des)
		| 'keyword into [
			...
		]
	]
]

If the input is

a/1 a/2
mykeyword
a/1 a/2


Only the first paths are printed. Why this? I thought the ANY rule 
keeps going on unti the end.
I think it has something to do with INTO not return true.
Oldes
23-Nov-2008
[3258]
The INTO is still just a proposal http://www.rebol.net/wiki/Parse_Project#INTO
Anton
23-Nov-2008
[3259]
Robert, your rule steps INTO the second a/1, and then, I suppose, 
fails to reach the end of it.

Show us the INTO rule, and we will tell you what is wrong with it. 
PARSE will treat the path a/1 like the block [a 1] eg:
	>> parse [a/1][into [here: (print mold here) 'a 1 1 1]]
	[a 1]
	== true

(You also wrote 'keyword in your rules, but 'mykeyword in your input. 
I'm hoping that was just a typo.)
BrianH
23-Nov-2008
[3260]
INTO is not a proposal, the proposal is to extend INTO to string 
types, possibly with a type check.
eFishAnt
23-Nov-2008
[3261]
Thanks for all the helps on parse...I have my new platform working 
100% as of this morning.  The labor of over a year of technology...and 
the code keeps getting smaller and faster.  100% REBOL.  It's all 
dialects.
Pekr
24-Nov-2008
[3262]
eFish - what is your new platform about? Still an IOS, or anything 
new? Once new rebol.com site is done, we need your success stories 
:-)
Brock
24-Nov-2008
[3263x2]
I've been hoping for these publicly for years... but you won't get 
them.  Competitive advantage, and you have to respect that.  Although, 
if the companies were left nameless and so was the author, then maybe 
he could atleast outline the concept that was involved or the problems 
that were overcome.
The impact wouldn't be as big, but it would definitely hope show 
the industrial strength of Rebol.
amacleod
24-Nov-2008
[3265]
100% rebol platform? What are we talking about here?
eFishAnt
24-Nov-2008
[3266x2]
I have another month or so before deployment.  Still lots of busy 
work, mostly more parse rules.  I probably shouldn't say much yet, 
but I was excited after a weekend of breakthroughs, and anyway, I 
wanted people to know I am even more heavily invested in REBOL than 
ever.
The {^}^{^}^{^}} problem went away by thinking about it differently, 
so now Javascript doesn't bite me any more...
Steeve
24-Nov-2008
[3268x2]
some hints ?
or u just arousing us
eFishAnt
24-Nov-2008
[3270]
a month or few and I should be ready to say more.  I just got too 
excited...;-)
Steeve
24-Nov-2008
[3271]
shame on u ;-)
Davide
3-Dec-2008
[3272]
How can I parse into a paren! ?
I've tried: 
parse [(a b)] [paren! into [word! word!]]

but It doesn't work
Maarten
3-Dec-2008
[3273x3]
>> data: [( a b )]
== [(a b)]
>> parse data [ into [set w word! set 
v word!] (print [ v w])]
b a
== true
Silly formatting on macbook paste, but you get the idea. Leave the 
paren! match out of your rule:
i.e rule: [ into [ set v word! set w word!] (print [ v w])]
Davide
3-Dec-2008
[3276x2]
Ok, the paren! consume the input, but how can I parse only paren! 
?
your rule work for (a b) and for [a b]

>> parse [[a b]] rule
a b
== true
>> parse [(a b)] rule
a b
== true
...or better, do you know where I can find a simple algebra parse 
script, which can compute simple expression like [1 + (2 /3)] ?
I'm learning how to parse, and such example would be illuminant
Dockimbel
3-Dec-2008
[3278x2]
>> rule: [mark: paren! :mark into [ set v word! set w word!] (print 
[ v w])]
>> parse [[a b]] rule
== false
>> parse [(a b)] rule
a b
== true
There's a nice example here : http://www.rebol.com/docs/core23/rebolcore-15.html#section-6, 
but it requires a string! value as input. You could adapt it to use 
a block! value as input.
Oldes
3-Dec-2008
[3280x2]
Try to play with this: http://oldes.multimedia.cz/rebol/expr-test.r
or:
http://oldes.multimedia.cz/rebol/expr-test2.r
http://oldes.multimedia.cz/rebol/expr-test3.r
Davide
3-Dec-2008
[3282x3]
thanks ! I'm going to study it
ok this is my first attempt for a basic expression parser

stack: copy []
push: func [x] [insert stack x]
pop: does [take stack]
term: [
	pos: paren! :pos into [expr] (push rejoin ["(" pop ")"]) |
	set t string! (push mold t ) | 

 set sign opt ['+ | '-] set t number! (if none? sign [sign: '+] push 
 mold (t * to-integer join sign "1")) | 

 set gp path! (push rejoin [{$('#} first gp {').attr('} second gp 
 {')} ]) 
]
oper: compose ['+ | '- | '* | (to-lit-word "/")]
operrule: [set o oper (push o)]

expr: [term any [operrule term (t2: pop o: pop t1: pop push rejoin 
[t1 o t2])]]


I'm sure it's not optimized nor correct, so any correction is welcome.
it can parse expression like: [- 1 * (a/b + 2)] and it emits a javascript 
compatible string.
(is a part of a comet server written in rebol)
Oldes
4-Dec-2008
[3285x3]
instead of:

set sign opt ['+ | '-] set t number! (if none? sign [sign: '+] push 
mold (t * to-integer join sign "1")) |
I would use something like:
    set t number! (push mold t ) |
 '- set t number! (push mold negate t ) |

(Which is not perfect as well)
because the above will not work for expressions like: [ - (1 + 1)]
also I'm not sure, if the mold is needed
Brock
4-Dec-2008
[3288x5]
I am having some parse difficulties.  I have the below code...
records: read/lines http://www.geocities.com/[kalef-:-rogers-:-com]/samples.txt
lang-rule: [
	thru "language%3a" copy language to "+%2b" |
	thru "language%3a" copy language to "&resultview" |
	thru "language%3a" copy language to "&"
	;thru "language="   copy language to "&" |
]
rec: 1
foreach record records[
	language: copy ""
	parse record [lang-rule]
	print [rec tab language]
	rec: rec + 1
]
in the parse rule  lang-rule.  It seems that only two of the three 
rules work at any one time with the data I have loaded. (note the 
last rule is commented out)
If I change the order of the rules and place the pipe or bar '|' 
as appropriate, I can't get all three of these rules to work together.
I expect the output to be either the text 'en' or 'fr'  (for english 
or french) for each record, however records 52 & 66 the parse is 
not ending properly for the current setup.  If you change the order 
of the rules, then other records will not work as expected.   Any 
ideas?
Oldes
4-Dec-2008
[3293]
lang-rule: [
	thru "language%3a" copy language ["en" | "fr"] to end
]
Chris
4-Dec-2008
[3294]
You could dehex first?  That would make things more consistent...
Brock
4-Dec-2008
[3295x2]
thanks for the suggestions.  I never thought of using the actual 
text I was expecting as an option like you suggested Oldes.
Okay Oldes, your solution works, but why does my code fail, any ideas? 
 I have other scenarios that follow this same sort of structure but 
do not have a simple two word expected result.  I've been able to 
handle these so far, simply by changing the order and moving the 
'stop' word of the Ampersand to the bottom of the rule options.  
[I'm trying Chris's option now]
Davide
4-Dec-2008
[3297]
I'm here again ! 

Is possible to write a rule that match any word! but those that are 
in a block ?
example:

list: ['for 'while 'show]
parse block [any [word! *NOT IN* list]]

If there's no a direct approach, is there a workaround ?
Oldes
4-Dec-2008
[3298x3]
Brock: it'sbecause in rows 52 and 66 you find "+%2b".It'snot next 
to lang value you want, but it's there so the first rule is true.
You can use this for any lang-id with 2 chars:
lang-chars: charset [#"a" - #"z"]
lang-rule: [
	thru "language%3a" copy language 2 lang-chars to end
]
I would not use dehexas with dehex you parse the data twiceso it 
must be slower.