Class: TexLogParser::HighlightedMessages
- Inherits:
-
Object
- Object
- TexLogParser::HighlightedMessages
- 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
-
#initialize ⇒ HighlightedMessages
constructor
Creates a new instance.
-
#read(lines) ⇒ Array<(Message, Int)>
Reads a message from the given lines.
Methods included from LogParser::RegExpPattern
Methods included from LogParser::Pattern
Constructor Details
#initialize ⇒ HighlightedMessages
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.
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.) 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..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..gsub!(/^.*?For immediate help type.*$/, '') msg..gsub!(/^!\.+\s*$/, '') msg..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.) 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..gsub!(@end_match[0], '') end msg.preformatted = true msg..sub!(@start, '') msg..gsub!(/^#{Regexp.escape(@start_match[1][0])}\s+/, '') msg..strip! [msg, consumed] end |