File: condition_lexer.mll

package info (click to toggle)
bibtex2html 1.75-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 484 kB
  • ctags: 414
  • sloc: ml: 3,036; sh: 297; makefile: 243; perl: 50
file content (101 lines) | stat: -rw-r--r-- 3,046 bytes parent folder | download
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
{

  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' '|' '(' ')' '\\']

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) }
  | ['0'-'9']+            { INT(Lexing.lexeme lexbuf) }
  | ['A'-'Z' 'a'-'z' '_'] +   { 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")) }
  | '\\' '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")) }
  | '\\' '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 }