[REBOL] Re: Dialects - Bane or Blessing? (was: Teaching Rebol)
From: al:bri:xtra at: 26-Sep-2002 21:23
Gregg wrote:
> What other dialects are out there?
There's my ML dialect. Here's a little sample from my Wiki script:
print ML compose/deep [
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
html [
head [
title (Title)
link/rel/type/href "stylesheet" "text/css" (%Wiki.css)
script/type/language/src "text/javascript" "JavaScript"
(%Wiki.js) ""
]
(Body)
]
]
Here's a sample of my Fixed dialect (it's used for chopping up fixed width
data files generated by a DOS BASIC program)
Fields: [
"Family Name" 20
"First Name" 25
"Preferred" 12
"Mail to Whom" 35
"Invoices?" logic!
"Reports?" logic!
"Address" [25 20 20]
"Telephone" 19 /with " -()"
"Cellphone" 7 /with " -()"
"Nationality" 3 issue!
"Language" 2 issue!
skip 4
"Year" 2 integer!
"Form" 4 issue!
skip 4
"Gender" 1 issue!
"Birth" 8 date!
"Enrollment" 5 issue!
skip
"First Started" 8 date!
"First Attended" 8 date!
skip 2
"Type" 1 issue!
"Status" 1 issue!
"Caregiver 1 Family Name" 20
"Caregiver 1 Title" 4
"Caregiver 1 First Name" 12
"Caregiver 1 Address" [25 20 20]
skip 20
"Caregiver 1 Cellphone" 6 /with " -()"
"Caregiver 1 Home Telephone" 14 /with " -()"
"Caregiver 1 Work Telephone" 14 /with " -()"
"Caregiver 1 Occupation" 3 issue!
"Caregiver 1 Relationship" 1 issue!
skip 4
"Caregiver 1 Invoices?" logic!
"Caregiver 1 Reports?" logic!
"Caregiver 1 Voting Rights?" logic!
"Caregiver 1 Emergency?" logic!
"Caregiver 1 Living With?" logic!
"Caregiver 1 Legal Guardian?" logic!
"Caregiver 1 Access Rights?" logic!
"Caregiver 1 User Flag 1?" logic!
"Caregiver 1 User Flag 2?" logic!
"Caregiver 1 User Flag 3?" logic!
Here's a very small sample of my eText dialect:
eText Sampler
*************
Author: "Andrew Martin" [Al--Bri--xtra--co--nz].
Date: 7/October/2001
Intent
======
eText is designed as a quick, easy, portable, powerful documentation
language. It's primarily suited for generating high content HTML and WML
pages.
There's loads more examples on my site; just substitute ".txt" for ".html"
on nearly any URL.
And the script for interpreting my CSS dialect (for creating style sheets)
CSS: function [
"CSS generates CSS markup from Rebol words, paths, tags, blocks and
other values."
Dialect [block!] "CSS dialect block."
] [CSS Number Declaration Property Value Value2 Selector Selector2
Selector3] [
CSS: make string! 2000
Number: [integer! | decimal!]
Declaration: [
some [
set Property set-word! (
repend CSS [
tab mold get 'Property
; In the above line "get 'Property" can be replaced
; with "Property" with new Rebol versions.
]
)
some [
[set Value Number %.] (
repend CSS [
#" " Value #"%"
]
)
| set Value file! (
repend CSS [
" url(" replace/all copy Value #" " " " ")"
]
)
| set Value url! (
repend CSS [
" url(" Value ")"
]
)
| [set Value Number set Value2 word!] (
repend CSS [
#" " Value Value2
]
)
| set Value [word! | issue!] (
repend CSS [
#" " mold Value
]
)
] (
append CSS ";^/"
)
]
]
parse Dialect [
any [
[
set Selector word! set Selector2 word! set Selector3 word! (
repend CSS [
mold Selector #" " mold Selector2 #" " mold
Selector3 " {^/"
]
)
| set Selector word! (
repend CSS [
mold Selector " {^/"
]
)
| set Selector block! (
foreach Item Selector [
repend CSS [Item ", "]
]
remove/part back back tail CSS 2
append CSS " {^/"
)
| set Selector path! (
foreach Item :Selector [
repend CSS [Item #" "]
]
remove back tail CSS
append CSS " {^/"
)
]
into Declaration (
append CSS rejoin [
tab "}" newline
]
)
]
end
]
CSS
]
And there's my Build-Tag dialect, which is incorporated into the latest
Rebol versions.
Build-Tag: function [
"Generates a tag from a composed block."
Values [block!] "Block of parens to evaluate and other data."
] [
Tag Value_Rule XML? Name Attribute Value
] [
Tag: make string! 7 * length? Values
Value_Rule: [
set Value issue! (Value: mold Value)
| set value file! (Value: replace/all copy Value #" " " ")
| set Value any-type!
]
XML?: false
parse compose Values [
[
set Name ['?xml (XML?: true) | word!] (append Tag Name)
any [
set Attribute [word! | url!] Value_Rule (
repend Tag [#" " Attribute {="} Value {"}]
)
| Value_Rule (repend Tag [#" " Value])
]
end (if XML? [append Tag #"?"])
]
| [set Name refinement! to end (Tag: mold Name)]
]
to tag! Tag
]
And here's some stuff I've been working on. My XForms dialect for generating
HTML forms in Rebol (it doesn't work very well, but it's an example of a
dialect):
X: Forms [
Logic "Truth?" /Truth
Logic "Falsey?" /Falsey
Field "Line" /Line 10
Secret "Password" /Password 10
Area "Paragraphs" /Paragraphs 40x4
SelectOne "Gender" /Gender [
#"F" "Female"
#"M" "Male"
]
SelectOne "Relationship" /Relationship [
#"F" "Father"
#"G" "Guardian"
#"M" "Mother"
]
SelectOne "Invoices?" /Invoices? [
#"N" "No"
#"Y" "Yes"
]
Date "Birth" /DoB
Output "Age" /Age
Integer "Number" /Number
Output "Total" /Total
Submit "Enter"
] make object! [
Truth: true
Falsey: false
Line: "string!"
Password: none
Paragraphs: trim {A long line of text,
that is several lines long.
It has several lines indeed!
And here's another!}
Gender: #"F"
Relationship: #"M"
Invoices?: #"Y"
DoB: 25/10/1960
Age: has [YMD] [
YMD: system/words/Age now DoB
rejoin [
YMD/Years " years, " YMD/Months " months, " YMD/Days " days."
]
]
Number: 123456
Total: $123.45
]
I'm sure there's more to come, and there's plenty more out there to be
discovered.
Andrew Martin
The dialects are out there! :)
ICQ: 26227169 http://valley.150m.com/