Lexical Structure
Neon source code is encoded in UTF-8. All keywords and identifiers are case sensitive.
Comments
The comment lead-in character sequence is --
.
A single line comment is a --
followed by arbitrary text to the end of the line.
A block comment is introduced with /*
and ends with */
.
Block comments may span multiple lines.
Block comments may not nest.
Example:
-- The following line prints some text.
print("Hello, World.")
/* This comment spans multiple
lines of text until the comment
closing characters. */
Keywords
All words that consist of only uppercase letters are reserved for keywords. The following keywords are defined by the language.
Keyword | Description |
---|---|
|
used in |
|
logical conjunction |
|
names a tested expression in |
|
assert that an expression is true, used for diagnostics |
|
generic array type |
|
used in |
|
multiple value matching from a range |
|
constant declaration |
|
exception and forward function declaration |
|
default value for function parameter |
|
decrement a |
|
generic dictionary type |
|
used in |
|
alternative condition in |
|
alternative and test in |
|
include an external file directly into the compiled code |
|
enumeration type declaration |
|
end of most kinds of blocks of code |
|
exception declaration |
|
early exit from loops |
|
export identifier from module |
|
boolean constant |
|
indicates first value in array subscript |
|
loop with a sequential control variable |
|
loop over an array of values |
|
definition of subprogram |
|
literal |
|
conditional test and branch |
|
function parameter passing mode; aggregate membership test |
|
increment a |
|
used in |
|
function parameter passing mode |
|
access code in another module |
|
used in a |
|
indicates last value in array subscript |
|
assignment to read-only value |
|
generic loop |
|
used in |
|
arithmetic modulus |
|
declares a predefined function in the standard library |
|
early skip to next loop iteration |
|
dynamic memory allocation |
|
pointer value constant |
|
logical negation |
|
used in |
|
logical disjunction |
|
function parameter passing mode |
|
alternative condition in a |
|
pointer type declaration |
|
private record field |
|
initiate exception search |
|
named aggregate type declaration |
|
bottom-tested loop |
|
early exit and value return from function |
|
used in |
|
used in |
|
used in |
|
boolean constant |
|
start of exception-checked block |
|
define named type |
|
used at end of |
|
variable declaration |
|
used in |
|
used in |
|
top-tested loop |
|
parameter specification for named parameters |
Identifiers
An identifier is a letter followed by any number of letters, digits, or underscore. Identifiers which consist of all uppercase letters are reserved for Keywords.
Numbers
Literal numbers are in base 10 by default.
Numbers may be specified in a variety of bases (these support integers only):
-
Binary preceded by
0b
-
Octal preceded by
0o
-
Hexadecimal preceded by
0x
For base 10 numbers, they may contain a fractional portion following a decimal point .
.
Additionally, they may have an exponent following e
or E
.
Strings
Strings are sequences of Unicode characters surrounded by double quotes. The only special character within a string is the backslash, used for character escapes. The allowed character escapes are:
Escape |
Replacement |
Description |
|
" |
double quote |
|
\\ |
backslash |
|
chr(8) |
backspace |
|
chr(11) |
form feed |
|
chr(10) |
newline |
|
chr(13) |
carriage return |
|
chr(9) |
tab |
|
chr(XXXX) |
Unicode character XXXX (where XXXX is a 4-digit hex number) |
|
chr(XXXXXXXX) |
Unicode character XXXXXXXX (where XXXXXXXX is a 8-digit hex number) |
|
character |
Unicode character named NAME from the Unicode standard |
|
expression |
Example:
VAR s: String
s := "Hello, World"
Literal strings may need to contain backslashes (such as when used for regular expressions).
Instead of using normal double-quoted strings, there are two varieties of "raw strings".
The first can contain any character except "
:
CONSTANT s: String := @"This string contains backslash (\) characters"
The second type of string uses arbitrary delimiters so that any literal string can be included in source. The simplest form is:
CONSTANT s: String := @@"This string contains backslashes (\) and "quotes"."@@
If there is a need to include the sequence "@@
within the string, an arbitrary identifier may appear between the @
at the start and end of the stiring.
For example:
CONSTANT s: String := @raw@"A raw string example is @@"like this"@@."@raw@