~ubuntu-branches/ubuntu/lucid/camomile/lucid

« back to all changes in this revision

Viewing changes to internal/uReStrLexer.mll

  • Committer: Bazaar Package Importer
  • Author(s): Sylvain Le Gall
  • Date: 2005-12-03 01:18:55 UTC
  • Revision ID: james.westby@ubuntu.com-20051203011855-qzvwlld1xyqnl62t
Tags: upstream-0.6.3
ImportĀ upstreamĀ versionĀ 0.6.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(* $Id: uReStrLexer.mll,v 1.4 2003/12/19 17:24:34 yori Exp $
 
2
   Copyright 2003 Yamagata Yoriyuki *)
 
3
 
 
4
{
 
5
open UReStrParser
 
6
}
 
7
 
 
8
let ascii_char = ['\000'-'\127']
 
9
 
 
10
let utf8_char =
 
11
  ['\194'-'\223']['\128'-'\191']
 
12
| ['\224'-'\239']['\128'-'\191']['\128'-'\191']
 
13
| ['\240'-'\247']['\128'-'\191']['\128'-'\191']['\128'-'\191']
 
14
| ['\248'-'\251']['\128'-'\191']['\128'-'\191']['\128'-'\191']['\128'-'\191']
 
15
| ['\252'-'\253']['\128'-'\191']['\128'-'\191']['\128'-'\191']['\128'-'\191']['\128'-'\191']
 
16
 
 
17
let hex_char = ['0'-'9''a'-'f''A'-'F']
 
18
 
 
19
rule token = parse
 
20
| '.' {DOT}
 
21
| '*' {ASTARISK}
 
22
| '+' {PLUS}
 
23
| '?' {QUESTION}
 
24
| '[' {LEFT_BRACKET}
 
25
| ']' {RIGHT_BRACKET}
 
26
| '-' {MINUS}
 
27
| '^' {HAT}
 
28
| '$' {DOLLAR}
 
29
| "\\|" {ALT}
 
30
| "\\(" {LEFT_PAREN}
 
31
| "\\)" {RIGHT_PAREN}
 
32
| "\\`" {BOS}
 
33
| "\\'" {EOS}
 
34
| "\\{" ['0'-'9']+ (',' ['0'-'9']*)? "\\}" {
 
35
  let s = Lexing.lexeme lexbuf in
 
36
  try
 
37
    let n = String.index s ',' in
 
38
    let s1 = String.sub s 2 (n - 2) in
 
39
    let n1 = int_of_string s1 in
 
40
    let len2 = String.length s - n - 3 in
 
41
    if len2 <= 0 then REPN (n1, None, s) else
 
42
    let s2 = String.sub s (n + 1) len2 in
 
43
    let m = int_of_string s2 in
 
44
    REPN (n1, Some m, s)
 
45
  with Not_found ->
 
46
    let s1 = String.sub s 2 (String.length s - 4) in
 
47
    let n = int_of_string s1 in
 
48
    REPN (n, Some n, s)}
 
49
| '{' {LEFT_BRACE}
 
50
| '}' {RIGHT_BRACE}
 
51
| ' ' {SPACE}
 
52
| '&' {AND}
 
53
| '|'  {OR}
 
54
| ':' {COLON}
 
55
| "\\u" hex_char hex_char hex_char hex_char 
 
56
| "\\U" hex_char hex_char hex_char hex_char hex_char hex_char hex_char hex_char
 
57
    {let s = Lexing.lexeme lexbuf in
 
58
    let s = "0x" ^ (String.sub s 2 (String.length s - 2)) in
 
59
    let n = int_of_string s in
 
60
    UCHAR (UChar.chr_of_uint n)}
 
61
| '\\' ascii_char {
 
62
  let s = Lexing.lexeme lexbuf in
 
63
  ASCII s.[0]}
 
64
| '\\' utf8_char {
 
65
  let s = Lexing.lexeme lexbuf in
 
66
  UTF8.validate s;
 
67
  UCHAR (UTF8.look s 2)}
 
68
| ascii_char {
 
69
  let s = Lexing.lexeme lexbuf in
 
70
  ASCII s.[0]}
 
71
| utf8_char {
 
72
  let s = Lexing.lexeme lexbuf in
 
73
  UTF8.validate s;
 
74
  UCHAR (UTF8.look s 0)}
 
75
| eof {END}