lexbuf.mli 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. (** Lexing buffer. *)
  2. type t
  3. (** The state of the buffer *)
  4. val from_lexbuf : ?reset_line:bool -> Sedlexing.lexbuf -> t
  5. (** Create a new buffer *)
  6. val start : t -> unit
  7. (** Intialize a new run. *)
  8. val buffer : t -> Sedlexing.lexbuf
  9. (** Extract the sedlex buffer. Required in each rule. *)
  10. val positions : t -> Lexing.position * Lexing.position
  11. (** Extract the starting and ending position for the matched token.
  12. This function is used outside of the parser, in order to get the position
  13. of the latest token in the case of an error.
  14. *)
  15. val content : t -> string
  16. (** Extract the token matched by the rule *)
  17. val set_start_position : t -> Lexing.position -> unit
  18. (** Reset the starting position. Used while parsing the string to keep the
  19. begining of the whole string. *)
  20. val tokenize : (t -> 'a) -> t -> unit -> 'a * Lexing.position * Lexing.position
  21. (** Function to use in the parser in order to extract the token match, and the
  22. starting and ending position. *)
  23. val rollback : t -> unit
  24. (** Rollback the latest token matched *)
  25. (** {1 State in expressions}
  26. The comment system is terrible. The same symbol can be used for :
  27. - starting a comment
  28. - inequality operation
  29. In order to manage this, I try to identify the context in a very basic way,
  30. using a stack for determining the token to send.
  31. *)
  32. type lexer = t -> Tokens.token
  33. and buffer_builder = ?nested:bool -> Buffer.t -> t -> Tokens.token
  34. type stringWraper = {
  35. start_string : lexer -> lexer;
  36. (** Start a new string. This function is used insed the token lexer, in
  37. order to identify how to start a new string *)
  38. wrap : buffer_builder -> buffer_builder;
  39. (** function used to escape the character and add it to the buffer. This
  40. function is used inside the string lexer. *)
  41. end_string : lexer;
  42. (** Function used to match the end of the string. This function is used
  43. after the string lexer, in order to identify the end patten for a
  44. string *)
  45. }
  46. type state =
  47. | Token (** Default state, parsing the tokens *)
  48. | String of stringWraper (** String enclosed by [''] *)
  49. | MString of int (** String enclosed by [{}]*)
  50. | EndString of stringWraper
  51. (** State raised just before closing the string.
  52. The buffer is rollbacked and the position is the closing symbol. *)
  53. | Expression (** Expression where [!] is an operator *)
  54. val pp_state : Format.formatter -> state -> unit
  55. val state : t -> state option
  56. (** Get the current state for the lexer.
  57. @return [None] when in the default state *)
  58. val enter_state : t -> state -> unit
  59. (** Enter into a new state *)
  60. val leave_state : t -> unit
  61. (** Leave the current state *)
  62. val overlay : t -> lexer -> lexer
  63. val start_recovery : t -> unit
  64. (** Set the lexer in recovery mode, the lexer raise this mode after an error,
  65. in order to ignore the further errors until a new location *)
  66. val is_recovery : t -> bool
  67. (** Check if the lexer is in recovery mode *)