(***********************************************************************)
(*                                                                     *)
(*                                 GALAX                               *)
(*                              XQuery Engine                          *)
(*                                                                     *)
(*  Copyright 2001-2003, Lucent Technologies.                          *)
(*  Distributed only by permission.                                    *)
(*                                                                     *)
(***********************************************************************)

(* $Id: lexutil.mli,v 1.3 2003/06/27 00:05:07 simeon Exp $ *)

(* Module Lexutil
   Description:
     This module contains some basic functions used during lexing.
*)

(****************************)
(* Lexing global parameters *)
(****************************)

(* Language currently parsed *)

type language_kind =
  | XML_1_0
  | XPath_2_0
  | XQuery_1_0


(* Lexical state *)

type lex_state =
      (* XQuery states *)
  | SchemaState
  | DefaultState
      (* XML states *)
  | OpeningTagState
  | ClosingTagState
  | TextState
  | AttributeTextDoubleState      (* Note: There are three kinds of attribute value lexing. - Jerome *)
  | AttributeTextSingleState
  | EntityIncludedInLiteralState
  | PIState
  | CDATAState
  | CommentState
      (* Top-level document state *)
  | XMLDeclState
  | XMLDocumentState
      (* DTD states *)
  | DocTypeState
  | DTDDeclState
  | EntityValueState


(********************)
(* Comment handling *)
(********************)

val depth : int ref

(****************************)
(* String and text handling *)
(****************************)

(* String content *)

val reset_string           : unit -> unit
val add_char_to_string     : char -> unit
val add_string_to_string   : string -> unit
val get_string             : unit -> string

(**************************)
(* Lexical state handling *)
(**************************)

(* Initialization of the lexical state *)

val init_xquery_lexing : unit -> unit
val init_xml_lexing    : unit -> unit

(* Accesses the current lexical state *)

val get_current_lex_state : unit -> lex_state

(* Accesses the current quote kind *)

type attribute_quote_kind =
  | SingleQuoteKind
  | DoubleQuoteKind
  | EntityIncludedInLiteralKind

val attribute_quote_kind : unit -> attribute_quote_kind

(* Stack discipline for the lexical state *)

val push_schema                 : unit -> unit

val push_default                : unit -> unit
val push_text                   : unit -> unit
val push_attribute_text_single  : unit -> unit
val push_attribute_text_double  : unit -> unit
val push_opening_tag            : unit -> unit
val push_closing_tag            : unit -> unit
val push_processing_instruction : unit -> unit
val push_cdata                  : unit -> unit
val push_comment                : unit -> unit
val push_xmldecl                : unit -> unit
val push_xmldocument            : unit -> unit
val push_doctype                : unit -> unit
val push_dtddecl                : unit -> unit
val push_entity_value           : unit -> unit

(* entity states -- used from the parser itself! *)

val push_entity_included  : unit -> unit
val push_entity_included_in_literal  : unit -> unit

val pop_state                   : unit -> unit
val pop_state_keep_buffer       : unit -> unit

(* Parse kind *)

val get_parsing_kind : unit -> language_kind


(********************)
(* Token processing *)
(********************)

(* Extracts an axis name *)

val get_axis : string -> Xquery_ast.axis

(* Extracts the type name in a type definition *)

val get_type_defn : string -> Namespace.uqname

(* Extracts the element name in an element declaration *)

val get_element_defn : string -> Namespace.uqname

(* Extracts escaped name *)

val get_escaped_name : string -> string

(* Extracts the attribute name in an attribute declaration *)

val get_attribute_defn : string -> Namespace.uqname

(* Extracts the function name in a function definition *)

val get_function_name : string -> Namespace.uqname

(* Extracts the PI target&content *)

val get_target_pi  : string -> string

(* Extracts the character encoding *)

val get_xml_encoding_quotes : string -> string
val get_xml_encoding_single_quotes : string -> string

(* Extracts character and entity references *)

val get_char_ref       : string -> string
val get_hexchar_ref    : string -> string
val get_entity_ref     : string -> string

