Comments (5)
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 42parser 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.
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.
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.
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.
I suppose this can be closed @parrt
from grammars-v4.
Related Issues (20)
- PL/SQL parser cannot recognise record field with keyword HOT 1
- [cpp] Add Antlr4ng port for the CPP grammar HOT 1
- [php] Port the php grammar to Antlr4ng
- [php] examples/strings.php has a BOM--files cannot have BOM!! HOT 1
- [scala] Numerous errors in the grammar
- [BigQuery] - why not support BigQuery
- Problems with SQL reformatting HOT 2
- Support for Dart3 Version HOT 1
- new Grammer HOT 3
- Errors running C++ and C# lexers HOT 2
- [javascript] parser is too greedy for some new expressions
- [build] Builds are using old version of Antlr4BuildTasks, builds fail
- sql/plsql alter_table accepts emply alternative
- [PL/SQL] SQL functions misplaced in parser definition? HOT 1
- Fortran 90 parser emits Syntax Error on valid Fortran with no spaces around logic operator HOT 7
- Fortran 90: add common extensions HOT 4
- Java 20: Strange naming of some concepts in Parser
- [csharp grammar] CSharp and Java producing different error messages for expected tokens HOT 1
- Fortran f90 grammar: problems parsing END SELECT HOT 8
- [fortran] Add latest Fortran grammar, addressing issues in older versions HOT 14
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 grammars-v4.