-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexer.mll
More file actions
55 lines (49 loc) · 1.65 KB
/
Copy pathlexer.mll
File metadata and controls
55 lines (49 loc) · 1.65 KB
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
{
(* Patchdep
*
* dependency.ml
* Copyright (C) 2007-2008
* Sapan Bhatia <sapanb@cs.princeton.edu>
* PlanetLab *)
open Parser (* The type token is defined in parser.mli *)
open Printf
exception Eof
(* Wonder if there's a better way of doing this. *)
type lexstates = Global | Filespec | Changespec
let lexstate = ref Global
}
rule scanner = parse
| ""
{
match !lexstate with
| Global -> globscan lexbuf
| Filespec -> filespec lexbuf
| Changespec -> changespec lexbuf
}
and
globscan = parse
| "+++" { lexstate:= Filespec;filespec lexbuf}
(* For some *odd* reason "@@" doesn't work *)
| "@@" { lexstate:= Changespec;changespec lexbuf}
| eof {EOF}
| '\n' {globscan lexbuf}
| _ {let _=find_eol lexbuf in scanner lexbuf}
and
filespec = parse
| [' ''\t'] {filespec lexbuf}
| ([^' ''\n''\t']+ as fname) {lexstate:=Global;FILEDEF(fname)}
| _ {lexstate:=Global;globscan lexbuf}
and
changespec = parse
| [' ''\t'] {changespec lexbuf}
| ['+''-'](['0'-'9']+ as location)','(['0'-'9']+ as change) {
CHANGESPEC(int_of_string location, int_of_string change) }
| "@@" {lexstate:=Global;globscan lexbuf}
(* Because unidiff is broken --> *)
| ['+''-'](['0'-'9']+ as location) {
CHANGESPEC(int_of_string location, 1) }
| "@@" {lexstate:=Global;globscan lexbuf}
and
find_eol = parse
| ['\n''\r'] { () }
| _ {find_eol lexbuf}