Two fixes: 1. Hex string lexer now flushes dangling nibble when encountering invalid characters. For `<4X8Y>`, the X and Y are invalid, so we flush nibble 4 as 0x40, then flush nibble 8 as 0x80, producing `\x40\x80`. 2. Fixed skip_whitespace_and_comments() to properly handle whitespace after comments. The previous logic only continued looping if the next byte was `%`, missing cases where whitespace follows a comment. All 52 lexer tests pass. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
54 lines
1.2 KiB
Text
54 lines
1.2 KiB
Text
package pdftract
|
|
|
|
import "fmt"
|
|
|
|
// PdftractError is the base error type for all pdftract errors.
|
|
type PdftractError struct {
|
|
Message string
|
|
Stderr string
|
|
ExitCode int
|
|
}
|
|
|
|
func (e *PdftractError) Error() string {
|
|
if e.Stderr != "" {
|
|
return fmt.Sprintf("pdftract error (exit %d): %s", e.ExitCode, e.Stderr)
|
|
}
|
|
return e.Message
|
|
}
|
|
|
|
{% for error in errors %}
|
|
{% if error.exit_code != 0 and error.exit_code != 10 %}
|
|
// {{ error.exception_name }} represents {{ error.description }}.
|
|
type {{ error.exception_name }} struct {
|
|
Message string
|
|
Stderr string
|
|
ExitCode int
|
|
}
|
|
|
|
func (e *{{ error.exception_name }}) Error() string {
|
|
if e.Stderr != "" {
|
|
return fmt.Sprintf("{{ error.description }} (exit %d): %s", e.ExitCode, e.Stderr)
|
|
}
|
|
return e.Message
|
|
}
|
|
|
|
{% endif %}
|
|
{% endfor %}
|
|
{% for error in errors %}
|
|
{% if error.exit_code == 10 %}
|
|
// {{ error.exception_name }} represents {{ error.description }}.
|
|
type {{ error.exception_name }} struct {
|
|
Message string
|
|
Stderr string
|
|
ExitCode int
|
|
}
|
|
|
|
func (e *{{ error.exception_name }}) Error() string {
|
|
if e.Stderr != "" {
|
|
return fmt.Sprintf("{{ error.description }} (exit %d): %s", e.ExitCode, e.Stderr)
|
|
}
|
|
return e.Message
|
|
}
|
|
|
|
{% endif %}
|
|
{% endfor %}
|