GithubHelp home page GithubHelp logo

Comments (11)

ohler55 avatar ohler55 commented on September 28, 2024

Seems reasonable but I do not want to use globals as it breaks multithreading. Let me mull over other options.

from ox.

take-five avatar take-five commented on September 28, 2024

Oh, I've meant that __line__ and __column__ are Ox::Sax instance methods

from ox.

ohler55 avatar ohler55 commented on September 28, 2024

Still doesn't work as Ox::Sax is created by the user, not the parser. The handler does not have to inherit from that class either. I took a slight different approach. If the handler has an @line instance variable it is set before any callback. Same for @column. If there are no callback then they are not set and there is no overhead. Look for it in 1.9.0 later tonight.

from ox.

ohler55 avatar ohler55 commented on September 28, 2024

Take a look at 1.9.0.

from ox.

take-five avatar take-five commented on September 28, 2024

Wow, thanks for quick work!

Line numbers work absolutely correctly, but I do not completely understand, how column numbers are calculated.

Look:

<top name="sample">
  <middle name="second">
    <bottom name="third"/>
  </middle>
</top>
class Sample < ::Ox::Sax
  attr_reader :line, :column
  def initialize
    @line, @column = nil, nil
  end

  def start_element(name); puts "start: #{name.inspect} at #{line}:#{column}";        end
  def end_element(name);   puts "end: #{name.inspect} at #{line}:#{column}";          end
  def attr(name, value);   puts "  #{name.inspect} => #{value.inspect} at #{line}:#{column}"; end
  def text(value);         puts "text #{value.inspect} at #{line}:#{column}";         end
end

Here is the output:

start: :top at 1:6 # everything is clear here, we're at the beginning of "name" attribute
  :name => "sample" at 1:20
start: :middle at 2:12 # that's not clear to me, we're at the "a" letter of "name" attribute
  :name => "second" at 2:26
start: :bottom at 3:14
  :name => "third" at 3:27
end: :bottom at 3:29 # strange: third line is 27 chars length
end: :middle at 4:12
end: :top at 5:7

from ox.

ohler55 avatar ohler55 commented on September 28, 2024

Does seem off. It will be a couple of days before I can look at it though. Probably reading white space.

Alexey Mihaylov [email protected] wrote:

Wow, thanks for quick job!

Line numbers work absolutely correctly, but I do not completely
understand, how column numbers are calculated.

Look:

<top name="sample">
 <middle name="second">
   <bottom name="third"/>
 </middle>
</top>
class Sample < ::Ox::Sax
 attr_reader :line, :column
 def initialize
   @line, @column = nil, nil
 end

def start_element(name); puts "start: #{name.inspect} at
#{line}:#{column}";        end
def end_element(name);   puts "end: #{name.inspect} at
#{line}:#{column}";          end
def attr(name, value);   puts "  #{name.inspect} => #{value.inspect} at
#{line}:#{column}"; end
def text(value);         puts "text #{value.inspect} at
#{line}:#{column}";         end
end

Here is the output:

start: :top at 1:6 # everything is clear here, we're at the beginning
of "name" attribute
 :name => "sample" at 1:20
start: :middle at 2:12 # that's not clear to me, we're at the "a"
letter of "name" attribute
 :name => "second" at 2:26
start: :bottom at 3:14
 :name => "third" at 3:27
end: :bottom at 3:29 # strange: third line is 27 chars length
end: :middle at 4:12
end: :top at 5:7

Reply to this email directly or view it on GitHub:
#44 (comment)

from ox.

take-five avatar take-five commented on September 28, 2024

Anyway, thanks for your great work!

from ox.

ohler55 avatar ohler55 commented on September 28, 2024

Change the line numbers to be the start of each component and also fixed the bug of the column being too high in release 1.9.1.

from ox.

take-five avatar take-five commented on September 28, 2024

I'll take a look today

from ox.

take-five avatar take-five commented on September 28, 2024

Works great!

Thank you very, very much for your great work!

from ox.

ohler55 avatar ohler55 commented on September 28, 2024

Thanks for finding bugs and for the suggestion.

from ox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.