UString as Text
The purpose of this page is to begin thinking about how ustrings could be integrated with text units.
A ustring is just an inline expression form for text structure.
[save/ [u].html]
<html><head><title>[v title]</title></head><body>
[foreach/ content.?]
[if/]
:h1 <h1>[v]</h1>
:p <p>[v]</p>
:html [v]
[/if]
[/foreach]
</body></html>
[/save]
The above is equivalent to:
~save {
~filename {
~u
~literal .html
}
~contents {
~line {
~literal <html><head><title>
~v {
~selector title
}
~literal </title></head><body>
}
~foreach {
~selector content.?
~contents {
~line {
~if {
~case {
~condition {
~type type
~value h1
~content {
~literal <h1>
~v
~literal </h1>
}
}
}
[...]
}
}
}
}
}
}
One sees UTL is a sort of ”symbolic assembly language“ which expressions get easily verbose.
This pressuposes a ustring definition such as:
^ustring {
^u :string
^v {
^selector :selector
^default :ustring
}
^literal :string
^line :ustring
^if {
^case {
^condition {
^type :unit-type
^value :string
^content :ustring
}
}
}
^foreach {
^selector :selector
^contents :ustring
}
}
The selector type should actually not be declared as :string but as parsed selector, too:
^selector {
^level {
^modifier
^type :unit-type
^value :string
}
}
The unit-type used in selectors and if-conditions should by strong-typed, too:
^unit-type
^is-unit :unit-type
^is-type :unit-type
^is-role :unit-type
How can a module add a new tag say [wp] for Wikipeda links?
^paragraph :ustring {
^wp :ustring-tag {
^article :string
}
}
When parsing this line:
~paragraph I was born in [wp Barcelona]
the UTL parser recognizes the declared tag [wp] and feeds this text structure:
~paragraph {
~literal "I was born in "
~wp {
~article Barcelona
}
}
Although some tags can be automatically parsed by using default binary children, in the general case they must provide a parser in order to fill out its contents. For example: if-tag.
^if :ustring-tag {
~tag-parser parseIf
^case {
^condition {
^type :unit-type
^value :string
^content :ustring
}
}
}
When parsing this:
[if/]
:h1 <h1>[v]</h1>
:p <p>[v]</p>
:html [v]
[/if]
the UTL parser detects an if-tag and calls parseIf giving it the tag contents consisting of 3 lines.
The function parseIf feeds the text structure accordingly.

