There are several different literal token types referred to in this documentation.
Names in Pyret match the following regular expression:
The convention in Pyret is that kebab-case-names are used for names of values and fields, and TitleCaseNames are used for annotations.
a a1 a-1 abc ABC a----------b a-_-_-_-__--b a--_ _a __
The following are not valid names:
_- -_ a- -a -a- -abc a1- a-1- a_1- α 1abc $abc
Strings in Pyret come in several forms. First, they can be enclosed in double quotes:
"a string" "a string\" with escapes" "'single quotes' are allowed unescaped or \' escaped"
They can also be enclosed in single quotes:
'a string' 'a string\' with escapes' '"double quotes" are allowed unescaped or \" escaped'
String literals with single or double quotes must terminate by the end of the line:
"multi-line strings not allowed with double quotes"
Finally, multi-line string literals can be created by starting and ending them with three backticks (“‘). For example:
``` This string spans multiple lines ```
Multi-line string literals strip all whitespace before the first non-whitespace character and after the last non-whitespace character. All whitespace at the beginning of intermediate lines is preserved.
Pyret has several types of number literals. The most traditional allows for decimal numbers, negation, and an exponent:
That is, an optional sign, then some number of digits, optionally followed by a decimal point and more digits, optionally followed by an exponent. These are valid number literals:
0.1 1 1e100 1.1e100 +1.1e100 -1.1e-100 1.1230e-0 10 19 19.0
Note that a number literal cannot start with a decimal point; some leading digits are required. These are not number literals:
.1 1.1.1 1.+1 0.1+100
This first kind of number literal represents an exact number, or Exactnum. Number literals can also be prefixed with a tilde, to indicate that the number is an approximation, or a Roughnum. So these are all valid rough number literals:
~0.1 ~1 ~1e100 ~1.1e100 ~+1.1e100 ~-1.1e-100 ~1.1230e-0 ~10 ~19 ~19.0
And these are not valid:
~.1 ~1.1.1 ~1.+1 ~0.1+100
Finally, numbers can be written as exact ratios of whole numbers:
These numbers are interpreted as Exactnums. These are valid rational literals:
1/2 -1/2 +1/4 1234/9 0/1234
It is a syntax error to use zero as the denominator in a fraction literal. These are not valid rational literals:
1+1/2 -1/0 1.1/9 1/-3
Boolean literals are the lowercase words true and false.