lib/ebnf/writer.rb in ebnf-2.3.1 vs lib/ebnf/writer.rb in ebnf-2.3.2

- old
+ new

@@ -179,12 +179,13 @@ html_result = eruby.evaluate(format: format, rules: formatted_rules) if validate begin + require 'nokogiri' # Validate the output HTML - doc = Nokogiri::HTML5("<!DOCTYPE html>" + html_result, max_errors: 10) + doc = ::Nokogiri::HTML5("<!DOCTYPE html>" + html_result, max_errors: 10) raise EncodingError, "Errors found in generated HTML:\n " + doc.errors.map(&:to_s).join("\n ") unless doc.errors.empty? rescue LoadError, NoMethodError # Skip end @@ -405,18 +406,18 @@ seq = segments.inject([]) {|memo, s| memo.concat([[:hex, "#x22"], s])}[1..-1] seq.unshift(:seq) return format_abnf(seq, sep: nil, embedded: false) else - return (@options[:html] ? %("<code class="grammar-literal">#{'%s' if sensitive}#{@coder.encode expr}</code>") : %(#{'%s' if sensitive}"#{expr}")) + return (@options[:html] ? %("<code class="grammar-literal">#{@coder.encode expr}</code>") : %("#{expr}")) end end parts = { - alt: (@options[:html] ? "<code>/</code> " : "/ "), - star: (@options[:html] ? "<code>*</code> " : "*"), - plus: (@options[:html] ? "<code>+</code> " : "1*"), - opt: (@options[:html] ? "<code>?</code> " : "?") + alt: (@options[:html] ? "<code>/</code>" : "/ "), + star: (@options[:html] ? "<code>*</code>" : "*"), + plus: (@options[:html] ? "<code>+</code>" : "1*"), + opt: (@options[:html] ? "<code>?</code>" : "?") } lbrac = (@options[:html] ? "<code>[</code> " : "[") rbrac = (@options[:html] ? "<code>]</code> " : "]") lparen = (@options[:html] ? "<code>(</code> " : "(") rparen = (@options[:html] ? "<code>)</code> " : ")") @@ -462,10 +463,12 @@ "#{min}#{r}" elsif min == 0 && max == '*' "#{parts[:star]}#{r}" elsif min > 0 && max == '*' "#{min}#{parts[:star]}#{r}" + elsif min == 0 + "#{parts[:star]}#{max}#{r}" else "#{min}#{parts[:star]}#{max}#{r}" end else raise "Unknown operator: #{expr.first}" @@ -501,10 +504,11 @@ while !scanner.eos? if hex = scanner.scan(Terminals::HEX) # Append any decimal values alt << "%d" + deces.join(".") unless deces.empty? deces = [] + hex = hex.upcase if in_range # Add "." sequences for any previous hexes alt << "%x" + hexes[0..-2].join(".") if hexes.length > 1 alt << "%x#{hexes.last}-#{hex[2..-1]}" @@ -550,10 +554,10 @@ fmt = case u.ord when 0x0000..0x00ff then "%02X" when 0x0100..0xffff then "%04X" else "%08X" end - char = "%x" + (fmt % u.ord) + char = "%x" + (fmt % u.ord).upcase if @options[:html] if u.ord <= 0x20 char = %(<abbr title="#{ASCII_ESCAPE_NAMES[u.ord]}">#{@coder.encode char}</abbr>) elsif u.ord == 0x22 %(<abbr title="quot">>&quot;</abbr>)