import type { GrlKeyword } from "./keywords.js";
import type { UnitKind } from "./units.js";

export type GrlTokenKind =
  | "keyword"
  | "identifier"
  | "number"
  | "string"
  | "comment"
  | "punctuation"
  | "operator"
  | "eof";

export interface GrlSourcePosition {
  offset: number;
  line: number;
  column: number;
}

export interface GrlSourceRange {
  start: GrlSourcePosition;
  end: GrlSourcePosition;
}

export interface GrlBaseToken {
  kind: GrlTokenKind;
  raw: string;
  range: GrlSourceRange;
}

export interface GrlKeywordToken extends GrlBaseToken {
  kind: "keyword";
  value: GrlKeyword;
}

export interface GrlIdentifierToken extends GrlBaseToken {
  kind: "identifier";
  value: string;
}

export interface GrlNumberToken extends GrlBaseToken {
  kind: "number";
  value: number;
  unit?: {
    raw: string;
    kind: UnitKind;
    siUnit: string;
    normalizedValue: number;
  };
}

export interface GrlStringToken extends GrlBaseToken {
  kind: "string";
  value: string;
}

export interface GrlCommentToken extends GrlBaseToken {
  kind: "comment";
  style: "line" | "block";
  value: string;
}

export interface GrlPunctuationToken extends GrlBaseToken {
  kind: "punctuation";
  value: string;
}

export interface GrlOperatorToken extends GrlBaseToken {
  kind: "operator";
  value: string;
}

export interface GrlEofToken extends GrlBaseToken {
  kind: "eof";
  value: "";
}

export type GrlToken =
  | GrlKeywordToken
  | GrlIdentifierToken
  | GrlNumberToken
  | GrlStringToken
  | GrlCommentToken
  | GrlPunctuationToken
  | GrlOperatorToken
  | GrlEofToken;
