| 1 |
# 'checkit_tiff' is a conformance checker for baseline TIFFs |
| 2 |
# |
| 3 |
# author: Andreas Romeyke, 2015-2022 |
| 4 |
# licensed under conditions of libtiff |
| 5 |
# (see http://libtiff.maptools.org/misc.html) |
| 6 |
# |
| 7 |
# |
| 8 |
# |
| 9 |
# compile grammar with 'peg' by piumarta |
| 10 |
# |
| 11 |
start <- ( Line )+ EndOfFile |
| 12 |
Line <- LineType EndOfLine |
| 13 |
/ < [^\r\n]+ > EndOfLine {fprintf(stderr, "grammar parser error at line %i (error at '%s')\n", parser_state.lineno-1, yytext); exit(EXIT_FAILURE); } |
| 14 |
LineType <- TagLine |
| 15 |
/ ModeLine |
| 16 |
/ IncludeLine |
| 17 |
/ CommentLine |
| 18 |
/ SpaceLine |
| 19 |
CommentLine <- '#' < ( !EndOfLine .)* > { commentline(); } |
| 20 |
|
| 21 |
IncludeLine <- 'include' OpenBracket < Path > ClosingBracket { set_include ( yytext ); } |
| 22 |
|
| 23 |
SlashorBackslash <- '/' |
| 24 |
/ '\\' |
| 25 |
|
| 26 |
Path <- ( Subpath )+ |
| 27 |
|
| 28 |
Subpath <- [A-Z] |
| 29 |
/ [a-z] |
| 30 |
/ [0-9] |
| 31 |
/ '.' |
| 32 |
/ '_' |
| 33 |
/ '-' |
| 34 |
/ SlashorBackslash |
| 35 |
|
| 36 |
|
| 37 |
ModeLine <- 'mode' OpenBracket < Mode > ClosingBracket { unsigned int i = i_pop(); set_mode( i ); } |
| 38 |
LogicalOr <- 'logical_or' LogicalOrOpen LogicalOrList LogicalOrClose |
| 39 |
|
| 40 |
LogicalOrOpen <- OpenBracket { set_rule_logical_open();} |
| 41 |
LogicalOrClose <- ClosingBracket { } |
| 42 |
|
| 43 |
LogicalOrListElement <- Any { v_push( any ); incr_logical_elements();} |
| 44 |
/ Range { v_push( range); incr_logical_elements();} |
| 45 |
/ Only { v_push( only ); incr_logical_elements();} |
| 46 |
/ Number { v_push( only ); incr_logical_elements();} |
| 47 |
/ NTupel { v_push( ntupel); incr_logical_elements();} |
| 48 |
/ RegEx { v_push( regex ); incr_logical_elements();} |
| 49 |
/ FullAscii { v_push( full_ascii); incr_logical_elements();} |
| 50 |
/ PrintableAscii { v_push( printable_ascii ); incr_logical_elements();} |
| 51 |
LogicalOrList <- LogicalOrListElement (Colon LogicalOrListElement)* |
| 52 |
|
| 53 |
Mode <- 'baseline' { i_push(mode_baseline ); } |
| 54 |
/ 'enable_type_checks' { i_push(mode_enable_type_checks); } |
| 55 |
/ 'enable_offset_checks' { i_push(mode_enable_offset_checks); } |
| 56 |
/ 'enable_ifd_checks' { i_push(mode_enable_ifd_checks); } |
| 57 |
/ 'enable_deep_geotiff_checks' { i_push(mode_enable_deep_geotiff_checks); } |
| 58 |
/ 'enhanced' #/* TODO: later if all types of TIFF are supported */ |
| 59 |
|
| 60 |
TagLine <- Tag Semicolon Requirements Semicolon Content { rule_addtag_config(); } |
| 61 |
/ Tag Semicolon Requirements Semicolon LogicalOr { set_rule_logical_close(); } |
| 62 |
Tag <- < Number > { |
| 63 |
unsigned int tag = i_pop(); |
| 64 |
/* rule_tagorder_in_dsl( tag ); */ |
| 65 |
if (tag < 254) set_parse_error("wrong tag (should be >253)", yytext); |
| 66 |
else if (tag > 65535) set_parse_error("wrong tag (should be <65536)", yytext); |
| 67 |
else settag( tag ); |
| 68 |
} |
| 69 |
TagReference <- < Number > { |
| 70 |
unsigned int tag = i_pop(); |
| 71 |
if (tag < 254) set_parse_error("wrong tagreference (should be >253)", yytext); |
| 72 |
else if (tag > 65535) set_parse_error("wrong tagreference (should be <65536)", yytext); |
| 73 |
else settagref( tag ); |
| 74 |
} |
| 75 |
Semicolon <- ';' ( Space )* |
| 76 |
Requirements <- 'mandatory' { set_mandatory(); } |
| 77 |
/ IfDepends { set_ifdepends(); } |
| 78 |
/ OptDepends { set_optdepends(); } |
| 79 |
/ 'optional' { set_optional(); } |
| 80 |
IfDepends <- 'depends' OpenBracket TagReference Dot ValueReference ClosingBracket |
| 81 |
|
| 82 |
OptDepends <- 'optdepends' OpenBracket TagReference Dot ValueReference ClosingBracket |
| 83 |
|
| 84 |
|
| 85 |
Content <- Any { v_push( any ); } |
| 86 |
/ Range { v_push( range); } |
| 87 |
/ Only { v_push( only ); } |
| 88 |
/ NTupel { v_push( ntupel ); reset_valuelist() } |
| 89 |
/ RegEx { v_push( regex ); } |
| 90 |
/ PrintableAscii { v_push( printable_ascii ); } |
| 91 |
/ FullAscii { v_push( full_ascii ); } |
| 92 |
/ Datetime { v_push( datetime ); } |
| 93 |
/ Iccprofile { v_push( iccprofile ); } |
| 94 |
# / SBit { v_push( sbit ); } |
| 95 |
|
| 96 |
Range <- 'range' OpenBracket Number Colon Number ClosingBracket |
| 97 |
|
| 98 |
Number <- < '0x' [0-9a-f]+ > { i_push(strtoul(yytext, NULL, 16) ); } |
| 99 |
/ '2^' < ( Digit )+ > { i_push((unsigned long)2 <<atoul(yytext) ); } |
| 100 |
/ < ( Digit )+ > { i_push(atoul(yytext) );} |
| 101 |
|
| 102 |
Colon <- ',' (Space )* |
| 103 |
Dot <- '.' (Space )* |
| 104 |
OpenBracket <- '(' |
| 105 |
ClosingBracket <- ')' |
| 106 |
|
| 107 |
ValueList <- Value (Colon Value)* |
| 108 |
Value <- Number { incr_values(); } |
| 109 |
NTupel <- 'ntupel' OpenBracket ValueList ClosingBracket {unsigned int v=parser_state.valuelist; i_push(v); reset_valuelist(); } |
| 110 |
ValueReference <- Any { parser_state.any_reference = any_ref; } |
| 111 |
/ Number { parser_state.any_reference = only_ref; i_push(atoul(yytext) );} |
| 112 |
/ RegEx { parser_state.any_reference = regex_ref; } |
| 113 |
/ Range { parser_state.any_reference = range_ref; } |
| 114 |
/ NTupel { parser_state.any_reference = ntupel_ref; } |
| 115 |
/ Only { parser_state.any_reference = only_ref; } |
| 116 |
Only <- 'only' OpenBracket Number ClosingBracket { } |
| 117 |
#SBit <- 'sbit' OpenBracket < Digit > ClosingBracket{ i_push(atoul(yytext) ); } |
| 118 |
# / 'sbit' OpenBracket Digit { set_parse_error("'sbit' expects a closing bracket", yytext); } |
| 119 |
# / 'sbit' OpenBracket { set_parse_error("'sbit' expects a digit", yytext); } |
| 120 |
# / 'sbit' { set_parse_error("'sbit' expects an open bracket", yytext); } |
| 121 |
RegEx <- 'regex' OpenBracket '"' < ( PCRE )* > '"' ClosingBracket { regex_push ( yytext ); } |
| 122 |
Datetime <- 'datetime' |
| 123 |
Iccprofile <- 'iccprofile' |
| 124 |
PrintableAscii <- 'printascii' |
| 125 |
FullAscii <- 'fullascii' |
| 126 |
SpaceLine <- ( Space )* |
| 127 |
Space <- ' ' / '\t' |
| 128 |
Any <- 'any' |
| 129 |
Digit <- [0-9] |
| 130 |
EndOfLine <- [\r\n] {incrlineno();} |
| 131 |
EndOfFile <- !. |
| 132 |
PCRE <- EscapedPCRE |
| 133 |
/ [^"\\] |
| 134 |
# FIXME: unescape char in yybuffer |
| 135 |
EscapedPCRE <- '\\' '\\' |
| 136 |
/ '\\' '"' |
| 137 |
|
| 138 |
|