Skip to content

Lexical Structure ​

Implementation status: Implemented (syx-lexer, complete token set; regex literals Phase 50+; nested block comments; identifiers UAX #31 XID — ADR-229 / M2-S2-04)

SYX source files are UTF-8 text (without a BOM). Lexical analysis splits source into a Token stream for the parser.


Character Set ​

ElementRange
Source encodingUTF-8 (no BOM)
Line terminator\n (LF) / \r\n (CRLF, normalized)
Whitespace / \t / \v / \f

Any Unicode character may appear anywhere in source (comments, string literals, identifiers); string literals support the \u{…} escape.

Identifiers ​

identifier ::= letter (letter | digit | '_')*
letter     ::= [a-zA-Z_] | <unicode XID_Start>
RuleDescription
First characterLetter or _
SubsequentLetter, digit, _
Case sensitivityFoo ≠ foo
UnicodeImplemented (XID_Start / XID_Continue via unicode-xid; ADR-229)
NormalizationIdentifiers are not NFC-normalized; comparison is source-spelling equality
KeywordsCannot be used as ordinary identifiers
swift
count
_private
MyType
helloWorld
αβγ                           // Unicode XID (valid)

Diagnostics: L006 illegal character; L001 identifier naming lint (lint rule).

Keywords ​

Reserved words cannot be used as ordinary identifiers. The complete list is grouped as follows:

Declarations ​

KeywordMeaning
classReference type
structValue type
enumEnumeration
protocolProtocol
extensionExtension
actorConcurrency-isolated type
funcFunction
initInitializer
deinitDeinitializer
varMutable binding
letImmutable binding
importImport a module
typealiasType alias
associatedtypeAssociated type
globalGlobal actor (modifies actor)
datadata class modifier (data class)
finalForbids subclassing (final class / final func)

Access Control ​

KeywordMeaning
publicAcross modules
internalWithin the module (default)
privateFile / scope
fileprivateWithin the file

Control Flow ​

KeywordMeaning
ifCondition
elseOtherwise
guardEarly-exit guard
switchMulti-way branch
caseBranch
defaultDefault
forLoop
infor-in container
whileConditional loop
repeatrepeat while
breakBreak out
continueContinue
returnReturn
fallthroughRejected (not supported by SYX)

Concurrency ​

KeywordMeaning
asyncAsynchronous function
awaitAsynchronous wait
TaskTask
actorIsolated object
globalGlobal actor modifier
isolatedIsolation (partial)
sendingPass parameters across isolation (Phase 26)
distributeddistributed actor (partial)

Types ​

KeywordMeaning
SelfImplementing type
TypeMetatype
someOpaque result
anyExistential type

Error Handling ​

KeywordMeaning
tryError propagation
catchCatch
throwThrow
throwsError signature (throws T typed throws Partially implemented)

Literals ​

KeywordMeaning
trueBoolean true
falseBoolean false
nilNull value

Generics and Metaprogramming ​

KeywordMeaning
whereGeneric constraint
requiresEffect annotation
macroUser macro declaration
compileTimeConstant evaluation
Pure / IOEffect labels

Contextual Keywords ​

KeywordMeaning
staticStatic (type method / field)
finalForbids override
overrideOverride
lazyLazy property (class only)
mutatingMutating method
convenienceConvenience init (Not implemented)
requiredRequired init (Not implemented)
prefix / infix / postfixCustom operators
associativityAssociativity
precedencePrecedence

The full list lives in crates/syx-lexer/src/token.rs.

Literals ​

Integer Literals ​

int-literal ::= digit+ (suffix)?
             | '0x' hex-digit+ (suffix)?
             | '0b' binary-digit+ (suffix)?
             | '0o' octal-digit+ (suffix)?

suffix ::= 'i8' | 'i16' | 'i32' | 'i64' | 'i128' | 'isize'    -- signed
        | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'usize'    -- unsigned
FormExampleInferred type
Decimal42Int
Hexadecimal0xFFInt
Binary0b1010Int
Octal0o17Int
Suffix100i8 / 0xFFu8 / 42i128Corresponding fixed width
Underscore1_000_000i64_ ignored at compile time

Unsuffixed integers default to platform Int (64-bit host → Int64; 32-bit → Int32).

Floating-Point Literals ​

float-literal ::= digit+ '.' digit+ (exponent)? (suffix)?
               | digit+ exponent (suffix)?

exponent ::= ('e' | 'E') ('+' | '-')? digit+
suffix    ::= 'f32' | 'f64'
FormExampleInferred type
Decimal3.14Double
Suffix3.14f32 / 2.0f64Float32 / Float64
Scientific notation2.5e10Double
Underscore1_000.5Same as above

Unsuffixed floats default to Double.

Booleans and Nil ​

LiteralType
trueBool
falseBool
nilContextually inferred (T? / Optional<T>)

String Literals ​

string-literal ::= '"' string-char* '"'
string-char    ::= <any except '"', '\', newline> | escape
escape         ::= '\' ('n' | 'r' | 't' | '\\' | '\"' | '\'' | '0' | 'x' hex-digit hex-digit | 'u' '{' unicode-codepoint '}')
               | '$' '(' expr ')'        -- interpolation
ElementMeaning
"..."Delimited by double quotes
\n \r \tCommon control characters
\\ \" \' \$Literal characters
\0NUL (warning: may truncate the string)
\x41ASCII byte (0x00–0xFF)
\u{1F600}Unicode code point (U+0000–U+10FFFF)
\(expr)Interpolation (arbitrary expression)
swift
"Hello, World"
"Hello, \(name)!"
"line one\nline two"
"emoji: \u{1F600}"
"ascii: \x41"

Raw newlines forbidden: no bare newline inside a string; an unterminated string reports L001. Storage: UTF-8 byte array (Rust String back end). Grapheme clusters: .length / substring / for-in operate on Unicode grapheme clusters (since Phase 84, indexed with unicode-segmentation).

Regex Literals ​

regex-literal ::= '/' regex-body '/' regex-flag?
regex-flag    ::= [a-zA-Z]+
FormExampleStatus
/pattern//\d+/Implemented
/pattern/i/hello/iPartially supported (flag accepted by parser)
/pattern/m/foo/mNot implemented

Disambiguated by / and context (not the start of a comment); the typical let p = /\d+/ is unambiguous.

Dictionary Literals ​

dict-literal ::= '[' dict-entry (',' dict-entry)* ']' | '{' dict-entry (',' dict-entry)* '}'
dict-entry   ::= expr ':' expr
FormSyntaxType
Dictionary["a": 1, "b": 2][K: V] static
Object{ "name": "SYX" }Dynamic Object

When the parser sees [key: value, …] (first element followed by :), it is a Dictionary; [elem, …] (first element followed by , or ]) is an Array.

Comments ​

FormUse
// textSingle line (to end of line or whole line)
/* text */Block (nesting supported)
/// textDocumentation comment (extracted by syx doc)
swift
// Single-line comment

/* Block comment
   /* may nest */
   any line
*/

/// Documentation comment
/// Multiple lines: each starting with `///`
func add(a: Int, b: Int) -> Int { return a + b }

Operators ​

Arithmetic and Assignment ​

OperatorMeaningPrecedence
+ - * / %Arithmetic100 / 90
=Assignment10
+= -= *= /= %=Compound assignment10
<< >>Bit shift80
& | ^Bitwise50 / 30 / 40

Comparison and Logic ​

OperatorMeaningPrecedence
== !=Equality60
=== !==Identity60
< <= > >=Ordered comparison70
&&Logical AND20
||Logical OR10
!Logical NOT (unary)—
??Nil coalescing5
?try chain / Optional / ?.—
! (postfix)Force unwrap—

Others ​

OperatorMeaning
->Function return type
=>Closure fat arrow (partially supported)
..<Half-open range
...Closed range (partially supported)
&Borrow &T / &mut T
@Attribute @attached / @Component
#Macro #assert
.Member access
?:Ternary (deliberately not provided; use an if expression; ≠ a pending gap)

Separators ​

separator ::= '(' | ')' | '{' | '}' | '[' | ']' | ',' | ':' | ';' | '.'
SymbolUse
( )Tuple / function parameters / condition
{ }Block / dictionary Object / closure
[ ]Array / subscript / Dictionary type
,List separator
:Named parameter / type annotation / dictionary key-value
;Empty (optional; never required by SYX)
.Member access / decimal point

Whitespace ​

whitespace ::= ' ' | '\t' | '\n' | '\r' | <unicode Zs>
  • Mostly skipped at the lexical layer (except inside string literals)
  • Comments are treated as whitespace
  • Indentation is not enforced (no Python-style mandatory indentation)

Diagnostics: L001–L012 (lexical / lint)

Usage examples → Language Guide: The Basics · Strings

See also → Types · Expressions · Grammar Summary

SYX · Apache-2.0