///|
/// A 0-based UTF-8 byte offset paired with 1-based line and column coordinates.
#derive(Eq, Debug)
pub(all) struct Position {
  offset : Int32
  line : Int32
  column : Int32
}

///|
/// Half-open source span `[start, end)`.
#derive(Eq, Debug)
pub(all) struct Span {
  start : Position
  end : Position
}

///|
/// Token kinds supported by the CUE lexer.
#derive(Eq, Debug)
pub(all) enum TokenKind {
  // Identifiers & CUE-specific names
  Ident(String)
  DefIdent(String)
  HiddenIdent(String)
  HiddenDefIdent(String)
  Bottom
  // Keywords
  Null
  True
  False
  Package
  Import
  Let
  For
  In
  If
  // Literals & interpolation
  IntLit(String)
  FloatLit(String)
  StringLit(String)
  BytesLit(Bytes)
  StringInterpStart(String)
  StringInterpMid(String)
  StringInterpEnd(String)
  BytesInterpStart(Bytes)
  BytesInterpMid(Bytes)
  BytesInterpEnd(Bytes)
  // Attributes
  Attribute(String, String)
  // Delimiters & punctuation
  LBrace
  RBrace
  LBracket
  RBracket
  LParen
  RParen
  Colon
  Comma
  Dot
  Ellipsis
  // Operators
  And
  Or
  Land
  Lor
  Star
  Question
  Bang
  Assign
  Eq
  Neq
  Lt
  Le
  Gt
  Ge
  Match
  NotMatch
  Plus
  Minus
  Slash
  // End of input
  Eof
}

///|
/// A lexed token carrying its kind, raw source lexeme, and source span.
#derive(Eq, Debug)
pub(all) struct Token {
  kind : TokenKind
  lexeme : String
  span : Span
}

///|
/// A lexed line comment (`//...`) without trailing CR/LF and its exact source span.
#derive(Eq, Debug)
pub(all) struct Comment {
  text : String
  span : Span
}

///|
/// Lexical diagnostic categories produced by `tokenize`.
#derive(Eq, Debug)
pub(all) enum LexErrorKind {
  UnexpectedChar(Char)
  UnterminatedString
  UnterminatedBytes
  UnterminatedAttribute
  InvalidEscape(Char)
  InvalidEscapeSequence(String)
  InvalidMultilineString(String)
  InvalidNumber(String)
}

///|
/// A lexical error with its exact source span.
#derive(Eq, Debug)
pub(all) struct LexError {
  kind : LexErrorKind
  span : Span
}