Giter Site home page Giter Site logo

Comments (5)

whitten avatar whitten commented on July 17, 2024

I understand that you expect that the error message should be presented.
Is there something in the language standard or spec that supports your view
?

On Mon, Jan 12, 2015 at 8:27 AM, maiermic [email protected] wrote:

input:

def func():
return 42

parser reports:
no error
expected:
An error message that indent before function definition is
unexpected/extraneous.


Reply to this email directly or view it on GitHub
#133.

from grammars-v4.

maiermic avatar maiermic commented on July 17, 2024

I ran my example on the command line (Python 3.4.0):

$ python my-example.py
  File "my-example.py", line 1
    def func():
    ^
IndentationError: unexpected indent

from grammars-v4.

whitten avatar whitten commented on July 17, 2024

Is Python on the command line considered to be the reference server for
Python?
( I'm really asking because I don't know. I have no dog in this fight.)

I DO know making a grammar that is whitespace aware is harder than making
one
that ignores whitespace. This is probably going to require some tweaking of
the grammar,
possibly even intentionally putting a rule in to generate the error.

David

On Mon, Jan 12, 2015 at 9:48 AM, maiermic [email protected] wrote:

I ran my example on the command line (Python 3.4.0):

$ python my-example.py
File "my-example.py", line 1
def func():
^IndentationError: unexpected indent


Reply to this email directly or view it on GitHub
#133 (comment).

from grammars-v4.

bkiers avatar bkiers commented on July 17, 2024

When looking at the rule that is responsible for the creation of INDENT tokens, the NEWLINE rule, you can see that INDENT tokens are only created when the lexer "sees" a line break. Fixing it in the grammar would mean to use a predicate to check if we're at the start of the input stream followed by one or more spaces.

At the moment it looks like:

NEWLINE
 : ( '\r'? '\n' | '\r' ) SPACES?
   {
     ...
   }
 ;

and should be:

NEWLINE
 : ( {atStartOfInput()}? SPACES
   | ( '\r'? '\n' | '\r' ) SPACES?
   )
   {
     ...
   }
 ;

where atStartOfInput() would look likt his:

boolean atStartOfInput() {
  return super.getCharPositionInLine() == 0 && super.getLine() == 1;
}

Will make a PR later this day.

from grammars-v4.

bkiers avatar bkiers commented on July 17, 2024

I suppose this can be closed @parrt

from grammars-v4.

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.