Giter Club home page Giter Club logo

Comments (9)

dabeaz avatar dabeaz commented on August 22, 2024 1

The calc grammar is not going to accept an input of "//comment" because it does not recognize an empty input---there has to be an expression. If you want the grammar to accept empty input, then there has to be a grammar rule for it (otherwise a syntax error will occur).

from ply.

dabeaz avatar dabeaz commented on August 22, 2024

Is the comment supposed to consume the trailing newline character or not? If so, maybe the regex needs to include it. For example r'#.*\n'

from ply.

5nizza avatar 5nizza commented on August 22, 2024

Yep, you are right, with \n of course (or excluding \n): r"""[#][^\n]*"""
But the result remains the same - the same Stacktrace.

from ply.

dabeaz avatar dabeaz commented on August 22, 2024

The p_error() function is called with an argument of None when there's a syntax error involving the end of file. The traceback message is being caused by not checking for this. See ply/example/calc/calc.py for an example.

from ply.

5nizza avatar 5nizza commented on August 22, 2024

Still does not ignore the comments and calls p_error instead. The same if provide ' ' as input. Also tried with t_ignore_comment = r'//.*' instead of defining new function -- the same result: it does not ignore comments and pure spaces (wo numbers) and treat them as syntax errors.

from ply.

5nizza avatar 5nizza commented on August 22, 2024

I think I found the workaround/reason. Consider the example of calc.py after adding t_ignore_comment = r'//.*':
it parses: "1+2", "1+2\n//comment", "//comment\n1+2" (that is, as expected it Ply ignores the comments and parses the expression)

But Ply cannot parse "//comment", that is the sentence without an expression in it.
Not a major issue, therefore.
Thanks.

from ply.

5nizza avatar 5nizza commented on August 22, 2024

After adding empty rule it works now! Thanks!

from ply.

Joshua195 avatar Joshua195 commented on August 22, 2024

@5nizza For multilinea comments how can I do it? I have this but it does not work
t_ignore_multi_comment = r'/*(.|\r|\n)?*[\n]?/'

from ply.

yjjnls avatar yjjnls commented on August 22, 2024

@5nizza For multilinea comments how can I do it? I have this but it does not work
t_ignore_multi_comment = r'/(.|\r|\n)_?[\n]_?/'

r'(/\*(.|\n)*?\*/)|(//.*)'
@Joshua195

from ply.

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.