lib/textpow/syntax.rb in textpow1x-1.2.4 vs lib/textpow/syntax.rb in textpow1x-1.2.5

- old
+ new

@@ -88,21 +88,11 @@ def parse_and_store_syntax_info(table) table.each do |key, value| case key when "firstLineMatch", "foldingStartMarker", "foldingStopMarker", "match", "begin" - begin - regex = if Textpow::RUBY_19 - value.force_encoding("ASCII-8BIT") - Regexp.new(value) - else - Oniguruma::ORegexp.new(value, :options => Oniguruma::OPTION_CAPTURE_GROUP) - end - instance_variable_set("@#{key}", regex) - rescue RegexpError, ArgumentError => e - raise ParsingError, "Parsing error in #{value}: #{e.to_s}" - end + instance_variable_set("@#{key}", parse_regex(value)) when "content", "fileTypes", "name", "contentName", "end", "scopeName", "keyEquivalent" instance_variable_set("@#{key}", value) when "captures", "beginCaptures", "endCaptures" instance_variable_set("@#{key}", value.sort) when "repository" @@ -114,18 +104,38 @@ STDERR.puts "Ignoring: #{key} => #{value.gsub("\n", "\n>>")}" if $DEBUG end end end + def parse_regex(value) + if Textpow::RUBY_19 + parse_regex_with_invalid_chars(value) + else + Oniguruma::ORegexp.new(value, :options => Oniguruma::OPTION_CAPTURE_GROUP) + end + rescue RegexpError, ArgumentError => e + raise ParsingError, "Parsing error in #{value}: #{e.to_s}" + end + + def parse_regex_with_invalid_chars(value) + Regexp.new(value.force_encoding('UTF-8')) + rescue RegexpError => e + if e.message =~ /UTF-8/ or e.message =~ /invalid multibyte escape/ + puts "Ignored utf8 regex error #{$!}" + /INVALID_UTF8/ + else + raise e + end + end + # register in global syntax list -> can be found by include def register_in_syntaxes(scope) @@syntaxes[@name_space] ||= {} @@syntaxes[@name_space][scope] = self if scope end def self.convert_file_to_table(file) raise "File not found: #{file}" unless File.exist?(file) - case file when /(\.tmSyntax|\.plist)$/ require 'plist' Plist::parse_xml(file) else