parser.y

Thu, 13 Mar 2003 08:57:05 +0000

author
eric
date
Thu, 13 Mar 2003 08:57:05 +0000
changeset 125
e2ef1c2f9eca
parent 63
6eddf63aa517
permissions
-rw-r--r--

changed program name from t2p to tumble.

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