File: condition_lexer.mll

package info (click to toggle)
bibtex2html 1.99-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 912 kB
  • sloc: ml: 6,334; makefile: 714; perl: 50; sh: 15
file content (126 lines) | stat: -rw-r--r-- 4,461 bytes parent folder | download | duplicates (5)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
(**************************************************************************)
(*  bibtex2html - A BibTeX to HTML translator                             *)
(*  Copyright (C) 1997-2014 Jean-Christophe Filliâtre and Claude Marché   *)
(*                                                                        *)
(*  This software is free software; you can redistribute it and/or        *)
(*  modify it under the terms of the GNU General Public                   *)
(*  License version 2, as published by the Free Software Foundation.      *)
(*                                                                        *)
(*  This software is distributed in the hope that it will be useful,      *)
(*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                  *)
(*                                                                        *)
(*  See the GNU General Public License version 2 for more details         *)
(*  (enclosed in the file GPL).                                           *)
(**************************************************************************)

{

  open Condition_parser

  exception Lex_error of string;;

  let string_buf = Buffer.create 79

  let char_of_string s =
    try
      char_of_int (int_of_string s)
    with
	_ -> raise (Lex_error ("invalid character code"))

}

let digit = ['0' - '9']

let special_char = ['$' '^' '.' '*' '+' '?' '[' ']' 'b' '|' '(' ')' '\\']

let letter = [ 'A'-'Z' 'a'-'z' ]

rule token = parse
    [' ' '\t' '\n'] +     { token lexbuf }
  | "and"                 { AND }
  | "or"                  { OR }
  | "not"                 { NOT }
  | "exists"              { EXISTS }
  | "&"                   { AND }
  | "|"                   { OR }
  | "!"                   { NOT }
  | "?"                   { EXISTS }
  | ':'                   { COLON }
  | '('                   { LPAR }
  | ')'                   { RPAR }
  | "$key"                { DOLLAR_KEY }
  | "$type"               { DOLLAR_TYPE }
  | (">" | "<" | ">=" | "<=" | "=" | "<>" | "==" | "!=") 
                          { COMP(Lexing.lexeme lexbuf) }
  | digit +               { INT(Lexing.lexeme lexbuf) }
  | (letter | '_') (letter | digit | '_' | '-') *   
                          { IDENT(Lexing.lexeme lexbuf) }
  | '"'                   { Buffer.clear string_buf; STRING(string lexbuf) }
  | '\''                  { Buffer.clear string_buf; STRING(string2 lexbuf) }
  | eof                   { EOF }
  | _                     { raise 
			      (Lex_error 
				 ("Invalid character " ^ 
				  (Lexing.lexeme lexbuf))) }

and string = parse
    '"'                   
      { Buffer.contents string_buf }
  | eof                   
      { raise (Lex_error ("Unterminated string")) }
  | '\\' '"'              
      { Buffer.add_char string_buf '"';
	string lexbuf }
  | '\\' 'r'              
      { Buffer.add_char string_buf '\r';
	string lexbuf }
  | '\\' 'n'              
      { Buffer.add_char string_buf '\n';
	string lexbuf }
  | '\\' 't'              
      { Buffer.add_char string_buf '\t';
	string lexbuf }
  | '\\' special_char    
      { Buffer.add_string string_buf (Lexing.lexeme lexbuf);
	string lexbuf }
  | '\\' (digit digit digit as s) 
      { Buffer.add_char string_buf (char_of_string s);
	string lexbuf }
  | '\\' _ 
      { raise (Lex_error ("Invalid escape character " ^ 
			  (Lexing.lexeme lexbuf))) }
  | _                     
      { Buffer.add_char string_buf (Lexing.lexeme_char lexbuf 0);
	string lexbuf }
 
and string2 = parse
  |  '\''                 
      { Buffer.contents string_buf }
  | eof                  
      { raise (Lex_error ("Unterminated string")) }
  | '\\' '\''   
      { Buffer.add_char string_buf '\'';
	string2 lexbuf }
  | '\\' 'r'   
      { Buffer.add_char string_buf '\r';
	string2 lexbuf }
  | '\\' 'n'             
      { Buffer.add_char string_buf '\n';
	string2 lexbuf }
  | '\\' 't' 
      { Buffer.add_char string_buf '\t';
	string2 lexbuf }
  | '\\' special_char  
      { Buffer.add_string string_buf (Lexing.lexeme lexbuf);
	string2 lexbuf }
  | '\\' (digit digit digit as s)
      { Buffer.add_char string_buf (char_of_string s);
	string2 lexbuf }
  | '\\' _
      { raise (Lex_error ("Invalid escape character " ^ 
			  (Lexing.lexeme lexbuf))) }
  | _                     
      { Buffer.add_char string_buf (Lexing.lexeme_char lexbuf 0);
	string2 lexbuf }