Comments (11)
Seems reasonable but I do not want to use globals as it breaks multithreading. Let me mull over other options.
from ox.
Oh, I've meant that __line__
and __column__
are Ox::Sax
instance methods
from ox.
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.
Take a look at 1.9.0.
from ox.
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.
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 endHere 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.
Anyway, thanks for your great work!
from ox.
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.
I'll take a look today
from ox.
Works great!
Thank you very, very much for your great work!
from ox.
Thanks for finding bugs and for the suggestion.
from ox.
Related Issues (20)
- Various thoughts HOT 10
- Use "interned" (frozen and deduplicated) Strings in Ruby 3.0+ to minimize object allocations. HOT 3
- Become `Ractor`-safe to allow usage in non-main `Ractor`. HOT 1
- Bundle install failing HOT 7
- Parse error for comments containing special characters inside a DOCTYPE declaration HOT 1
- Single carriage return is not converted to line feed HOT 16
- Easy way to get backtrace information from the C extension? HOT 18
- Process XML with instructions longer than 1024 characters. HOT 9
- Ox 2.14.7 causes segfault HOT 14
- RESX XML parsing - support for xml:space="preserve" HOT 3
- Preserve newlines in attributes and bodies when parsing. HOT 2
- [BUG] Bus Error (crashes ruby when using more than 16458 characters in a field) HOT 5
- Request to include a new mode to load which prepends xml attributes with a given string or a default HOT 1
- Ox.load result changes after parsing specific xml. HOT 2
- Sax parser segfault in v2.14.7+ HOT 4
- `StringIO` in `Ox::Builder` HOT 2
- Sax parsing with default encoding set to UTF-8 breaks Ox::Sax#text HOT 2
- OpenSSL::SSL::SSLContext::DEFAULT_CERT_STORE is not shareable across ractors HOT 1
- Issue with gems on M1 that depends on ox HOT 3
- test/tests.rb fails with ruby3.2.0preview3 and onwards HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ox.