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.

     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 %token AUTHOR
    51 %token CREATOR
    52 %token TITLE
    53 %token SUBJECT
    54 %token KEYWORDS
    56 %type <range> range
    57 %type <range> image_ranges
    58 %type <range> page_ranges
    60 %type <fp> unit
    64 %type <fp> length
    66 %%
    68 statements: 
    69 	statement
    70 	| statements statement ;
    72 statement:
    73 	input_statement
    74 	| output_statement ;
    77 range:
    78 	INTEGER ELIPSIS INTEGER { $$.first = $1; $$.last = $3; }
    79 	| INTEGER { $$.first = $1; $$.last = $1; } ;
    81 image_ranges:
    82 	range { input_images ($1); }
    83 	| image_ranges ',' range { input_images ($3); } ;
    86 input_file_clause:
    87 	FILE_KEYWORD STRING  ';'  { input_set_file ($2) } ;
    89 image_clause:
    90 	IMAGE INTEGER ';' { range_t range = { $2, $2 }; input_images (range); } ;
    92 images_clause:
    93 	IMAGES image_ranges ';' ;
    95 rotate_clause:
    96 	ROTATE INTEGER ';' { input_set_rotation ($2) } ;
    98 unit:
    99 	/* empty */  /* default to INCH */ { $$ = 25.4; }
   100 	| CM { $$ = 1.0; }
   101 	| INCH { $$ = 25.4; } ;
   103 length:
   104 	FLOAT unit { $$ = $1 * $2; } ;
   106 crop_clause:
   107 	CROP PAGE_SIZE ';'
   108 	| CROP PAGE_SIZE orientation ';'
   109 	| CROP length ',' length ';'
   110 	| CROP length ',' length ',' length ',' length ';' ;
   112 orientation:
   113 	PORTRAIT
   114 	| LANDSCAPE ;
   116 size_clause:
   117 	SIZE PAGE_SIZE ';'
   118 	| SIZE PAGE_SIZE orientation ';'
   119 	| SIZE length ',' length ';' ;
   121 resolution_clause:
   122 	RESOLUTION FLOAT unit ;
   124 modifier_clause:
   125 	rotate_clause | crop_clause | size_clause | resolution_clause;
   127 modifier_clauses:
   128 	modifier_clause
   129 	| modifier_clauses modifier_clause;
   131 modifier_clause_list:
   132 	'{' modifier_clauses '}' ;
   134 part_clause:
   135 	ODD { input_set_modifier_context (INPUT_MODIFIER_ODD); }
   136           modifier_clause_list ';'
   137           { input_set_modifier_context (INPUT_MODIFIER_ALL); }
   138 	| EVEN { input_set_modifier_context (INPUT_MODIFIER_EVEN); }
   139 	  modifier_clause_list ';'
   140           { input_set_modifier_context (INPUT_MODIFIER_ALL); } ;
   142 input_clause:
   143 	input_file_clause
   144 	| image_clause
   145 	| images_clause
   146 	| part_clause
   147 	| modifier_clause
   148 	| input_clause_list ;
   150 input_clauses:
   151 	input_clause
   152 	| input_clauses input_clause ;
   154 input_clause_list:
   155 	'{' input_clauses '}' ;
   157 input_statement:
   158 	INPUT input_clauses ;
   160 pdf_file_attribute:
   161 	AUTHOR STRING { output_set_author ($2); }
   162 	| CREATOR STRING { output_set_creator ($2); }
   163 	| TITLE STRING { output_set_title ($2); }
   164 	| SUBJECT STRING { output_set_subject ($2); }
   165 	| KEYWORDS STRING { output_set_keywords ($2); } ;
   167 pdf_file_attributes:
   168 	/* empty */
   169 	| pdf_file_attribute
   170 	| pdf_file_attributes pdf_file_attribute ;
   172 output_file_clause:
   173 	FILE_KEYWORD STRING { output_set_file ($2); }
   174 	pdf_file_attributes ';'
   176 label_clause:
   177 	LABEL ';' { page_label_t label = { NULL, '\0' }; output_set_page_label (label); }
   178 	| LABEL STRING ';' { page_label_t label = { $2, '\0' }; output_set_page_label (label); }
   179 	| LABEL CHARACTER ';' { page_label_t label = { NULL, $2 }; output_set_page_label (label); }
   180 	| LABEL STRING ',' CHARACTER ';' { page_label_t label = { $2, $4 }; output_set_page_label (label); } ;
   182 page_ranges:
   183 	range { output_pages ($1); }
   184 	| page_ranges ',' range { output_pages ($3); } ;
   186 page_clause:
   187 	PAGE INTEGER ';' { range_t range = { $2, $2 }; output_pages (range); } ;
   189 pages_clause:
   190 	PAGES page_ranges ';' ;
   192 bookmark_name:
   193 	STRING { output_set_bookmark ($1); } ;
   195 bookmark_name_list:
   196 	bookmark_name
   197 	| bookmark_name_list ',' bookmark_name ;
   199 bookmark_clause:
   200 	BOOKMARK { output_push_context (); bookmark_level++; }
   201 	bookmark_name_list
   202 	output_clause_list ';' { bookmark_level--; output_pop_context (); } ;
   204 output_clause:
   205 	output_file_clause
   206 	| label_clause
   207 	| page_clause | pages_clause
   208 	| bookmark_clause
   209 	| output_clause_list ;
   211 output_clauses:
   212 	output_clause
   213 	| output_clauses output_clause ;
   215 output_clause_list:
   216 	'{' { output_push_context (); }
   217 	output_clauses '}' { output_pop_context (); } ;
   219 output_statement:
   220 	OUTPUT output_clauses ;