File: cudf_822_lexer.mll

package info (click to toggle)
cudf 0.7-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 632 kB
  • sloc: ml: 2,532; ansic: 869; makefile: 205
file content (50 lines) | stat: -rw-r--r-- 1,998 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(*****************************************************************************)
(*  libCUDF - CUDF (Common Upgrade Description Format) manipulation library  *)
(*  Copyright (C) 2009-2012  Stefano Zacchiroli <zack@upsilon.cc>            *)
(*                                                                           *)
(*  This library is free software: you can redistribute it and/or modify     *)
(*  it under the terms of the GNU Lesser General Public License as           *)
(*  published by the Free Software Foundation, either version 3 of the       *)
(*  License, or (at your option) any later version.  A special linking       *)
(*  exception to the GNU Lesser General Public License applies to this       *)
(*  library, see the COPYING file for more information.                      *)
(*****************************************************************************)

(** Lexer for CUDF 822 surface syntax *)

{
  open Cudf_types
  open Cudf_822_parser

  let get_range { Lexing.lex_start_p = start_pos;
		  Lexing.lex_curr_p = end_pos } =
    (start_pos, end_pos)

  (* Lexing.new_line is only available in OCaml 3.11 or greater *)
  (* let lexing_new_line = Lexing.new_line *)
  let lexing_new_line lexbuf =
    let lcp = lexbuf.Lexing.lex_curr_p in
    lexbuf.Lexing.lex_curr_p <-
      { lcp with
	  Lexing.pos_lnum = lcp.Lexing.pos_lnum + 1;
	  Lexing.pos_bol = lcp.Lexing.pos_cnum; }

}

let lower_letter = [ 'a' - 'z' ]
let digit = [ '0' - '9' ]
let blank = [ ' ' '\t' ]
let ident = lower_letter (lower_letter | digit | '-')*

rule token_822 = parse
  | (ident as field) ':' ' '
    ([^'\n']* as rest)		{ FIELD(field, (get_range lexbuf, rest)) }
  | ' ' ([^'\n']* as rest)	{ CONT(get_range lexbuf, rest) }
  | '#' [^'\n']* ('\n'|eof)	{ token_822 lexbuf }
  | blank* '\n'			{ lexing_new_line lexbuf;
				  EOL }
  | eof				{ EOF }
  | _				{ raise (Parse_error_822
					   ("unexpected RFC 822 token",
					    (lexbuf.Lexing.lex_start_p,
					     lexbuf.Lexing.lex_curr_p))) }