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

World: r3wp

[Parse] Discussion of PARSE dialect

Anton
1-Mar-2006
[840]
Yes, I'm not having much luck here.
Rebolek
1-Mar-2006
[841]
Probably it's something like Oldes' comma problem. :/
Gabriele
1-Mar-2006
[842]
>> lt: to lit-word! first [ < ]
== '<
>> parse [1 < 2] [number! lt number!]
== true
Rebolek
1-Mar-2006
[843x3]
great, thanks!
actually not great, but working :)
Unfortunately, there's probably no similar trick that can be used 
with comma, poor Oldes
Volker
1-Mar-2006
[846]
replace/all str "," comma " ; :))
Oldes
1-Mar-2006
[847]
you cannot use this in a dialect!
Volker
1-Mar-2006
[848]
before i load the string! But not too reliable, if you have "," in 
strings.
Oldes
1-Mar-2006
[849]
and I'm not such a poor:-) I am using double  parenthesis in my dialect 
instead of using commas (it's ugly, but it's working)
Volker
1-Mar-2006
[850]
how does some sample code look?
Oldes
1-Mar-2006
[851x2]
I still think it's a shame, that we cannot load strings with commas, 
so we cannot forexample parse javascript or actionscript
my code looks like doSomeFunction(("a" add b) 1)
Volker
1-Mar-2006
[853]
i think that is hard to do perfectly. for example "\"", how to parse 
that?
Oldes
1-Mar-2006
[854]
in actionscript it's doSomeFunction("a" add b, 1)
Volker
1-Mar-2006
[855]
doSomeFunction("a" add b # 1)
doSomeFunction("a" add b . 1)
?
Oldes
1-Mar-2006
[856x2]
I know it woud be possible to improve my dialect, but I'm not going 
to do it in near future, I'm already used to write it this way:)
I think it's quite logical to close it in parenthesis than using 
chars like #
Volker
1-Mar-2006
[858]
But chars like # are easier to search/replace. But i dont defend 
my solution, yours looks ok.
Do you write your dialect-code in rebol-blocks or in a string?
Oldes
1-Mar-2006
[859x4]
And for the Rebolek: I use in RSWF this:
slash: to-lit-word first [/]
	dslash: to-lit-word "//"
	rShift: to-lit-word ">>"
	UrShift: to-lit-word ">>>"
	_bigger: to-lit-word ">"
	_less: to-lit-word "<"
	_noteql: to-lit-word "<>"
	_lesseql: to-lit-word "<="
	_biggeql: to-lit-word ">="
and then:
'* (term-op: [ins-act #{0C}])
				| slash  (term-op: [ins-act #{0D}])	;Divide
				| dslash (term-op: [ins-act #{3F}])	;Modulo
				| rShift (term-op: [ins-act #{64}])	;RShift
				| UrShift (term-op: [ins-act #{65}]);UnsignedRShift
				| lShift (term-op: [ins-act #{63}])	;lShift
				| '| (term-op: [ins-act #{61}])	;bitwise OR
				| ['|| | 'or] (term-op: [ins-act #{11}]);OR
				| ['& | 'band] (term-op: [ins-act #{60}])	;bitwise AND
				| 'and (term-op: [ins-act #{10}])	;AND
Rebolek
1-Mar-2006
[863]
Thanks Oldes, that should help me
Oldes
1-Mar-2006
[864x2]
Volker: blocks
it's much more easier as you can use Rebol's datatypes
Volker
1-Mar-2006
[866]
i thought about something like "js-load string" which would do the 
comma-conversion. But if your dialect works, no need for extra work.
Rebolek
1-Mar-2006
[867]
maybe fixing REBOL should be better? If "." can work without problem, 
why not "," ?
Volker
1-Mar-2006
[868]
interesting question why it is left out. but you would have other 
problems too, although not that often. like "\"". in rebol that is 
"\" " . in javascript "^""
Rebolek
1-Mar-2006
[869]
Volker this is some special case, you can replace that before parsing 
string, but you cannot replace all commas in action script, some 
of them may be parts of string
Rondon
2-Mar-2006
[870x2]
Does anybody have an script to parse BNFs?
BHF's specification..
Gregg
3-Mar-2006
[872]
I think Bretty Handley did. Check codeconscious.
Rebolek
5-Mar-2006
[873]
I think this should print 5 and return 'true. But it does not.

>> parse [1 2 3 4 5][any number! set val number! (print val)]
== false

Help please? :)
Anton
5-Mar-2006
[874x2]
>> parse [1 2 3 4 5][any [set val number!] (if value? 'val [print 
val])]
5
== true
What you did was consume the five numbers, then try to set val to 
a sixth one.
Rebolek
5-Mar-2006
[876]
What I want is work with first four numbers and not with the last 
one
Anton
5-Mar-2006
[877]
Is it always 5 numbers ?
Rebolek
5-Mar-2006
[878]
No :(
Anton
5-Mar-2006
[879]
>> parse [1 2 3 4 5][4 [set val number! (print val)] number!]
1
2
3
4
== true
Rebolek
5-Mar-2006
[880]
Actually, the real elements may be very different. I just simplified 
the example.
Anton
5-Mar-2006
[881]
Ok, so you don't know how many numbers you have until you fail to 
find another one.
Rebolek
5-Mar-2006
[882]
I want to process all elements excluding the last one.
Anton
5-Mar-2006
[883]
And do you want to avoid putting them into a block first ?
Rebolek
5-Mar-2006
[884]
They are in block already
Anton
5-Mar-2006
[885x2]
Actually, you can do it like this:
>> parse [1 2 3 4 5][any [set val number! pos: number! (print val) 
:pos] number!]
1
2
3
4
== true
Rebolek
5-Mar-2006
[887]
Interesting, that should probably work, thanks!
Anton
5-Mar-2006
[888x2]
Welcome.
Actually, the last   number!   can probably become   opt number!