GithubHelp home page GithubHelp logo

indentation parsing doesn't work about eo HOT 14 CLOSED

yegor256 avatar yegor256 commented on August 16, 2024
indentation parsing doesn't work

from eo.

Comments (14)

alexpanov avatar alexpanov commented on August 16, 2024 1

@yegor256 do you think there needs to be a vote about that too? ;)

from eo.

g4s8 avatar g4s8 commented on August 16, 2024 1

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.

martinstraus avatar martinstraus commented on August 16, 2024 1

Identation is required? That's nasty.

from eo.

Tertioptus avatar Tertioptus commented on August 16, 2024

why white-space parsing anyway?

from eo.

yegor256 avatar yegor256 commented on August 16, 2024

@Tertioptus it's compact and effective

from eo.

g4s8 avatar g4s8 commented on August 16, 2024

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.

stain avatar stain commented on August 16, 2024

I think https://github.com/yshavit/antlr-denter can do it for the reference implementation using antlr.

from eo.

yegor256 avatar yegor256 commented on August 16, 2024

@stain many thanks for the antlr-denter link. Let's use it! Can you submit a pull request?

from eo.

stain avatar stain commented on August 16, 2024

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.

stain avatar stain commented on August 16, 2024

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.

jachinte avatar jachinte commented on August 16, 2024

@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.

pchmielowski avatar pchmielowski commented on August 16, 2024

@g4s8 I think, you should create a pull request and we'll review and discus it

from eo.

yegor256 avatar yegor256 commented on August 16, 2024

fixed, thanks all

from eo.

0pdd avatar 0pdd commented on August 16, 2024

@yegor256 all 6 puzzles are solved here: #104, #105, #106, #129, #131, #95.

from eo.

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.