parser.y

Tue, 01 Jan 2002 06:11:43 +0000

author
eric
date
Tue, 01 Jan 2002 06:11:43 +0000
changeset 30
35fad7ec7732
parent 27
7a28031fe457
child 31
2cec996b38bc
permissions
-rw-r--r--

add support for PDF file attributes: author, creator, title, etc.

eric@5 1 %{
eric@11 2 #include <stdio.h>
eric@11 3 #include "type.h"
eric@17 4 #include "semantics.h"
eric@5 5 %}
eric@5 6
eric@5 7 %union {
eric@5 8 int integer;
eric@27 9 char character;
eric@5 10 double fp;
eric@5 11 char *string;
eric@18 12 page_size_t size;
eric@18 13 range_t range;
eric@27 14 page_label_t page_label;
eric@5 15 }
eric@5 16
eric@5 17 %token <integer> INTEGER
eric@5 18 %token <fp> FLOAT
eric@5 19 %token <string> STRING
eric@27 20 %token <character> CHARACTER
eric@9 21 %token <size> PAGE_SIZE
eric@5 22
eric@7 23 %token ELIPSIS
eric@7 24
eric@9 25 %token CM
eric@9 26 %token INCH
eric@9 27
eric@5 28 %token EVEN
eric@5 29 %token ODD
eric@5 30 %token ALL
eric@5 31
eric@9 32 %token PORTRAIT
eric@9 33 %token LANDSCAPE
eric@9 34
eric@11 35 %token FILE_KEYWORD
eric@5 36 %token IMAGE
eric@9 37 %token IMAGES
eric@5 38 %token ROTATE
eric@5 39 %token CROP
eric@5 40 %token SIZE
eric@11 41 %token RESOLUTION
eric@5 42 %token INPUT
eric@5 43
eric@27 44 %token LABEL
eric@5 45 %token PAGE
eric@8 46 %token PAGES
eric@5 47 %token BOOKMARK
eric@5 48 %token OUTPUT
eric@5 49
eric@30 50 %token AUTHOR
eric@30 51 %token CREATOR
eric@30 52 %token TITLE
eric@30 53 %token SUBJECT
eric@30 54 %token KEYWORDS
eric@30 55
eric@11 56 %type <range> range
eric@11 57 %type <range> image_ranges
eric@11 58 %type <range> page_ranges
eric@11 59
eric@11 60 %type <fp> unit
eric@11 61
eric@11 62
eric@9 63
eric@9 64 %type <fp> length
eric@5 65
eric@5 66 %%
eric@5 67
eric@9 68 statements:
eric@9 69 statement
eric@9 70 | statements statement ;
eric@5 71
eric@9 72 statement:
eric@9 73 input_statement
eric@9 74 | output_statement ;
eric@5 75
eric@5 76
eric@11 77 range:
eric@11 78 INTEGER ELIPSIS INTEGER { $$.first = $1; $$.last = $3; }
eric@11 79 | INTEGER { $$.first = $1; $$.last = $1; } ;
eric@5 80
eric@9 81 image_ranges:
eric@20 82 range { input_images ($1); }
eric@20 83 | image_ranges ',' range { input_images ($3); } ;
eric@5 84
eric@5 85
eric@12 86 input_file_clause:
eric@17 87 FILE_KEYWORD STRING ';' { input_set_file ($2) } ;
eric@5 88
eric@5 89 image_clause:
eric@20 90 IMAGE INTEGER ';' { range_t range = { $2, $2 }; input_images (range); } ;
eric@9 91
eric@9 92 images_clause:
eric@19 93 IMAGES image_ranges ';' ;
eric@5 94
eric@5 95 rotate_clause:
eric@20 96 ROTATE INTEGER ';' { input_set_rotation ($2) } ;
eric@5 97
eric@9 98 unit:
eric@11 99 /* empty */ /* default to INCH */ { $$ = 25.4; }
eric@11 100 | CM { $$ = 1.0; }
eric@11 101 | INCH { $$ = 25.4; } ;
eric@9 102
eric@9 103 length:
eric@11 104 FLOAT unit { $$ = $1 * $2; } ;
eric@9 105
eric@5 106 crop_clause:
eric@9 107 CROP PAGE_SIZE ';'
eric@9 108 | CROP PAGE_SIZE orientation ';'
eric@9 109 | CROP length ',' length ';'
eric@9 110 | CROP length ',' length ',' length ',' length ';' ;
eric@9 111
eric@9 112 orientation:
eric@9 113 PORTRAIT
eric@9 114 | LANDSCAPE ;
eric@5 115
eric@5 116 size_clause:
eric@9 117 SIZE PAGE_SIZE ';'
eric@9 118 | SIZE PAGE_SIZE orientation ';'
eric@9 119 | SIZE length ',' length ';' ;
eric@9 120
eric@11 121 resolution_clause:
eric@11 122 RESOLUTION FLOAT unit ;
eric@11 123
eric@9 124 modifier_clause:
eric@11 125 rotate_clause | crop_clause | size_clause | resolution_clause;
eric@9 126
eric@9 127 modifier_clauses:
eric@9 128 modifier_clause
eric@9 129 | modifier_clauses modifier_clause;
eric@9 130
eric@9 131 modifier_clause_list:
eric@9 132 '{' modifier_clauses '}' ;
eric@5 133
eric@5 134 part_clause:
eric@19 135 ODD { input_set_modifier_context (INPUT_MODIFIER_ODD); }
eric@19 136 modifier_clause_list ';'
eric@19 137 { input_set_modifier_context (INPUT_MODIFIER_ALL); }
eric@20 138 | EVEN { input_set_modifier_context (INPUT_MODIFIER_EVEN); }
eric@19 139 modifier_clause_list ';'
eric@19 140 { input_set_modifier_context (INPUT_MODIFIER_ALL); } ;
eric@5 141
eric@5 142 input_clause:
eric@12 143 input_file_clause
eric@9 144 | image_clause
eric@9 145 | images_clause
eric@19 146 | part_clause
eric@9 147 | modifier_clause
eric@7 148 | input_clause_list ;
eric@5 149
eric@5 150 input_clauses:
eric@5 151 input_clause
eric@7 152 | input_clauses input_clause ;
eric@7 153
eric@7 154 input_clause_list:
eric@7 155 '{' input_clauses '}' ;
eric@5 156
eric@5 157 input_statement:
eric@8 158 INPUT input_clauses ;
eric@5 159
eric@30 160 pdf_file_attribute:
eric@30 161 AUTHOR STRING { output_set_author ($2); }
eric@30 162 | CREATOR STRING { output_set_creator ($2); }
eric@30 163 | TITLE STRING { output_set_title ($2); }
eric@30 164 | SUBJECT STRING { output_set_subject ($2); }
eric@30 165 | KEYWORDS STRING { output_set_keywords ($2); } ;
eric@30 166
eric@30 167 pdf_file_attributes:
eric@30 168 /* empty */
eric@30 169 | pdf_file_attribute
eric@30 170 | pdf_file_attributes pdf_file_attribute ;
eric@30 171
eric@12 172 output_file_clause:
eric@30 173 FILE_KEYWORD STRING { output_set_file ($2); }
eric@30 174 pdf_file_attributes ';'
eric@12 175
eric@27 176 label_clause:
eric@27 177 LABEL ';' { page_label_t label = { NULL, '\0' }; output_set_page_label (label); }
eric@27 178 | LABEL STRING ';' { page_label_t label = { $2, '\0' }; output_set_page_label (label); }
eric@27 179 | LABEL CHARACTER ';' { page_label_t label = { NULL, $2 }; output_set_page_label (label); }
eric@27 180 | LABEL STRING ',' CHARACTER ';' { page_label_t label = { $2, $4 }; output_set_page_label (label); } ;
eric@20 181
eric@9 182 page_ranges:
eric@20 183 range { output_pages ($1); }
eric@20 184 | page_ranges ',' range { output_pages ($3); } ;
eric@9 185
eric@5 186 page_clause:
eric@20 187 PAGE INTEGER ';' { range_t range = { $2, $2 }; output_pages (range); } ;
eric@8 188
eric@8 189 pages_clause:
eric@20 190 PAGES page_ranges ';' ;
eric@20 191
eric@20 192 bookmark_name:
eric@20 193 STRING { output_set_bookmark ($1); } ;
eric@20 194
eric@20 195 bookmark_name_list:
eric@20 196 bookmark_name
eric@20 197 | bookmark_name_list ',' bookmark_name ;
eric@5 198
eric@5 199 bookmark_clause:
eric@27 200 BOOKMARK { output_push_context (); bookmark_level++; }
eric@20 201 bookmark_name_list
eric@27 202 output_clause_list ';' { bookmark_level--; output_pop_context (); } ;
eric@5 203
eric@5 204 output_clause:
eric@12 205 output_file_clause
eric@27 206 | label_clause
eric@12 207 | page_clause | pages_clause
eric@12 208 | bookmark_clause
eric@7 209 | output_clause_list ;
eric@5 210
eric@5 211 output_clauses:
eric@5 212 output_clause
eric@7 213 | output_clauses output_clause ;
eric@7 214
eric@7 215 output_clause_list:
eric@20 216 '{' { output_push_context (); }
eric@20 217 output_clauses '}' { output_pop_context (); } ;
eric@5 218
eric@5 219 output_statement:
eric@8 220 OUTPUT output_clauses ;