File: configParser_parser.mly

package info (click to toggle)
missinglib 0.4.10.debian-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 504 kB
  • ctags: 329
  • sloc: ml: 1,726; sh: 233; makefile: 163
file content (55 lines) | stat: -rw-r--r-- 1,096 bytes parent folder | download | duplicates (2)
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
/* arch-tag: ocamlyacc parser for configuration files
*/
%{
  open Lexingutil;;
  open Strutil;;

  let valmerge vallist = 
    let vl2 = List.map Strutil.strip vallist in
    String.concat "\n" vl2;;

%}

%token EOFTOK
%token <string> NEWSECTION NEWSECTION_EOF EXTENSIONLINE
%token <string * string> NEWOPTION
    
%start main
%type <(string * (string * string) list) list> main
%%

main:
  sectionlist { $1 };
  | optionlist sectionlist { ( "DEFAULT", $1 ) :: $2 }
  | optionlist             { [ "DEFAULT", $1 ] }
  | error { raise_syntax_error "ConfigParser" (Parsing.symbol_start_pos () ) }
;

sectionlist:
  EOFTOK { [] }
  | sectionhead EOFTOK { [$1, []] }
  | section sectionlist { $1 :: $2 }
;

section:
  sectionhead optionlist { $1, $2 }
;

sectionhead:
  NEWSECTION { strip $1 }
;

optionlist:
  coption optionlist { $1 :: $2 }
  | coption { [ $1 ] } 
;

extensionlist:
  EXTENSIONLINE extensionlist { $1 :: $2 }
  | EXTENSIONLINE { [ $1 ] }
;

coption:
  NEWOPTION extensionlist { ( strip (fst $1), valmerge ((snd $1) :: $2) ) }
  | NEWOPTION { ( strip (fst $1), strip (snd $1) ) }
;