Class: TexLogParser::PrefixedMultiLinePattern

Inherits:
Object
  • Object
show all
Includes:
LogParser::RegExpPattern
Defined in:
lib/tex_log_parser/patterns/prefixed_multi_line_pattern.rb

Overview

Matches messages of this form:

Package tocbasic Info: omitting babel extension for `toc'
(tocbasic)             because of feature `nobabel' available
(tocbasic)             for `toc' on input line 132.

Note: Fails to pick up the fill message if lines get broken badly, e.g. in ‘000_pdf_fl.log:634`.

Instance Method Summary collapse

Methods included from LogParser::RegExpPattern

#begins_at?

Methods included from LogParser::Pattern

#begins_at?

Constructor Details

#initializePrefixedMultiLinePattern

Creates a new instance.

[View source]

15
16
17
18
19
20
# File 'lib/tex_log_parser/patterns/prefixed_multi_line_pattern.rb', line 15

def initialize
  super(/(Package|Class|\w+TeX)\s+(?:(\w+)\s+)?(Warning|Error|Info|Message)/,
        { pattern: ->(m) { /^\s*\(#{m[2]}\)/ }, # BROKEN_BY_LINEBREAKS
          until: :mismatch,
          inclusive: false })
end

Instance Method Details

#read(lines) ⇒ Array<(Message, Int)>

Reads a message from the given lines.

Parameters:

Returns:

  • (Array<(Message, Int)>)

    An array of the message that was read, and the number of lines that it spans.

Raises:

  • If no message end could be found among the given lines.

[View source]

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/tex_log_parser/patterns/prefixed_multi_line_pattern.rb', line 23

def read(lines)
  # @type [Message] msg
  # @type [Int] consumed
  msg, consumed = super(lines)

  case @start_match[3]
  when 'Error'
    msg.level = :error
  when 'Warning'
    msg.level = :warning
  when 'Info', 'Message'
    msg.level = :info
  else
    # TODO: abort?
    Logger.debug 'Unhandled message type!'
  end

  # source file from scope, parser does it

  # BROKEN_BY_LINEBREAKS
  # TODO: may be split across lines --> remove whitespace before extracting
  suffix_match = /on input line\s+(\d+)(?:\.\s*)?\z/.match(msg.message)
  unless suffix_match.nil?
    line = suffix_match[1].to_i
    msg.source_lines = { from: line, to: line }
  end

  # Remove uninformative line prefixes (e.g. `(tocbasic)`)
  unless @start_match[2].nil?
    msg.message.gsub!(@ending[:pattern][@start_match], ' ' * (@start_match[2].length + 2))
  end

  [msg, consumed]
end