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

World: r3wp

[Parse] Discussion of PARSE dialect

Oldes
4-Dec-2008
[3301x3]
You can use this if there may be url-encoded data and not encoded 
as well:
lang-chars: charset [#"a" - #"z"]
lang-rule: [
	thru "language" ["%3a" | "="] copy language 2 lang-chars to end
]
btw. you can also  use:
parse "language=xx" lang-rule
Davide.. in R2:
list: ['for | 'while | 'show]
parse [for each while end] [any [list | set w word! (probe w)]]
In R3 it should be better I think.
Chris
4-Dec-2008
[3304]
dehex, agreed -- until the speed trade off becomes worth it.  Which 
may be if you are wanting to get more than just the language from 
the string.
Brock
4-Dec-2008
[3305x2]
Oldes, thanks for ripping into that with so many options.  To your 
first response - of course, didn't notice that.  Your last response 
is not obvious to me what that does, I'll need to look at that more.
Dehex isn't an issue for me really.  I am only taking  a very small 
percentage of records.  So in the big picture, it's not a significant 
slow-down.  The process this is attached to runs daily on a group 
of text files totalling less than 10 MB in size.
Jerry
6-Dec-2008
[3307]
I was pasing something. I got this:
 ** Script Error: Internal limit reached
I still don't know what's wrong. Anybody?
sqlab
6-Dec-2008
[3308]
Too many recursions.
Maybe the rule is too complex or you get an infinte loop.
Just show your rule and the problem.
For sure someone will help.
Davide
6-Dec-2008
[3309]
Thanks Oldes, I've tried your hint, but it made my parse rule too 
complex, so I've used an additional word as discriminant.
Hope that R3 will improve this.
Jerry
7-Dec-2008
[3310]
sqlab, your are right. There is an infinite loop. I am fixing it. 
It's a C++ parser, so the rule is very complicated.
Maxim
24-Dec-2008
[3311x3]
paul asked: "Question for you regarding parse.  How do you force 
parse to return false immediately without processing the rest of 
the string or block one it evaluates a paren?"
example: 


parse/all s [some ["12345" here: (print "*" here: tail here) :here 
skip]]


basically, in the paren, you assing the tail of the data being parsed, 
and force parse to move to it, then try going beyond....  the skip 
makes it return false, otherwise it returns true.
oops example forgot string to parse... hehehe

>> s: "12345 12345 12345"
== "12345 12345 12345"

>> parse/all s [some ["12345" here: (print "*" here: tail here) :here]]
*
== true

>> parse/all s [some ["12345" here: (print "*" here: tail here) :here 
skip]]
*
== false
[unknown: 5]
24-Dec-2008
[3314x2]
Not exactly what I'm talking about.
Well maybe...
Steeve
24-Dec-2008
[3316]
parse/all s [some ["12345" (print "*") end skip]
is that not enough ?
[unknown: 5]
24-Dec-2008
[3317]
Well the skip is  going to produce false unless you know how much 
to skip
Maxim
24-Dec-2008
[3318x3]
the here: tail here: is just the code you assign IF something you 
want to check programatically matched.
now the question, paul, is do you want the WHOLE parse to fail, or 
just that rule?  up to the paren?
or do you want to do, basically, look ahead assertion?
BrianH
24-Dec-2008
[3321x2]
The skip will produce false because it is attempting to skip past 
the end.
The phrase [end skip] will always fail and return false.
[unknown: 5]
24-Dec-2008
[3323x2]
What I'm talking about is this:

words: [this that blah]


result: parse [this that bleh blah][some [set w word! (unless find 
words w [do something to return false here)]]
result should evaluate to false in my example
BrianH
24-Dec-2008
[3325]
For now, you want a continuation variable. Like this:

result: parse [this that bleh blah][some [set w word! (cont: unless 
find words w [[end skip]]) cont]]
Steeve
24-Dec-2008
[3326x2]
continue: none	;means continue is ok
stop: [end skip]

result: parse [this that bleh blah][some [set w word! (unless find 
words w [continue: stop]) continue]]
ahah, same idea
[unknown: 5]
24-Dec-2008
[3328x2]
Brian, I thought I tried that.
checking that one hold on.
Maxim
24-Dec-2008
[3330x2]
I was working on another idea where only THAT rule failed !
for a general failure, the above works for sure.
[unknown: 5]
24-Dec-2008
[3332]
yeah that will work Brian.  i think I was setting the word that I 
had placed at the end and that is why it failed before.
BrianH
24-Dec-2008
[3333]
That is the equivalent of the CHECK proposal.
[unknown: 5]
24-Dec-2008
[3334]
What is the Check proposal?
Maxim
24-Dec-2008
[3335]
look in:   http://www.rebol.net/wiki/Parse_Project
BrianH
24-Dec-2008
[3336]
Read the parse proposals linked above.
Maxim
24-Dec-2008
[3337]
its also a good read to know many of the "tricks" in parse   :-)
[unknown: 5]
24-Dec-2008
[3338]
By the way what I currently have been doing is setting a value to 
another word to differentiate why the parse failed - whether it was 
syntax or because of an invalid word.
Maxim
24-Dec-2008
[3339]
(of R2)
BrianH
24-Dec-2008
[3340]
I was the editor of the proposals and manager of the proposal process.
Maxim
24-Dec-2008
[3341]
I remember posting on the blogs a long time ago... its nice to see 
it was all compiled.... thanks brian !
[unknown: 5]
24-Dec-2008
[3342]
Yeah currently I would just set another value called 'flag in the 
parens and then check it after the parse was complete.  If it was 
true then I know a word wasn't found.
BrianH
24-Dec-2008
[3343]
In theory, the best proposals (I have a list in my head) will be 
able to be compiled to R2 parse rules. Tested theory :)
Maxim
24-Dec-2008
[3344x2]
the whole of the enhancements will make PARSE SOOOOOOO much more 
conscice and fun to use for advanced stuff.     :-)
I now have a real reason to want R3.
[unknown: 5]
24-Dec-2008
[3346]
I don't  know if  'Check functionality really needs to be BUILT as 
much as just communicated.
BrianH
24-Dec-2008
[3347]
Did you see my advanced example at the bottom? :)
[unknown: 5]
24-Dec-2008
[3348]
It shows the power of parse.
Maxim
24-Dec-2008
[3349]
not yet... reading it as I chat, cook and do some income tax stuff... 
I' m a bit like reichart... I've got an exec kernel in my brain  
 ;-)
[unknown: 5]
24-Dec-2008
[3350]
In fact that method I was showing is how TRETBASE will be parsing 
search criteria to ensure only acceptable words are used in the block 
that will be reduced.