Lexical Elements
A HorseIR program is written in the ASCII character set, with the exception of string data (i.e. characters, strings, and symbols) which may contain Unicode characters. Whitespace outside of string literals is ignored.
letter = 'a' ... 'z' | 'A' ... 'Z' ;
digit = '0' ... '9' ;
nzdigit = '1' ... '9' ;
digits = digit { digit } ;
ascii_character = /* All valid ASCII */ ;
escape_sequence = "\a" | "\b" | "\f" | "\n" | "\r" | "\t" | "\v" ;
Comments
There are 2 styles of comments for programmer documentation, both of which are ignored.
1. Line comments start with //
and ignore all text until the end of the line (or EOF)
2. Block comments start with /*
, end with */
and ignore all text in-between. Block comments do not nest and must be terminated.
// Line comment
/* Block comments
* may be multiline
*/
Identifiers
Identifiers define program elements (e.g. variables, modules, and functions) and consist of letters, digits and the underscore. The first character must not be a digit.
Identifier = ( letter | '_' ) { letter | digit | '_' } ;
The sink identifier (_
) may be used as /dev/null
of any type. It does not introduce a binding on declaration.
Keywords
Keywords are special character sequences which may not be used as identifiers (with exceptions, see below). Keywords define syntactic elements as well as types.
module repeat i32 month ktable
import var i64 minute
global return f32 second
def break f64 time
kernel continue complex func
check_cast bool str list
if char sym dict
else i8 dt enum
while i16 date table
Warning
Type keywords may be used as identifiers if they are part of a function literal (e.g. @list
).
Operators
There are no explicit operators for data manipulation. Instead, each operation is defined as a function, with built-in functions providing functionality commonly found in other languages.
Punctuation
Punctuation symbols give structure to programs and are part of the language syntax.
( ) = @
[ ] : .
{ } , ?
< > ; *
Values
Each basic type has an associated literal value given below.
Values = ValueList ':' Type
ValueList = Value | '(' Value { ',' Value } ')'
Value = IntValue | FloatValue | BoolValue | ComplexValue |
CharValue | StringValue | SymbolValue | CalendarValue ;
Sign = '+' | '-'
Integer = '0' | nzdigit { digit } ;
Float = Integer '.' [ digits ] | '.' digits ;
IntValue = [ Sign ] Integer ;
FloatValue = [ Sign ] Float ;
BoolValue = '0' | '1' ;
CharValue = "'" ascii_character "'" ;
StringValue = '"' { ascii_character } '"' ;
SymbolValue = '`' ( Identifier | StringValue ) ;
ComplexValue = FloatValue [ Sign Float ] 'i' ;
CalendarValue = DateTimeValue | MonthValue | DateValue |
MinuteValue | SecondValue | TimeValue ;
// Must correspond to valid dates within range, see the type declarations
MonthValue = Integer '-' Integer ;
DateValue = Integer '-' Integer '-' Integer ;
MinuteValue = Integer ':' Integer ;
SecondValue = Integer ':' Integer ':' Integer ;
TimeValue = Integer ':' Integer ':' Integer '.' Integer ;
DateTimeValue = DateValue 'T' TimeValue ;