Plain text only gets you so far. To format text, draw boxes, add buttons, or do almost anything else in ioL, you use tags. This chapter explains how tags are written. The next chapter puts them to work.
print('<span bold=true {Here is some bold text}>')
input()
Here is some bold text
Everything from the < to the matching > is one tag. The console doesn't display the tag itself. Instead, it carries out the tag's instructions: in this case, show some text in bold.
Each tag is self-contained. There's no separate "closing tag": the text the tag applies to goes inside the tag itself, between braces.
Here's a bigger tag, spread over several lines with a comment explaining each part:
< <! 1. the start of the tag !>
box <! 2. the tag type !>
color={black} <! 3. a field !>
{What time is it?} <! 4. the primary field !>
visible=true <! 5. another field !>
rotate=7,{deg} <! 6. a field with two values !>
> <! 7. the end of the tag !>
Normally you'd write it on one line:
<box color={black} {What time is it?} visible=true rotate=7,{deg}>
All the fields other than the primary field are called secondary fields. Each tag type has its own set of fields. The Language Reference lists the fields each tag supports.
As with ordinary text, the console doesn't care about spaces and line breaks inside a tag. Spaces around the = are fine too. The order of the fields doesn't matter either, except that the tag type must come first. These two tags do the same thing:
<span bold=true italic=true {Hello}>
<span
{Hello}
italic = true
bold = true
>
In Python, triple-quoted strings make it easy to print a tag laid out over several lines:
print('''
<box
border=2
backgroundColor={lightyellow}
color={black}
{What is your name?}
>
''')
input()
There's one exception to the rule that whitespace becomes a single space. If the whitespace straight after a tag
starts with a line break, it's ignored altogether, along with any indentation on the next line. That means
tags printed by separate print statements, or laid out one per line, sit right next to each other:
print('<span bold=true {Hello}>')
print('<span italic=true {world}>') # displays "Helloworld"
If you want a space between them, put it on the same line as the first tag, before the line break:
<span bold=true {Hello}> , or use </ >. Spaces within a line are never
lost: <span {Hello}> <span {world}> displays "Hello world".
When a field has more than one value, put a comma between each pair. Leave a comma out, and the next value is no longer part of that field. Instead it goes into the primary field:
<box rotate=7,{deg} {Hello}> <! rotated by 7 degrees, containing "Hello" !>
<box rotate=7 {deg} {Hello}> <! oops: rotated by 7, containing "degHello" !>
The second box still rotates, because degrees happen to be the default unit. But {deg} ended up in the box as text. When two blocks of text end up next to each other like this, they're joined into one.
What about one comma too many? Two commas with nothing between them leave an empty item in the list, and so does a comma at the very start of a list. An empty item is perfectly good ioL: it stands for null, a special value meaning "no value here", which you'll meet properly in the chapter on values.
The mul tag multiplies the numbers in its primary field. Look what a stray comma does to it:
<mul 2,3> <! two items: 2 and 3. Displays 6 !> <mul 2,,3> <! three items: 2, null and 3. Still displays 6 !> <mul ,2,3> <! three items: null, 2 and 3. Still displays 6 !>
There's nothing to multiply by in "no value", so mul simply leaves the null out. All the arithmetic tags do the same, so a stray comma doesn't upset a calculation.
The one place a comma can't go is at the end of a list. There, the console can't tell whether you meant to finish the list or forgot the next item, so it reports a syntax error:
ioL | invalid syntax | a list can't end with ','.
If you really do want a list that's just one empty item, write null.
The text inside braces can contain tags of its own. This is how you format part of a block of text:
print('<box {Hello, <span bold=true {World}>!}>')
Hello, World!
Tags can be nested as deeply as you need: a box containing a box containing a span, and so on.
In fact, everything your program prints is treated as one big block of text, as if it were inside a pair of invisible braces. That's why you could print plain text in the last chapter, and why a stray } is an error: there's no block for it to close.
Get a tag type wrong, and the console reports it in the terminal:
print('<Box {Hello}>')
ioL | invalid reference | Not defined in reference scope: Box.
A value the console can't make sense of becomes the special value invalid. If it ends up in something displayed on screen, it appears as an invalid marker, so you can see where the problem is.