Comments (14)
@yegor256 do you think there needs to be a vote about that too? ;)
from eo.
I've adapted python indentation parser (from @jachinte comment) for EO grammar.
Does anyone want to review it? I'm not familiar with ANTLR, so I can make a mistake. Just want to try EO at the earliest moment.
from eo.
Identation is required? That's nasty.
from eo.
why white-space parsing anyway?
from eo.
@Tertioptus it's compact and effective
from eo.
it's compact and effective
Furthermore, it's a necessary feature.
Without indentation parsing we can't understand method (or ctor) to pass argument in some cases.
E.g. if we have two objects:
object one as String:
String @s1
String @s2
ctor(String s)
one(s, "")
ctor(String s1, String s2)
String string():
concat s1, s2
object two as String:
String @s1
String @s2
ctor(String s)
one(s, "")
ctor(String s1, String s2)
String string():
concat s2, s1
this code
print:
one:
two:
"A",
"B"
can be interpreted in a two ways: one(two("A", "B"))
and one(two("A"), "B")
and return "AB" or "BA".
from eo.
I think https://github.com/yshavit/antlr-denter can do it for the reference implementation using antlr.
from eo.
@stain many thanks for the antlr-denter link. Let's use it! Can you submit a pull request?
from eo.
I can have a look at using antlr-denter, but not until the weekend I'm afraid :-(
It is much harder to write a regular grammar without block end characters - I tried to make some lookehad rules but couldn't get it quite to work - perhaps too late at night..
(To summarize: My idea was to make a lookahead rule to consume space on either end of a line:
NEWLINE = '\r\n' | '\n'
SPACE = ' '
indent = <SPACE> <SPACE>
morestatements = <indent> #"[^\n]*" <NEWLINE> statements)
and then use this as a positive and negative lookahead in the actual recursive rule statements
:
statement = object | number | string | etc
statements = ((&(morestatements) <indent> statement <NEWLINE> <indent> statements)) |
(!(morestatements) <indent> statement <NEWLINE>)
The theory would be that statements
would require recursion if there's equivalent space on the next line, or require non-recursion (no more statements) if there isn't equivalent space.
But to do this in a forward-looking grammar without too much trickery we would have to:
- Insist on a fixed indentation pattern (e.g. two spaces)
- Not allow non-indented comments within a block
- Always/never use newline in various patterns (e.g. after
:
)
Doing this I see why many languages like Java use {
and }
together with ;
- it makes it easier to write a simple grammar. But I don't think having a simple grammar is a good requirement for "eo" - as long as we don't end up with weird workarounds in the syntax (e.g. a series indented newlines as substitutes for }
!)
from eo.
My naive whitespace-agnostic grammar found 7 alternative interpretation of @g4s8's example with print: one: two: "A", "B"
-- "B"
can be an argument for print
, one
or two
-- and in addition both one
and two
could be consider top-level objects or an argument. If we had a more traditional ()
or {}
block for constructor it shouldn't be a problem.
Let's not forget the "no syntactic sugar" mantra -- lack of block characters is in a way also syntactic sugar..
from eo.
@stain I think it would be syntactic sugar if removing those characters was part of an alternative syntax, that is, the eo language supports {
and }
to define block scopes, but a new syntax allows indentation-based scopes.
As you are using Antlr, my first suggestion is to look at the python grammar in the Antlr repository. This StackOverflow question can also give you some insights.
from eo.
@g4s8 I think, you should create a pull request and we'll review and discus it
from eo.
fixed, thanks all
from eo.
@yegor256 all 6 puzzles are solved here: #104, #105, #106, #129, #131, #95.
from eo.
Related Issues (20)
- merge smaller libs into this repo HOT 7
- Printing PHI Expressions Extremely Slow HOT 4
- list.eo:208-211: The object does not work. After moving... HOT 2
- PhPackage need update HOT 2
- BytesRaw.java:33-36: Method {@link BytesOf#shift} should... HOT 2
- align-test-classes.xsl:27-28: Add link to corresponding... HOT 2
- remove-high-level-inner-classes.xsl:27-28: Create... HOT 14
- map.eo:105-112: Find a way to link hash code and index of... HOT 2
- text.eo:313-315: Implement text.replaced object. This... HOT 3
- Replace `int` and `float` with `number` HOT 1
- `eo-maven-plugin` allows attributes without names in an abstract object HOT 10
- Dataized.java:54-57: It is necessary to call {@link... HOT 2
- Dataized.java:64-67: It is necessary to call {@link... HOT 2
- PhDefault.java:65-68: It is necessary to call {@link... HOT 2
- PhTraced.java:50-53: It is necessary to call {@link... HOT 2
- Too many nested function calls HOT 9
- `xmir-to-phi` doesn't check PHI labels HOT 2
- Unable to compile "Hello World" program from README HOT 13
- Can't print simple string HOT 6
- XMIR representation of an alias? HOT 4
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 eo.