Class: TexLogParser::HighlightedMessages

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

Overview

Matches messages as produces by LaTeX 3, i.e. those of these forms:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
./plain.tex:5: fontspec error: "font-not-found"
!
! The font "NoSuchFont" cannot be found.
!
! See the fontspec documentation for further information.
!
! For immediate help type H <return>.
!...............................................

l.5 \setmainfont{NoSuchFont}

and

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! fontspec error: "font-not-found"
!
! The font "NoSuchFont" cannot be found.
!
! See the fontspec documentation for further information.
!
! For immediate help type H <return>.
!...............................................

l.5 \setmainfont{NoSuchFont}

and

.................................................
. LaTeX info: "xparse/define-command"
.
. Defining command \fontspec with sig. 'O{}mO{}' on line 472.
.................................................

and

*************************************************
* widows-and-orphans warning: "orphan-widow"
*
* Orphan on page 1 (second column) and widow on page 2 (first column)
*************************************************

Instance Method Summary collapse

Methods included from LogParser::RegExpPattern

#begins_at?

Methods included from LogParser::Pattern

#begins_at?

Constructor Details

#initializeHighlightedMessages

Creates a new instance.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/tex_log_parser/patterns/highlighted_messages.rb', line 53

def initialize
  super(/^(!{3,}|\.{3,}|\*{3,})$/,
        { pattern: lambda { |m|
                     case m[1][0]
                     when '!'
                       /^l\.(\d+)/
                     when '*'
                       /^\*{3,}\s*$/
                     when '.'
                       /^\.{3,}\s*$/
                     else
                       raise("Expected one of `[!.*]` but found: #{m[1][0]}")
                     end
                   },
          until: :match,
          inclusive: true })
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.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/tex_log_parser/patterns/highlighted_messages.rb', line 72

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

  is_error = @start_match[1][0] == '!'

  if is_error
    file_line_match = %r{^(/?(?:.*?/)*[^/]+):(\d+):\s*}.match(msg.message)
    line = nil
    if !file_line_match.nil? # if file-line active
      msg.source_file = file_line_match[1]
      line = file_line_match[2].to_i
      msg.message.gsub!(file_line_match[0], '')
    elsif !@end_match[1].nil?
      # No file-line format, so use line number from end match
      line = @end_match[1].to_i
    end
    msg.source_lines = { from: line, to: line } unless line.nil?

    msg.level = :error

    msg.message.gsub!(/^.*?For immediate help type.*$/, '')
    msg.message.gsub!(/^!\.+\s*$/, '')
    msg.message.gsub!(/^l\.\d+\s+.*$/, '')
  else
    # BROKEN_BY_LINEBREAKS
    # TODO: may be split across lines --> remove whitespace before extracting
    line_match = /on line\s+(\d+)\.$/.match(msg.message)
    unless line_match.nil?
      line = line_match[1].to_i
      msg.source_lines = { from: line, to: line }
    end

    msg.level = @start_match[1][0] == '*' ? :warning : :info

    msg.message.gsub!(@end_match[0], '')
  end

  msg.preformatted = true
  msg.message.sub!(@start, '')
  msg.message.gsub!(/^#{Regexp.escape(@start_match[1][0])}\s+/, '')
  msg.message.strip!

  [msg, consumed]
end