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

World: r3wp

[Dialects] Questions about how to create dialects

Geomol
11-Jan-2005
[16]
One way to solve the problem with required parameters is to use on/off 
flags. The rule for an anchor <a> will then be something like:


anchor: [#"a" (href: off) space some ["href=" (either href [print 
"HREF already found!"] [href: on]) set arg chars | "title=" .....]]
(if href = off [print "HREF required in anchor!"])


You can find this technique in the html32 dialect (I mentioned) for 
the src and alt parameters of the image tag <img>.
Chris
11-Jan-2005
[17]
Ah, I see.  Still, it doesn't seem most elegant.  Another option 
would be to generate the permutations dynamically, but again, not 
so elegant...
Robert
12-Jan-2005
[18x5]
Using keywords for parameters of course works but bloats the dialect, 
it's than mostly like HTML, XML only the opening/closing tags can 
be obmitted.
I like Vincent's approach to collect the things and than assign them 
in the order.
But I have an other problem with the non-keyword approach:


'keyword set name string! opt [set caption [string!]] opt [set size 
integer!] opt [set maxlength integer!] opt [set default string!]


In the above example the only order I can specify is: string! integer! 
integer! string! Right?

I can leave out some parts but I can't shuffel them. This isn't possible: 
string! string! integer! integer!


Because PARSE walks through the rule once from left to right. So 
by passing the second string! the integer! rules have been already 
"eaten".
The next question is: How do I provide only the second integer!? 
I would like to use NONE for skipped paramters. How can I handle 
this. I tried to add word! and than provide none but this will be 
parsed into a word! but NONE? returns FALSE...
Chris, multiplying out the permutations isn't a solution. To much 
combinations. The idea of Geomol is right. You need to keep track. 
The thing is that parse doesn't has a backtracking (or parallel checking 
of rules). If we would have this feature you could write something 
like: once [any [... | ... | ...]]
Pekr
12-Jan-2005
[23x2]
long requested feature imo some of us regard as not needed ...
it would really make my life easier sometimes to be able to find 
first occurance of A or B or C ...I know it can be done by using 
proper grammar rules, but - not by me ... so we are letting parse 
to work in some cases only for gurus, which are good at hacking such 
solution. But I thought rebol should made simple things simple .... 
and I find mixture of  "to first occurance of any value" as usefull 
....
Robert
12-Jan-2005
[25]
This can be done with some [...] and nested rules. But as said, if 
you want to handle it only ONCE you need to keep track of it yourself.
Pekr
12-Jan-2005
[26x2]
I am not sure I am able to easily write nested rules, nor beginners, 
while something like to/thru [a | b |c ] would be really easy to 
use, wouldn't it?
Well, otoh Carl is open to changes to Core imo, as he wants to concentrate 
upon Language ... so - why not suggest him any enhancement?
Volker
12-Jan-2005
[28]
Look at %vt-index.r in the desktop-source. its only drawback is, 
the last value counts, instead of insisting on a 'once.
DideC
12-Jan-2005
[29x2]
Robert: to remove parameters order, you can act like this :

strings: copy [] integers: copy []

rule: ['keyword (clear strings clear integers) some [set p integer! 
(append integers p) | set p string! (append strings p)] (size: integers/1 
maxlength integers/2 caption: strings/1 default: strings/2)]
It's the principle used by VID but by a function, not with 'parse 
(see grow-facets func in SVV)


But it can't solve the datatype order : you can't passed Maxlength 
without Size !
But you can add another keyword to handle this case, like :

['maxlength set p integer! (maxlength: p)]


It's what VID does : tuple! can be color or font color (depends the 
style you use). To be sure it's font color, you have the 'font-color 
keyword.
Robert
12-Jan-2005
[31]
Dide, ok thanks. How can I specify the "empty" parameters? I would 
like to use NONE so that the variables can be tested with NONE?
Geomol
12-Jan-2005
[32]
Sometimes do'ing the result work:

>> a: 'none
== none
>> type? a
== word!
>> a: do a
== none
>> type? a
== none!
Volker
12-Jan-2005
[33]
you parse a block, get 'none and want to handle it as none! ? Use 
it as word and [ if word = 'none [..] ] . Or use [ get word ]
Robert
12-Jan-2005
[34x2]
Dide, how to handle the "can't pass 'maxlength without 'size" problem 
best? I mean how to specify no-maxlength? Providing a 0 or  a -1? 
I would like to use 'none for all those values, but 'none can't be 
destinquished if it's a none-integer or none-string.
I could use STRING! and INTEGER! as empty values.
Andrew
12-Jan-2005
[36x3]
For my ML dialect (for easily creating HTML and XML), I didn't bother 
with error processing.
That's because it's designed for experts to use. And the experts 
aren't going to be making simple errors.
For other applications, I use different dialects, like eText for 
simple text -> HTML layout.
Gregg
13-Jan-2005
[39x3]
Something to consider, when you have cases like Chris's href examples 
above, is the separation of syntax and semantics. Also, for Robert's 
examples, remember that most languages have very strict rules and 
a lot of "markers" to make parsing easier (at the expense of making 
things harder to write). VID is a great example of a language that 
works hard to be flexible.
Look at your dialect from the top down too, as a user will. Write 
example code in it and think about how you expect it to behave.
And remember, LANGUAGE DESIGN IS HARD.
Maarten
13-Jan-2005
[42]
Nah, it took Carl merely twenty years to come up with REBOL
Geomol
13-Jan-2005
[43]
:-D
Robert
13-Jan-2005
[44]
My goal is to create the dialect in a way that it's easy to use for 
non-techies. Yes, it's hard but hey, otherwise it would be no challange.
Ladislav
13-Jan-2005
[45x2]
Robert: you don't need to have any knowledge of PARSE to design a 
dialect. The only thing you need is to know how the dialect should 
look and work.
e.g. I am not implementing all my dialects using PARSE
DideC
13-Jan-2005
[47x6]
Robert: Why not settings the words to none! just when you clear the 
block :
strings: copy [] integers: copy []

rule: ['keyword (clear strings clear integers   size: maxlength: 
caption: default: none  ) some [set p integer! (append integers p) 
| set p string! (append strings p)] (size: integers/1 maxlength integers/2 
caption: strings/1 default: strings/2)]
then, none! is default unless you specify Size and, maybe, Maxlength.
Ups, it's even not needed : if Integers is empty, then "size: empty/1 
--> none!"
So, mix the both : the 'maxlength and 'default keywords :
rule: [
	'keyword (clear strings clear integers)

 any [set p integer! (append integers p) | set p string! (append strings 
 p)]

 (size: integers/1 maxlength: integers/2 caption: strings/1 default: 
 strings/2)

 any ['maxlength set p integer! (maxlength: p) | 'default set p string! 
 (default: p)]
]

tests: [
	[]
	[keyword]
	[keyword 10 20 "Blue" "Orange"]
	[keyword 10 "Blue"]
	[keyword 10 20]
	[keyword "Blue" "Orange"]
	[keyword 10 "Blue" 20 "Orange"]
	[keyword "Blue" 10 20 "Orange"]
	[keyword "Blue" "Orange" 10 20]
	[keyword "Blue" maxlength 20]
	[keyword 10 default "Orange"]
	[keyword maxlength 20]
	[keyword default "Orange"]
	[keyword maxlength 20 default "Orange"]
	[keyword default "Orange" maxlength 20]
]

strings: copy [] integers: copy []
size: maxlength: caption: default: -1

foreach t tests [
	parse t rule
	print [mold t "==>" size maxlength caption default]
]
Robert
14-Jan-2005
[53x2]
Dide, yes I have found the side effect of empty/1 == none! as well.
About mixing: I'm thinking of something like this:

(keyword: none)
any [

 opt ['maxlength (keyword: 'maxlength) | 'default (keyword: 'default)]]
	any [set p integer! (repend integers [keyword p])
	...

I think you get the idea.
Graham
14-Jan-2005
[55]
I had this problem a couple of weeks ago when trying to write a function 
to repopulate a web page from the posted cgi object.
Robert
14-Jan-2005
[56]
As said, my goal is to reduce the number of keywords as much as possible 
and make it easy to use.
Graham
14-Jan-2005
[57]
Are you trying to parse html to see if it is valid or not?
Robert
14-Jan-2005
[58]
No, I'm doing a dialect to create HTML forms with CGI etc.
Sunanda
14-Jan-2005
[59]
I suspect a mixed positonal + keyword approach may be the best.
Positional for for common attrbutes.
Keyword for the more esoteric ones.
Maybe read up on CSS shorthand methods for inspiration.
Robert
15-Jan-2005
[60]
Yes, right that's what I'm going to do. Thanks for the CSS tipp, 
I take a look at.
Geomol
25-Jan-2005
[61x2]
I've defined a new format, which is a REBOL version of XML. I already 
have scripts, that can convert between this format and XML. So far, 
I've called the functions "xml2rebol" and "rebol2xml", but maybe 
"rebol" isn't a good name for the new format. I've thought about 
"rebxml" as a name. Any ideas or suggestions? This is a quick explanation 
of the foremat:

tag (optional attributes) string or block

If the string is empty, it's an empty element tag. In XML: <tag/>

If attributes are present, they are one or more pairs of a word and 
a string.
A block can hold strings and new tags.

This XML example:

<person alive="yes"><name>Mr. Smith</name><male/><address><street>Sunnylane</street><number>44</number></address><person>
will look like this in the new format:

[ person alive "yes" [ name "Mr. Smith" male "" address [ street 
"Sunnylane" number "44" ] ]

Other examples:
<tag></tag> = tag [ "" ]
<tag>content</tag> = tag "content"
or tag [ "content" ]
Both are valid.
Correction!
This XML example:

<person alive="yes"><name>Mr. Smith</name><male/><address><street>Sunnylane</street><number>44</number></address></person>
Terry
25-Jan-2005
[63x2]
I like this.. 
°Mr. Smith° (main °7°) has the following..
 
	°Class?° °Person°
	°Alive Dead Status° "Alive"
	°Address 1° "44"
	°Address 2° °Sunnylane°
Notice that °Sunnylane° and °Person° are themselves °7°s?  This means 
that more information is available regarding them.. ie:

°Sunnylane: last time paved?° 
or 
°Sunnylane: set last time paved -=24-Oct-2001=-°


Because °Mr. Smith° is a °Person°, we could make a query like.. °Mr. 
Smith: requires food to survive?°  and have the system respond "Yes."
Geomol
25-Jan-2005
[65]
:)