Code Monkey home page Code Monkey logo

Comments (6)

chriswailes avatar chriswailes commented on September 26, 2024

Thanks for the issue report. I'll try and get to this, and the other issues, this week.

from rltk.

codella avatar codella commented on September 26, 2024

@chriswailes this should fix the issue #39.

Would be nice to have this tested, QAd and merged asap, so we can rely on a more reliable line_offset :)

from rltk.

chriswailes avatar chriswailes commented on September 26, 2024

I merged the pull request, but it didn't seem to be related to this issue. I was unable to reproduce the initial problem. Here is the code I was using:

require 'rltk'

class TestLexer < RLTK::Lexer
     rule(/\s/)
     rule(/a/) { :A }
end

begin
     TestLexer.lex('   aaab')
rescue RLTK::LexingError => e
     puts e.message
     puts "Line number: #{e.line_number}"
     puts "Line offset: #{e.line_offset}"
end

This code correctly reports the offending character's offset as 6.

Output:

Unable to match string with any of the given rules: b
Line number: 1
Line offset: 6

from rltk.

codella avatar codella commented on September 26, 2024

Sorry, I reported a very bad example - got confused myself :/ I'll take another chance to show you that the problem was there and now it's gone. Take the following code (inspired by yours):

require 'rltk'

class TestLexer < RLTK::Lexer
  rule(/a/) { :A }
  rule(/[^ab]+/m) { :OTHER }
end

def lex(input)
  puts ">> Parsing #{input.inspect}..."
  TestLexer.lex(input)
rescue RLTK::LexingError => e
  puts e.message
  puts "Line number: #{e.line_number}"
  puts "Line offset: #{e.line_offset}"
end

lex("   \n\naaab")
puts "-" * 20
lex("   \n\n        aaab")

Output with RLTK 3.0.0

The output we get for the second string shows a wrong line_offset (3)...

>> Parsing "   \n\naaab"...
Unable to match string with any of the given rules: b
Line number: 3
Line offset: 3
--------------------
>> Parsing "   \n\n        aaab"...
Unable to match string with any of the given rules: b
Line number: 3
Line offset: 3

Output with RLTK 3.0.1

The output we get for the second string has a correct line_offset (11)...

>> Parsing "   \n\naaab"...
Unable to match string with any of the given rules: b
Line number: 3
Line offset: 3
--------------------
>> Parsing "   \n\n        aaab"...
Unable to match string with any of the given rules: b
Line number: 3
Line offset: 11

from rltk.

codella avatar codella commented on September 26, 2024

@chriswailes ^^^^ :^)

from rltk.

chriswailes avatar chriswailes commented on September 26, 2024

I was definitely convinced that your patch fixed a problem; I just wanted to make sure it fixed this problem as well :-)

from rltk.

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.