Tue, 01 Jan 2002 03:46:08 +0000
change 'format' to 'label', add character type, track bookmark level.
1 %{
2 #include <stdio.h>
3 #include "type.h"
4 #include "semantics.h"
5 %}
7 %union {
8 int integer;
9 char character;
10 double fp;
11 char *string;
12 page_size_t size;
13 range_t range;
14 page_label_t page_label;
15 }
17 %token <integer> INTEGER
18 %token <fp> FLOAT
19 %token <string> STRING
20 %token <character> CHARACTER
21 %token <size> PAGE_SIZE
23 %token ELIPSIS
25 %token CM
26 %token INCH
28 %token EVEN
29 %token ODD
30 %token ALL
32 %token PORTRAIT
33 %token LANDSCAPE
35 %token FILE_KEYWORD
36 %token IMAGE
37 %token IMAGES
38 %token ROTATE
39 %token CROP
40 %token SIZE
41 %token RESOLUTION
42 %token INPUT
44 %token LABEL
45 %token PAGE
46 %token PAGES
47 %token BOOKMARK
48 %token OUTPUT
50 %type <range> range
51 %type <range> image_ranges
52 %type <range> page_ranges
54 %type <fp> unit
58 %type <fp> length
60 %%
62 statements:
63 statement
64 | statements statement ;
66 statement:
67 input_statement
68 | output_statement ;
71 range:
72 INTEGER ELIPSIS INTEGER { $$.first = $1; $$.last = $3; }
73 | INTEGER { $$.first = $1; $$.last = $1; } ;
75 image_ranges:
76 range { input_images ($1); }
77 | image_ranges ',' range { input_images ($3); } ;
80 input_file_clause:
81 FILE_KEYWORD STRING ';' { input_set_file ($2) } ;
83 image_clause:
84 IMAGE INTEGER ';' { range_t range = { $2, $2 }; input_images (range); } ;
86 images_clause:
87 IMAGES image_ranges ';' ;
89 rotate_clause:
90 ROTATE INTEGER ';' { input_set_rotation ($2) } ;
92 unit:
93 /* empty */ /* default to INCH */ { $$ = 25.4; }
94 | CM { $$ = 1.0; }
95 | INCH { $$ = 25.4; } ;
97 length:
98 FLOAT unit { $$ = $1 * $2; } ;
100 crop_clause:
101 CROP PAGE_SIZE ';'
102 | CROP PAGE_SIZE orientation ';'
103 | CROP length ',' length ';'
104 | CROP length ',' length ',' length ',' length ';' ;
106 orientation:
107 PORTRAIT
108 | LANDSCAPE ;
110 size_clause:
111 SIZE PAGE_SIZE ';'
112 | SIZE PAGE_SIZE orientation ';'
113 | SIZE length ',' length ';' ;
115 resolution_clause:
116 RESOLUTION FLOAT unit ;
118 modifier_clause:
119 rotate_clause | crop_clause | size_clause | resolution_clause;
121 modifier_clauses:
122 modifier_clause
123 | modifier_clauses modifier_clause;
125 modifier_clause_list:
126 '{' modifier_clauses '}' ;
128 part_clause:
129 ODD { input_set_modifier_context (INPUT_MODIFIER_ODD); }
130 modifier_clause_list ';'
131 { input_set_modifier_context (INPUT_MODIFIER_ALL); }
132 | EVEN { input_set_modifier_context (INPUT_MODIFIER_EVEN); }
133 modifier_clause_list ';'
134 { input_set_modifier_context (INPUT_MODIFIER_ALL); } ;
136 input_clause:
137 input_file_clause
138 | image_clause
139 | images_clause
140 | part_clause
141 | modifier_clause
142 | input_clause_list ;
144 input_clauses:
145 input_clause
146 | input_clauses input_clause ;
148 input_clause_list:
149 '{' input_clauses '}' ;
151 input_statement:
152 INPUT input_clauses ;
154 output_file_clause:
155 FILE_KEYWORD STRING ';' { output_set_file ($2) } ;
157 label_clause:
158 LABEL ';' { page_label_t label = { NULL, '\0' }; output_set_page_label (label); }
159 | LABEL STRING ';' { page_label_t label = { $2, '\0' }; output_set_page_label (label); }
160 | LABEL CHARACTER ';' { page_label_t label = { NULL, $2 }; output_set_page_label (label); }
161 | LABEL STRING ',' CHARACTER ';' { page_label_t label = { $2, $4 }; output_set_page_label (label); } ;
163 page_ranges:
164 range { output_pages ($1); }
165 | page_ranges ',' range { output_pages ($3); } ;
167 page_clause:
168 PAGE INTEGER ';' { range_t range = { $2, $2 }; output_pages (range); } ;
170 pages_clause:
171 PAGES page_ranges ';' ;
173 bookmark_name:
174 STRING { output_set_bookmark ($1); } ;
176 bookmark_name_list:
177 bookmark_name
178 | bookmark_name_list ',' bookmark_name ;
180 bookmark_clause:
181 BOOKMARK { output_push_context (); bookmark_level++; }
182 bookmark_name_list
183 output_clause_list ';' { bookmark_level--; output_pop_context (); } ;
185 output_clause:
186 output_file_clause
187 | label_clause
188 | page_clause | pages_clause
189 | bookmark_clause
190 | output_clause_list ;
192 output_clauses:
193 output_clause
194 | output_clauses output_clause ;
196 output_clause_list:
197 '{' { output_push_context (); }
198 output_clauses '}' { output_pop_context (); } ;
200 output_statement:
201 OUTPUT output_clauses ;