(**
    This module contains the basic operators used in the QSP syntax.
 *)

type 'a literal = Text of string | Expression of 'a

let map_litteral : f:('a -> 'b) -> 'a literal -> 'b literal =
 fun ~f -> function Text t -> Text t | Expression e -> Expression (f e)

let eq_literal : eq:('a -> 'a -> bool) -> 'a literal -> 'a literal -> bool =
 fun ~eq l1 l2 ->
  match (l1, l2) with
  | Text s1, Text s2 -> String.equal s1 s2
  | Expression e1, Expression e2 -> eq e1 e2
  | _ -> false

type boperator =
  | Eq
  | Neq
  | Plus
  | Minus
  | Product
  | Div
  | Gt
  | Lt
  | Gte
  | Lte
  | And
  | Or
  | Mod
[@@deriving eq, show]

and uoperator = No | Neg | Add [@@deriving eq, show]

and assignation_operator =
  | Eq'
  | Inc  (** += *)
  | Decr  (** -= *)
  | Mult
  | Div_assign
[@@deriving eq, show]

type function_ =
  | Arrcomp
  | Arrpos
  | Arrsize
  | Countobj
  | Desc
  | Desc'
  | Dyneval
  | Dyneval'
  | Func
  | Func'
  | Getobj
  | Getobj'
  | Iif
  | Iif'
  | Input
  | Input'
  | Instr
  | Isnum
  | Isplay
  | Lcase
  | Lcase'
  | Len
  | Loc
  | Max
  | Max'
  | Mid
  | Mid'
  | Min
  | Min'
  | Msecscount
  | Rand
  | Replace
  | Replace'
  | Rgb
  | Rnd
  | Selact
  | Str
  | Str'
  | Strcomp
  | Strfind
  | Strfind'
  | Strpos
  | Trim
  | Trim'
  | Ucase
  | Ucase'
  | Val
[@@deriving eq, show]

type keywords =
  | IncLib
  | Addobj
  | Cla
  | Clear
  | Clear'
  | Close
  | CloseAll
  | Cls
  | CmdClear
  | CopyArr
  | DelAct
  | FreeLib
  | DelObj
  | Dynamic
  | Exec
  | Exit
  | Gosub
  | Goto
  | Jump
  | KillAll
  | KillObj
  | KillVar
  | MainTxt
  | MainTxt'
  | Menu
  | Msg
  | Nl
  | Nl'
  | P
  | P'
  | Pl
  | Pl'
  | Play
  | OpenGame
  | OpenQst
  | RefInt
  | SaveGame
  | SetTimer
  | ShowActs
  | ShowInput
  | ShowObjs
  | ShowStat
  | Stattxt
  | Stattxt'
  | Unselect
  | View
  | Wait
  | XGoto
[@@deriving eq, show]