Names
Words are separated by whitespace, and can contain most non-whitespace characters, including UTF-8 characters. In particular, they can contain hyphens ('-'); use of hyphens is encouraged so separate words in a name (as opposed to the use of underscores or camelCase). However, a name may not start with a hyphen. Similarly, a name may contain digits but may not start with one. A name may contain periods ('.'); beginning a name with a period is a way of indicating that the name is normally to be hidden from human eyes (as in the Unix filesystem).
The following characters are not allowed in names:
# " ' ` ( ) [ ] { } ; ~ = + * / % ^ < > & | ,
Lines and Blocks
Like Python, Trylon code is organized by lines and indented blocks. An indented block is "owned" by the line above it; in a way, it can be thought of as being a part of that line.
If a line is too long to fit on the screen, it can be continued with "--" at the end of the line. Then the following line (minus its indentation, which is ignored) will be considered part of that line.
if some-value == "this" || some-value == "that" || --
some-value == "the-other" || --
some-value == "yet-something-else"
do-something
The meaning of a line will depend on the current syntax, but might be changed by the first word on the line:
foo = bar + baz
if x < y
for item in collection
The syntax of a block is usually determined by its owning line.
The Two Syntaxes
Trylon has two block-level syntaxes. One is the "class" syntax, defining methods and other elements of a class:
superclass SuperClass
fields name collection
help-text = "Help text goes here."
num-items
return collection num-items
for-each: block
class SubProto
Lines in the "class" syntax are function declarations (with their associated code blocks), shared-field declarations (using "="), or special forms like "fields" or "class".
The other is the "method" syntax, for code within a method:
frobnify: index
adjusted-index = index
if adjusted-index > max-index
adjusted-index = max-index
print-line: "Frobnification complete."
Lines within the "method" syntax are either expressions, assignments (technically, assignments are also expressions, and if the name being assigned to doesn't exist in an outer scope, a local is auto-declared in the current block), and special forms like "if", "while", "for", etc.
(Technically, there's a third syntax, for the cases in a "switch" statement.)
Classes in the Filesystem
Most classes will have a file in the filesystem with the source code to define it. Since classes may also act as namespaces for other classes, a class may also be specified by a directory, with files (or directories) for its sub-classes and (optionally) a file called "main" with source code for defining methods, fields, etc.
A typical project will live in a directory, with its sources in a subdirectory called "sources":
my-project/
Notes
to-do
build-settings
sources/
main
Screen
Window
XWindows/
Carbon/
Note that this could have all been defined within one file ("sources/main"), if that were more convenient:
trylon main
class Screen
class Window
class XWindows
class Screen
class Window
class Carbon
class Screen
class Window