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

World: r3wp

[Parse] Discussion of PARSE dialect

Graham
16-Nov-2007
[2278x2]
I'll try Gregg's split function
Nice to have code snippets on line when the brain is too tired to 
create one's own
Brock
22-Nov-2007
[2280x3]
What's wrong with this?  I'm trying to retrieve the "area" query 
string parameter out of this web log record...

test: {10.200.55.63 - - [22/Oct/2007:10:32:57 -0500] "GET /irj/servlet/prt/portal/prtroot/com.cpc.km.Redirect?userid=KALEFBM&area=chm&Rurl=http://bjzprd
/sellserve/displaysalesupdate.aspx?id=3815" 302 182}
with the following parse statement...
parse test [
	thru "area="
	copy new-area
	[to " " | to "?" | to "&"]
	to end
	(if debug? [print new-area])
]
I expect the return to be just the characters   chm, however the 
remainder of the querystring text is also being transfered.  So the 
   to "&"     is not  being considered within the rule.
Chris
22-Nov-2007
[2283]
I don't think you can use copy in that way.
Brock
22-Nov-2007
[2284]
meaning I would nead to have 3   thru... copy... to...  rules?
Steeve
22-Nov-2007
[2285]
parse/all test [thru "&area=" copy val to "&"]
print val
Chris
22-Nov-2007
[2286x3]
Hmm, no - I'm wrong.  Try parse/all first though (for to " ")
Or, instead of parse, do -- select decode-cgi find/tail string "?" 
to-set-word 'area
string = test
Steeve
22-Nov-2007
[2289]
the problem comes from [to " " | to "?" | to "&"]
Brock
22-Nov-2007
[2290]
@ Steeve,  yes, but i'm not certain there will be a   ?  or   &  
or  space character, so I want to test for all three
BrianH
22-Nov-2007
[2291]
Use charset "?& ".
Steeve
22-Nov-2007
[2292]
use a charset instead.
valid: complement charset "^-^/ ?&"
parse/all  test [thru "&area" copy val some valid to end]
Chris
22-Nov-2007
[2293]
Yep, that'd be the surest...
Steeve
22-Nov-2007
[2294]
oups, to late
BrianH
22-Nov-2007
[2295x2]
Searching for tabs and newlines would not be necessary in this case, 
but yes.
Be concise Steeve :)
Chris
22-Nov-2007
[2297]
Wouldn't work for the Rurl value though...
Steeve
22-Nov-2007
[2298]
huhu
Brock
22-Nov-2007
[2299]
seems this works... parse/all test  [thru "area=" copy new-area some 
terminator to end (if debug? [print new-area])]
where   terminator: complement charset ["?" "&" " "].
In my earlier tests I didn't use the complement!!
BrianH
22-Nov-2007
[2300x2]
Go thru the GET, thru the first ?, then process every variable seperately, 
especially of you allow unencoded strings for some variables.
The value of the Rurl parameter is an unencoded string by the way.
Brock
22-Nov-2007
[2302]
yes, that was another issue I was going to need to tackle... I did 
some searching and couldn't find how to encode it easily.
Chris
22-Nov-2007
[2303]
If it's consistently the last value, that makes it easier...
BrianH
22-Nov-2007
[2304x3]
If you require that the argument value that is not url-encoded be 
the last, you can just do a to end or whatever the string terminator 
is.
In this case that would be "
Be sure to parse the whole get line - otherwise you might miss (or 
catch) maliciously crafted calls to your site.
Brock
22-Nov-2007
[2307x2]
@ Chris:  trying to accomodate variable placement within the string, 
but I can see that this can be a problem with the Rurl parameter.
thanks for the input guys.
btiffin
24-Jan-2008
[2309]
I'm pondering attempting a PARSE lecture here on Altme;  It'd be 
run twice, 9am EST, 9pm EST (or somesuch)  Topic would be dialecting. 
 I want to see if it would work, but I'm no where near a professor 
level rebol.  So, think of it as a kindergarten lecture, as a trial.


Plan;  Post this message - see if there is feedback.  Allow for some 
Q&A time for specific topics of interest.  A week or two later, run 
a hour (probably less) of monologue (interruptions allowed for stuff 
that is just plain wrong ... but other than that participants would 
be asked to hold off on questions).  Followed immediately with a 
Q&A, complaint, correction session.  Then a DocBase page created 
with a merged transcript of the two timezoned lectures, things learned 
and hopefully something along the lines of a simple file management 
(or some such) dialect source code file.  R2 related - for me the 
R3 DELECT still hasn't sunk in.  If it works, then perhaps it could 
become a semi-regular activity...there is going to be a lot to discuss 
come "link to the rebol.dll" time.
amacleod
24-Jan-2008
[2310]
sounds good
Pekr
24-Jan-2008
[2311]
If it is not supposed to be interactive, you could as well prepare 
it in a form of DocBase article, and then run the session ...
btiffin
24-Jan-2008
[2312]
Petr; true.  It is meant to be interactive, but after a monologue 
phase.  I worry a little bit as I have a sad tendency to be "almost 
right" with REBOL so I'd want the material vetted over before unleashing 
it on the innocent.
SteveT
25-Jan-2008
[2313]
As 'the'  newbie !! I'd 'Pay' for that! ;-)
james_nak
25-Jan-2008
[2314]
That would be great.
btiffin
25-Jan-2008
[2315]
Ok; I'll accept a class size of as least three as enough to make 
it worth continuing.  please be advised; The teacher can be a complete 
moron every second or third minute so the participants will be asked 
to take any knowledge gained as "maybe correct".  :)  I hope and 
expect that any semi-correct information will be fully corrected 
by the community before the information leaks too far afield.  Raising 
parse takes a village.
SteveT
26-Jan-2008
[2316]
Can you let me know what time in th UK the lecture may be ?? Ta
btiffin
26-Jan-2008
[2317]
Yeah; I'll work out two time slots;  still leaning toward 9am EST, 
-5 hours on GMT, and 9pm.  On a Saturday/Sunday.  
More to come.
btiffin
2-Feb-2008
[2318]
Poll re lecture;  How many people "get" pattern matching?  The whole 
success, fail and backtracking over alternates thing?  Does the class 
start with that level of description or right into parse?
Brock
2-Feb-2008
[2319]
I would be most interest in parse info.  My big interest is how parse 
can be used in conjunction with domain specific languages, but realize 
that might be scope creep.
btiffin
2-Feb-2008
[2320]
Nope on the creep;  A DSL will be the outcome of the lecture.  I'm 
leaning either toward a password management dialect or a (simple) 
file management command set.
Brock
3-Feb-2008
[2321]
great, looking forward to it
Geomol
3-Feb-2008
[2322]
A bit related, which might be a help in understanding parse in any 
way:

I want to know. how fast rebcode is at emulating CPUs, so I'm developing 
a 6502 assembler using parse and want to emulate the 6502 CPU using 
rebcode at a later time. When the assembler is more finished, I'll 
release it with a GPL license. It's basically a bunch of parse rules.
Gregg
3-Feb-2008
[2323x2]
James is getting into Forth, and I was just looking at some old notes 
I made on ForthR (play on "further"), where the machine primitives 
are actually a little REBOL VM/emulator, rather than ASM for a specific 
chip. Easier to get started, though not real Forth.
I've always thought we should have examples of how languages can 
be implemented in REBOL.
Graham
4-Feb-2008
[2325]
I have the figforth assembly code for the 6502  ... so you could 
run fig forth on your 6502 emulator ?
Gregg
4-Feb-2008
[2326]
Yeah, let me see where I put that... :-)
Geomol
4-Feb-2008
[2327]
I'm not really sure. First I do a general 6502 assembler and emulator, 
but I only have an emulator of the BBC homecomputer to test up against, 
so I probably have to deal with some Operating System stuff too. 
I operate with a 64k address space, and on the BBC writing to some 
certain addresses made something special for that platform happen. 
But let's see, what we can do.