parser.y

Fri, 14 Mar 2003 08:56:38 +0000

author
eric
date
Fri, 14 Mar 2003 08:56:38 +0000
changeset 132
ccf1c28a2940
parent 125
e2ef1c2f9eca
permissions
-rw-r--r--

remove debug output.

eric@63 1 /*
eric@125 2 * tumble: build a PDF file from image files
eric@63 3 *
eric@63 4 * Parser
eric@125 5 * $Id: parser.y,v 1.18 2003/03/13 00:57:05 eric Exp $
eric@63 6 * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
eric@63 7 *
eric@63 8 * This program is free software; you can redistribute it and/or modify
eric@63 9 * it under the terms of the GNU General Public License version 2 as
eric@63 10 * published by the Free Software Foundation. Note that permission is
eric@63 11 * not granted to redistribute this program under the terms of any
eric@63 12 * other version of the General Public License.
eric@63 13 *
eric@63 14 * This program is distributed in the hope that it will be useful,
eric@63 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
eric@63 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
eric@63 17 * GNU General Public License for more details.
eric@63 18 *
eric@63 19 * You should have received a copy of the GNU General Public License
eric@63 20 * along with this program; if not, write to the Free Software
eric@63 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
eric@63 22 */
eric@63 23
eric@5 24 %{
eric@48 25 #include <stdbool.h>
eric@48 26 #include <stdint.h>
eric@11 27 #include <stdio.h>
eric@17 28 #include "semantics.h"
eric@5 29 %}
eric@5 30
eric@5 31 %union {
eric@5 32 int integer;
eric@27 33 char character;
eric@5 34 double fp;
eric@5 35 char *string;
eric@18 36 page_size_t size;
eric@18 37 range_t range;
eric@27 38 page_label_t page_label;
eric@5 39 }
eric@5 40
eric@5 41 %token <integer> INTEGER
eric@5 42 %token <fp> FLOAT
eric@5 43 %token <string> STRING
eric@27 44 %token <character> CHARACTER
eric@9 45 %token <size> PAGE_SIZE
eric@5 46
eric@7 47 %token ELIPSIS
eric@7 48
eric@9 49 %token CM
eric@9 50 %token INCH
eric@9 51
eric@5 52 %token EVEN
eric@5 53 %token ODD
eric@5 54 %token ALL
eric@5 55
eric@9 56 %token PORTRAIT
eric@9 57 %token LANDSCAPE
eric@9 58
eric@11 59 %token FILE_KEYWORD
eric@5 60 %token IMAGE
eric@9 61 %token IMAGES
eric@5 62 %token ROTATE
eric@5 63 %token CROP
eric@5 64 %token SIZE
eric@11 65 %token RESOLUTION
eric@5 66 %token INPUT
eric@5 67
eric@27 68 %token LABEL
eric@5 69 %token PAGE
eric@8 70 %token PAGES
eric@5 71 %token BOOKMARK
eric@5 72 %token OUTPUT
eric@5 73
eric@30 74 %token AUTHOR
eric@30 75 %token CREATOR
eric@30 76 %token TITLE
eric@30 77 %token SUBJECT
eric@30 78 %token KEYWORDS
eric@30 79
eric@11 80 %type <range> range
eric@11 81 %type <range> image_ranges
eric@11 82 %type <range> page_ranges
eric@11 83
eric@11 84 %type <fp> unit
eric@11 85
eric@32 86 %type <fp> length
eric@9 87
eric@32 88 %type <integer> orientation
eric@32 89
eric@32 90 %type <size> page_size
eric@5 91
eric@5 92 %%
eric@5 93
eric@9 94 statements:
eric@9 95 statement
eric@9 96 | statements statement ;
eric@5 97
eric@9 98 statement:
eric@9 99 input_statement
eric@9 100 | output_statement ;
eric@5 101
eric@5 102
eric@11 103 range:
eric@11 104 INTEGER ELIPSIS INTEGER { $$.first = $1; $$.last = $3; }
eric@11 105 | INTEGER { $$.first = $1; $$.last = $1; } ;
eric@5 106
eric@9 107 image_ranges:
eric@20 108 range { input_images ($1); }
eric@20 109 | image_ranges ',' range { input_images ($3); } ;
eric@5 110
eric@5 111
eric@12 112 input_file_clause:
eric@17 113 FILE_KEYWORD STRING ';' { input_set_file ($2) } ;
eric@5 114
eric@5 115 image_clause:
eric@20 116 IMAGE INTEGER ';' { range_t range = { $2, $2 }; input_images (range); } ;
eric@9 117
eric@9 118 images_clause:
eric@19 119 IMAGES image_ranges ';' ;
eric@5 120
eric@5 121 rotate_clause:
eric@20 122 ROTATE INTEGER ';' { input_set_rotation ($2) } ;
eric@5 123
eric@9 124 unit:
eric@32 125 /* empty */ /* default to INCH */ { $$ = 1.0; }
eric@32 126 | CM { $$ = (1.0 / 25.4); }
eric@32 127 | INCH { $$ = 1.0; } ;
eric@9 128
eric@9 129 length:
eric@11 130 FLOAT unit { $$ = $1 * $2; } ;
eric@9 131
eric@5 132 crop_clause:
eric@9 133 CROP PAGE_SIZE ';'
eric@9 134 | CROP PAGE_SIZE orientation ';'
eric@9 135 | CROP length ',' length ';'
eric@9 136 | CROP length ',' length ',' length ',' length ';' ;
eric@9 137
eric@9 138 orientation:
eric@32 139 PORTRAIT { $$ = 0; }
eric@32 140 | LANDSCAPE { $$ = 1; } ;
eric@32 141
eric@32 142 page_size:
eric@32 143 PAGE_SIZE { $$ = $1; }
eric@32 144 | PAGE_SIZE orientation { if ($2)
eric@32 145 {
eric@32 146 $$.width = $1.height;
eric@32 147 $$.height = $1.width;
eric@32 148 }
eric@32 149 else
eric@32 150 $$ = $1;
eric@32 151 }
eric@32 152 | length ',' length { $$.width = $1; $$.height = $3; } ;
eric@5 153
eric@5 154 size_clause:
eric@32 155 SIZE page_size ';' { input_set_page_size ($2); } ;
eric@9 156
eric@11 157 resolution_clause:
eric@11 158 RESOLUTION FLOAT unit ;
eric@11 159
eric@9 160 modifier_clause:
eric@11 161 rotate_clause | crop_clause | size_clause | resolution_clause;
eric@9 162
eric@9 163 modifier_clauses:
eric@9 164 modifier_clause
eric@9 165 | modifier_clauses modifier_clause;
eric@9 166
eric@9 167 modifier_clause_list:
eric@9 168 '{' modifier_clauses '}' ;
eric@5 169
eric@5 170 part_clause:
eric@19 171 ODD { input_set_modifier_context (INPUT_MODIFIER_ODD); }
eric@19 172 modifier_clause_list ';'
eric@19 173 { input_set_modifier_context (INPUT_MODIFIER_ALL); }
eric@20 174 | EVEN { input_set_modifier_context (INPUT_MODIFIER_EVEN); }
eric@19 175 modifier_clause_list ';'
eric@19 176 { input_set_modifier_context (INPUT_MODIFIER_ALL); } ;
eric@5 177
eric@5 178 input_clause:
eric@12 179 input_file_clause
eric@9 180 | image_clause
eric@9 181 | images_clause
eric@19 182 | part_clause
eric@9 183 | modifier_clause
eric@7 184 | input_clause_list ;
eric@5 185
eric@5 186 input_clauses:
eric@5 187 input_clause
eric@7 188 | input_clauses input_clause ;
eric@7 189
eric@7 190 input_clause_list:
eric@7 191 '{' input_clauses '}' ;
eric@5 192
eric@5 193 input_statement:
eric@8 194 INPUT input_clauses ;
eric@5 195
eric@30 196 pdf_file_attribute:
eric@30 197 AUTHOR STRING { output_set_author ($2); }
eric@30 198 | CREATOR STRING { output_set_creator ($2); }
eric@30 199 | TITLE STRING { output_set_title ($2); }
eric@30 200 | SUBJECT STRING { output_set_subject ($2); }
eric@30 201 | KEYWORDS STRING { output_set_keywords ($2); } ;
eric@30 202
eric@31 203 pdf_file_attribute_list:
eric@31 204 pdf_file_attribute
eric@31 205 | pdf_file_attribute_list pdf_file_attribute ;
eric@31 206
eric@30 207 pdf_file_attributes:
eric@30 208 /* empty */
eric@31 209 | pdf_file_attribute_list ;
eric@30 210
eric@12 211 output_file_clause:
eric@30 212 FILE_KEYWORD STRING { output_set_file ($2); }
eric@48 213 pdf_file_attributes ';' ;
eric@12 214
eric@27 215 label_clause:
eric@27 216 LABEL ';' { page_label_t label = { NULL, '\0' }; output_set_page_label (label); }
eric@27 217 | LABEL STRING ';' { page_label_t label = { $2, '\0' }; output_set_page_label (label); }
eric@27 218 | LABEL CHARACTER ';' { page_label_t label = { NULL, $2 }; output_set_page_label (label); }
eric@27 219 | LABEL STRING ',' CHARACTER ';' { page_label_t label = { $2, $4 }; output_set_page_label (label); } ;
eric@20 220
eric@9 221 page_ranges:
eric@20 222 range { output_pages ($1); }
eric@20 223 | page_ranges ',' range { output_pages ($3); } ;
eric@9 224
eric@5 225 page_clause:
eric@20 226 PAGE INTEGER ';' { range_t range = { $2, $2 }; output_pages (range); } ;
eric@8 227
eric@8 228 pages_clause:
eric@20 229 PAGES page_ranges ';' ;
eric@20 230
eric@20 231 bookmark_name:
eric@20 232 STRING { output_set_bookmark ($1); } ;
eric@20 233
eric@20 234 bookmark_name_list:
eric@20 235 bookmark_name
eric@20 236 | bookmark_name_list ',' bookmark_name ;
eric@5 237
eric@5 238 bookmark_clause:
eric@27 239 BOOKMARK { output_push_context (); bookmark_level++; }
eric@20 240 bookmark_name_list
eric@27 241 output_clause_list ';' { bookmark_level--; output_pop_context (); } ;
eric@5 242
eric@5 243 output_clause:
eric@12 244 output_file_clause
eric@27 245 | label_clause
eric@12 246 | page_clause | pages_clause
eric@12 247 | bookmark_clause
eric@7 248 | output_clause_list ;
eric@5 249
eric@5 250 output_clauses:
eric@5 251 output_clause
eric@7 252 | output_clauses output_clause ;
eric@7 253
eric@7 254 output_clause_list:
eric@20 255 '{' { output_push_context (); }
eric@20 256 output_clauses '}' { output_pop_context (); } ;
eric@5 257
eric@5 258 output_statement:
eric@8 259 OUTPUT output_clauses ;