New dialect for building HTML and XML tags [Announce] ML update
[1/7] from: AJMartin::orcon::net::nz at: 24-Dec-2003 22:51
I've enhanced my ML dialect to eliminate the need for the 'check function:
>> French: true
== true
>> ML compose [input/type/checked checkbox (French)]
== {<input type="checkbox" checked="checked" />}
>> French: false
== false
>> ML compose [input/type/checked checkbox (French)]
== {<input type="checkbox" />}
>> French: none
== none
>> ML compose [input/type/checked checkbox (French)]
== {<input type="checkbox" />}
Note that a logic! false or none! attribute causes the corresponding Name to
vanish away, which makes it just right for optional attributes in HTML and
XML tags.
And I've enhanced my ML dialect to allow building complex tags, with out
needing to use path! values (but it still allows path! values)! Just use a
surrounding <" and ">" for the "expanded" tag:
>> ML [< a href http://www.rebol.com title "Rebol HQ" > [ "Rebol HQ Link"] ]
== {<a href="http://www.rebol.com" title="Rebol HQ">Rebol HQ Link</a>}
I've also chopped out NameSpace, which was implemented wrongly (it doesn't
do the right thing for XSL stylesheets that generate HTML). :( I've also
chopped out some redundant words and values. :)
Enjoy!
Andrew J Martin
Speaking in tongues and performing miracles.
ICQ: 26227169
http://www.rebol.it/Valley/
http://valley.orcon.net.nz/
http://Valley.150m.com/
-><-
; From my %Patterns.r script:
Fail^: [to end skip] ; A rule that always fails.
Succeed^: [] ; A rule that always succeeds.
LT^: compose [(to-lit-word "<")]
GT^: compose [(to-lit-word ">")]
Slash^: Compose [(to-lit-word "/")]
[
Rebol [
Name: 'ML
Title: "ML"
File: %"ML.r"
Author: "A J Martin"
Owner: "Aztecnology"
Rights: "Copyright © 2003 A J Martin, Aztecnology."
eMail: [Rebol--orcon--net--nz]
Web: http://www.rebol.it/Valley/
Tabs: 4
Purpose: {ML generates XML markup from Rebol words, paths, refinements,
tags and blocks.}
Requires: [Build-Tag Fail^ LT^ GT^ Slash^]
Provides: [ML]
Language: 'English
Date: 11/December/2003
Version: 2.0.0
]
ML: function [
{ML generates XML markup from Rebol words, paths, tags, refinements and
blocks.}
Dialect [block!] "ML Dialect"
] [Gate String Values_Rule Value Tag Values Name Attribute] [
Gate: []
String: copy ""
Values_Rule: [
; Caution! The 'none word below is replaced in the 'parse rule
below!
none [
set Value any-type! (
Tag: next next Tag
either Value [
if logic? Value [
Value: form first back Tag
]
insert/only Tag :Value
] [
remove back Tag
]
Value: none
)
(Tag: head Tag)
]
; Caution! The 'opt word below is replaced in the 'parse rule below!
opt [
set Value [
decimal! | file! | block! | string! | char!
| money! | time! | issue! | tuple! | date!
| email! | pair! | logic! | integer! | url!
]
]
]
parse Dialect [
any [
[
set Tag tag! (
Values_Rule/1: 0 ; Replace 'none word in 'Values_Rule
above.
Values_Rule/3: either any [ ; Replace 'opt word...
#"/" = last Tag ; empty tag.
#"?" = first Tag ; XML tag.
#"!" = first Tag ; DOCTYPE tag.
] [0] [1]
)
| [
LT^ set Tag [word! | url!]
(
Values: make block! 10
insert tail Values Tag
)
any [
[opt Slash^ GT^ (insert Gate Fail^) Fail^]
| Gate set Name [word! | url!] set Attribute [
decimal! | file! | string! | char! | none!
| money! | time! | issue! | tuple! | date!
| email! | logic! | integer! | url! | lit-word!
]
(
if Attribute [
if logic? Attribute [
Attribute: form Name
]
insert tail Values reduce [Name Attribute]
]
)
]
(
clear Gate
Tag: Values
Values_Rule/1: 0 ; Replace 'none word in
'Values_Rule above.
Values_Rule/3: 1 ; Replace 'opt word...
)
opt [Slash^ (Values_Rule/3: 0)]
GT^
]
| set Tag [path! | word!] (
Tag: to-block get 'Tag
; Replace 'none word in 'Values_Rule above.
Values_Rule/1: -1 + length? Tag
Values_Rule/3: 'opt ; Replace 'opt word...
)
] (Value: none) Values_Rule (
if not tag? Tag [
Tag: build-tag Tag
]
insert tail String reduce either none? :Value [
if all [
#"/" <> last Tag
#"?" <> first Tag
#"!" <> first Tag
] [
insert tail Tag " /"
]
Tag
] [
[
Tag
either block? :Value [ML Value] [:Value]
to-tag join #"/" first to-block Tag
]
]
Values_Rule/1: none
)
| set Tag refinement! (
; Converts: /br to: <br /> for a saving of three characters!
insert tail String head insert tail to-tag Tag " /"
)
| none! | logic! ; Ignore 'none and logic! values.
| unset! ; And ignore unset values (caused by 'print...)
| set Value any-type! (insert/only tail String :Value)
]
end
]
String
]
]
[2/7] from: bry:itnisk at: 11-Dec-2003 11:28
>And I've enhanced my ML dialect to allow building complex tags, with
out
>needing to use path! values (but it still allows path! values)! Just
use a
>surrounding <" and ">" for the "expanded" tag:
cool, I've been working with jabber recently, one thing I found with
it's xml is that it's streamed which means that while any sequence of
xml messages from jabber are well formed, a single message is not
necessarily well formed. For example to call jabber I send it:
<stream:stream to='apaches' xmlns='jabber:client'
xmlns:stream='http://etherx.jabber.org/streams'>
and it replies with
<?xml version="1.0"?>
<stream:stream from='apaches' xmlns='jabber:client'
xmlns:stream='http://etherx.jabber.org/streams'>
it is only when I shut down the communication with sending
</stream:stream>
that the whole thing returns a well formed xml document
example here:
http://jabbermanual.jabberstudio.org/test/protocol/xmlstreams.html
look at the first example; a simple session, for the clearest
presentation of this.
>I've also chopped out NameSpace, which was implemented wrongly (it
doesn't
>do the right thing for XSL stylesheets that generate HTML). :( I've
also
>chopped out some redundant words and values. :)
what was it doing that the xslt couldn't handle?
[3/7] from: maarten:vrijheid at: 11-Dec-2003 13:33
>it's xml is that it's streamed which means that while any sequence of
>xml messages from jabber are well formed, a single message is not
<<quoted lines omitted: 5>>
><stream:stream from='apaches' xmlns='jabber:client'
>xmlns:stream='http://etherx.jabber.org/streams'>
If you have a Jabber bot I am interested :)
--Maarten
[4/7] from: bry:itnisk at: 11-Dec-2003 15:44
No I don't have a jabber bot, I've been running jabberd and ejabberd
servers(ejabberd is erlang implementation of jabberd), to start up I've
been using Rebol to telnet to them, they reside on port 5222, just
typing in the raw xml in one textbox, sending, and reading the response
in another.
Basically I just had to have something to check against that my setup
was running the way it was supposed to.
[5/7] from: jason:cunliffe:verizon at: 11-Dec-2003 13:11
> If you have a Jabber bot I am interested :)
Nicolas Fournier has written "Maoww", a jabber client in Rebol/View
Very nice.
Top of the downloads page
http://www.rebolfrance.net/telechargement.html
http://www.rebolfrance.net/projets/concours/maoww.zip
- Jason
[6/7] from: AJMartin:orcon at: 24-Dec-2003 22:51
> > I've also chopped out NameSpace, which was implemented wrongly (it
doesn't do the right thing for XSL stylesheets that generate HTML). :(
> what was it doing that the xslt couldn't handle?
It was adding name space prefixes to tags that should not have name space
prefixes. :(
Latest version fixes a bug and removes more words.
Andrew J Martin
Speaking in tongues and performing miracles.
ICQ: 26227169
http://www.rebol.it/Valley/
http://valley.orcon.net.nz/
http://Valley.150m.com/
-><-
[
Rebol [
Name: 'ML
Title: "ML"
File: %"ML.r"
Author: "A J Martin"
Owner: "Aztecnology"
Rights: "Copyright © 2003 A J Martin, Aztecnology."
eMail: [Rebol--orcon--net--nz]
Web: http://www.rebol.it/Valley/
Tabs: 4
Purpose: {ML generates XML markup from Rebol words, paths, refinements,
tags and blocks.}
Requires: [Build-Tag Fail^ LT^ GT^ Slash^]
Provides: [ML]
Language: 'English
Date: 12/December/2003
Version: 2.1.0
]
ML: function [
{ML generates XML markup from Rebol words, paths, tags, refinements and
blocks.}
Dialect [block!] "ML Dialect"
] [Gate String Values_Rule Value Tag Values Name Attribute] [
Gate: []
String: copy ""
Values_Rule: [
; Caution! The 'none word below is replaced in the 'parse rule
below!
none [
set Value any-type! (
Tag: next next Tag
either :Value [
if logic? :Value [
Value: form first back Tag
]
insert/only Tag :Value
] [
remove back Tag
]
Value: none
)
]
; Caution! The 'opt word below is replaced in the 'parse rule below!
opt [
set Value [
decimal! | file! | block! | string! | char!
| money! | time! | issue! | tuple! | date!
| email! | pair! | logic! | integer! | url!
]
]
]
parse Dialect [
any [
[
set Tag tag! (
Values_Rule/1: 0 ; Replace 'none word in 'Values_Rule
above.
Values_Rule/3: either any [ ; Replace 'opt word...
#"/" = last Tag ; empty tag.
#"?" = first Tag ; XML tag.
#"!" = first Tag ; DOCTYPE tag.
] [0] [1]
)
| [
LT^ set Tag [word! | url!]
(
Values: make block! 10
insert tail Values Tag
)
any [
[opt Slash^ GT^ (insert Gate Fail^) Fail^]
| Gate set Name [word! | url!] set Attribute [
decimal! | file! | string! | char! | none!
| money! | time! | issue! | tuple! | date!
| email! | logic! | integer! | url! | lit-word!
]
(
if Attribute [
if logic? Attribute [
Attribute: form Name
]
insert tail Values reduce [Name Attribute]
]
)
]
(
clear Gate
Tag: Values
Values_Rule/1: 0 ; Replace 'none word in
'Values_Rule above.
Values_Rule/3: 1 ; Replace 'opt word...
)
opt [Slash^ (Values_Rule/3: 0)]
GT^
]
| set Tag [path! | word!] (
Tag: to-block get 'Tag
; Replace 'none word in 'Values_Rule above.
Values_Rule/1: -1 + length? Tag
Values_Rule/3: 'opt ; Replace 'opt word...
)
] (Value: none) Values_Rule (
if not tag? Tag [
Tag: build-tag head Tag
]
insert tail String reduce either none? :Value [
if all [
#"/" <> last Tag
#"?" <> first Tag
#"!" <> first Tag
] [
insert tail Tag " /"
]
Tag
] [
[
Tag
either block? :Value [ML Value] [:Value]
to-tag join #"/" first to-block Tag
]
]
Values_Rule/1: none
)
| set Tag refinement! (
; Converts: /br to: <br /> for a saving of three characters!
insert tail String head insert tail to-tag Tag " /"
)
| none! | logic! ; Ignore 'none and logic! values.
| unset! ; And ignore unset values (caused by 'print...)
| set Value any-type! (insert/only tail String :Value)
]
end
]
String
]
]
[7/7] from: bry:itnisk at: 12-Dec-2003 14:13
>It was adding name space prefixes to tags that should not have name
space
>prefixes. :(
Does this mean it was adding namespace prefixes to tags that were not in
the namespace that the prefix was bound to, or that it was coming with
output sort of like this:
<html:a xmlns:html="http://www.w3.org/xhtml"
xmlns="http://www.w3.org/xhtml" href="something">hi</html:a>
if it did that, although ugly it would still be permissible. I'm
supposing instead it was doing
<html:svg width="400" height="300">
....</html:svg>
which I agree, :(
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted