"checkit_tiff" is an incredibly fast conformance checker for baseline TIFFs (with various extensions), see http://andreas-romeyke.de
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
12KB

  1. # rule based checks if given TIFF is a specific baseline TIFF
  2. #
  3. # author: Andreas Romeyke, 2015/2016
  4. # licensed under conditions of libtiff
  5. # (see http://libtiff.maptools.org/misc.html)
  6. #
  7. start <- ( Line )+ EndOfFile
  8. Line <- CommentLine EndOfLine
  9. / SpaceLine EndOfLine
  10. / ModeLine EndOfLine
  11. / IncludeLine EndOfLine
  12. / TagLine EndOfLine
  13. / < MiscUntilEOL > { set_parse_error("wrong line entry",yytext); }
  14. CommentLine <- '#' ( !EndOfLine . )* { commentline(); }
  15. IncludeLine <- 'include' OpenBracket < ( [A-Za-z0-9_./\-]+ ) > ClosingBracket { set_include ( yytext ); }
  16. ModeLine <- 'mode' OpenBracket < Mode > ClosingBracket { int i = i_pop(); set_mode( i ); }
  17. / 'mode' OpenBracket Mode { set_parse_error( "modeline expects a closing bracket", yytext); }
  18. / 'mode' OpenBracket { set_parse_error( "modeline requires a mode", yytext); }
  19. / 'mode' { set_parse_error( "modeline requires an open bracket", yytext); }
  20. LogicalOr <- 'logical_or' OpenBracket LogicalOrList ClosingBracket { rule_add_logical_config(); reset_logical_list();}
  21. LogicalOrListElement <- Any { v_push( any );incr_logical_elements(); }
  22. / Range { v_push( range);incr_logical_elements(); }
  23. / Only { v_push( only );incr_logical_elements(); }
  24. / Number { v_push( only );incr_logical_elements(); }
  25. / NTupel { v_push( ntupel); reset_valuelist(); incr_logical_elements(); }
  26. / RegEx { v_push( regex );incr_logical_elements(); }
  27. / PrintableAscii { v_push( printable_ascii );incr_logical_elements(); }
  28. / < MiscUntilEOL > { set_parse_error("wrong values-keyword", yytext);}
  29. LogicalOrList <- LogicalOrListElement (Colon LogicalOrListElement)*
  30. Mode <- 'baseline' { i_push(mode_baseline ); }
  31. / 'enable_type_checks' { i_push(mode_enable_type_checks); }
  32. / 'enable_offset_checks' { i_push(mode_enable_offset_checks); }
  33. / 'enable_ifd_checks' { i_push(mode_enable_ifd_checks); }
  34. / 'enhanced' #/* TODO: later if all types of TIFF are supported */
  35. / MiscUntilEOL { set_parse_error("mode expects either 'baseline' or 'enhanced'", yytext); }
  36. TagLine <- Tag Semicolon Requirements Semicolon Content { rule_addtag_config(); }
  37. / Tag Semicolon Requirements Semicolon { set_parse_error("tagline requires content", yytext); }
  38. / Tag Semicolon Requirements { set_parse_error("tagline expects missed semicolon here", yytext); }
  39. / Tag Semicolon { set_parse_error("tagline requires a requiemrent-keyword (mandatory, etc.)",yytext); }
  40. / Tag { set_parse_error("tagline expects missed semicolon here", yytext); }
  41. Tag <- < Number > {
  42. int tag = i_pop();
  43. /* rule_tagorder_in_dsl( tag ); */
  44. if (tag < 254) set_parse_error("wrong tag (should be >253)", yytext);
  45. else if (tag > 65535) set_parse_error("wrong tag (should be <65536)", yytext);
  46. else settag( tag );
  47. }
  48. TagReference <- < Number > {
  49. int tag = i_pop();
  50. if (tag < 254) set_parse_error("wrong tagreference (should be >253)", yytext);
  51. else if (tag > 65535) set_parse_error("wrong tagreference (should be <65536)", yytext);
  52. else settagref( tag );
  53. }
  54. / < MiscUntilEOL > { set_parse_error("wrong tagreference", yytext); }
  55. Semicolon <- ';' ( Space )*
  56. / < MiscUntilEOL > { set_parse_error("missed semicolon", yytext);}
  57. Requirements <- 'mandatory' { set_mandatory(); }
  58. / IfDepends { set_ifdepends(); }
  59. / OptDepends { set_optdepends(); }
  60. / 'optional' { set_optional(); }
  61. / < MiscUntilEOL > { set_parse_error("wrong requirements-keyword", yytext);}
  62. IfDepends <- 'depends' OpenBracket TagReference Dot ValueReference ClosingBracket
  63. / 'depends' OpenBracket TagReference Dot ValueReference { set_parse_error("'depends' expects a closing bracket", yytext); }
  64. / 'depends' OpenBracket TagReference Dot { set_parse_error("'depends' expects a value reference", yytext); }
  65. / 'depends' OpenBracket TagReference { set_parse_error("'depends' expects a dot", yytext); }
  66. / 'depends' OpenBracket { set_parse_error("'depends' expects a tagreference", yytext); }
  67. / 'depends' { set_parse_error("'depends' expects an open bracket", yytext); }
  68. OptDepends <- 'optdepends' OpenBracket TagReference Dot ValueReference ClosingBracket
  69. / 'optdepends' OpenBracket TagReference Dot ValueReference { set_parse_error("'optdepends' expects a closing bracket", yytext); }
  70. / 'optdepends' OpenBracket TagReference Dot { set_parse_error("'optdepends' expects a value reference", yytext); }
  71. / 'optdepends' OpenBracket TagReference { set_parse_error("'optdepends' expects a dot", yytext); }
  72. / 'optdepends' OpenBracket { set_parse_error("'optdepends' expects a tagreference", yytext); }
  73. / 'optdepends' { set_parse_error("'optdepends' expects an open bracket", yytext); }
  74. Content <- Any { v_push( any ); }
  75. / Range { v_push( range); }
  76. / LogicalOr
  77. / Only { v_push( only ); }
  78. / NTupel { v_push( ntupel ); reset_valuelist() }
  79. / RegEx { v_push( regex ); }
  80. / PrintableAscii { v_push( printable_ascii ); }
  81. / Datetime { v_push( datetime ); }
  82. / Iccprofile { v_push( iccprofile ); }
  83. # / SBit { v_push( sbit ); }
  84. / < MiscUntilEOL > { set_parse_error("wrong values-keyword", yytext);}
  85. Range <- 'range' OpenBracket Number Colon Number ClosingBracket
  86. / 'range' OpenBracket Number Colon Number { set_parse_error("'range' expects a closing bracket", yytext); }
  87. / 'range' OpenBracket Number Colon { set_parse_error("'range' expects a number", yytext); }
  88. / 'range' OpenBracket Number { set_parse_error("'range' expects a colon", yytext); }
  89. / 'range' OpenBracket { set_parse_error("'range' expects a number", yytext); }
  90. / 'range' { set_parse_error("'range' expects an open bracket", yytext); }
  91. Number <- < '0x' ( [0-9a-f]+ ) > { i_push(strtol(yytext, NULL, 0) ); }
  92. / '2^' < ( Digit )+ > { i_push(2<<atol(yytext) ); }
  93. / < ( Digit )+ > { i_push(atol(yytext) );}
  94. Colon <- ',' (Space )*
  95. / < MiscUntilEOL > { set_parse_error("missed colon", yytext);}
  96. Dot <- '.' (Space )*
  97. / < MiscUntilEOL > { set_parse_error("missed dot", yytext)}
  98. OpenBracket <- '('
  99. ClosingBracket <- ')'
  100. ValueList <- Value (Colon Value)*
  101. Value <- Number { incr_values(); }
  102. NTupel <- 'ntupel' OpenBracket ValueList ClosingBracket {int v=parser_state.valuelist; i_push(v); reset_valuelist(); }
  103. / 'ntupel' OpenBracket ValueList { set_parse_error("'ntupel' expects a closing bracket", yytext);}
  104. / 'ntupel' OpenBracket { set_parse_error("'ntupel' expects a value list", yytext);}
  105. / 'ntupel' { set_parse_error("'ntupel' expects an open bracket", yytext);}
  106. ValueReference <- Any { parser_state.any_reference = any_ref; }
  107. / Number { parser_state.any_reference = only_ref; i_push(atol(yytext) );}
  108. / RegEx { parser_state.any_reference = regex_ref; }
  109. / Range { parser_state.any_reference = range_ref; }
  110. / NTupel { parser_state.any_reference = ntupel_ref; }
  111. / Only { parser_state.any_reference = only_ref; }
  112. / < MiscUntilEOL > { set_parse_error("value reference error: '%s'", yytext);}
  113. Only <- 'only' OpenBracket Number ClosingBracket { }
  114. / 'only' OpenBracket Number { set_parse_error("'only' expects a closing bracket", yytext);}
  115. / 'only' OpenBracket { set_parse_error("'only' expects a value list", yytext);}
  116. / 'only' { set_parse_error("'only' expects an open bracket", yytext);}
  117. #SBit <- 'sbit' OpenBracket < Digit > ClosingBracket{ i_push(atol(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. / 'regex' OpenBracket '"' < ( PCRE )* > '"' { set_parse_error("'regex' expects a closing bracket", yytext); }
  123. / 'regex' OpenBracket '"' < ( PCRE )* > { set_parse_error("'regex' expects a closing '\"'", yytext); }
  124. / 'regex' OpenBracket '"' { set_parse_error("'regex' expects a PCRE-regex", yytext); }
  125. / 'regex' OpenBracket { set_parse_error("'regex' expects an open '\"'", yytext); }
  126. / 'regex' { set_parse_error("'regex' expects an open bracket", yytext); }
  127. Datetime <- 'datetime'
  128. Iccprofile <- 'iccprofile'
  129. PrintableAscii <- 'printascii'
  130. SpaceLine <- ( Space )*
  131. Space <- ' ' / '\t'
  132. Any <- 'any'
  133. Digit <- [0-9]
  134. EndOfLine <- [\r\n] {incrlineno(); }
  135. EndOfFile <- !.
  136. MiscUntilEOL <- [^\r\n]+
  137. PCRE <- EscapedPCRE
  138. / [^"\\]
  139. # FIXME: unescape char in yybuffer
  140. EscapedPCRE <- '\\' '\\'
  141. / '\\' '"'