Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement 'is parsed' #177

Open
masak opened this issue Aug 17, 2016 · 9 comments
Open

Implement 'is parsed' #177

masak opened this issue Aug 17, 2016 · 9 comments

Comments

@masak
Copy link
Owner

masak commented Aug 17, 2016

Behind a feature flag.

The minimum viable feature would be enough to close this issue.

@masak
Copy link
Owner Author

masak commented Aug 17, 2016

Blocking on #174.

@vendethiel
Copy link
Collaborator

vendethiel commented Aug 18, 2016

should is parsed actually take an argument as to which category it is?

example:

sub foo() is parsed(/a+/):term {

}

sub bar() is parsed(/ <EXPR> if <EXPR>/):statement {
}

(yes, I know, 007 doesn't have adverbs. Doesn't really matter)

@masak
Copy link
Owner Author

masak commented Aug 18, 2016

The category information, for better or worse, goes on the name of the identifier:

macro infix:<?>(lhs, rhs) is parsed(/"?" <.ws> ["wooga" <.ws>]* "?"/) {
    return quasi { {{{lhs}}} + {{{rhs}}} };
}
say(1 ? wooga wooga wooga wooga ? 7);        # 8

macro statement:<next>() is parsed(/"next" <.ws> <identifier>?/) { ... }

Currently leaning towards not allowing is parsed on subs, simply because subs are very runtime-y, can be passed around the program, etc. This feels incompatible with statically knowable compile-time textual information. In a way, the strength of subs as first-class citizens also damns them as something that can't be is parsed realiably.

@vendethiel
Copy link
Collaborator

When you pass a sub as an argument (etc), the name changes. Which is really what makes this be.

I think it makes sense that is parsed really binds to that name. Just like my &a = infix:<~>; gives you a function without any special syntax on top. (and this goes back to sub a(infix:<+>) {3 + 4}, i.e. sub a(x is parsed...) {}, mmh...)

@masak
Copy link
Owner Author

masak commented Aug 21, 2016

No longer blocking on #174, seeing as we have regexes now. 🎉

@masak
Copy link
Owner Author

masak commented Aug 21, 2016

When you pass a sub as an argument (etc), the name changes. Which is really what makes this be.

I think it makes sense that is parsed really binds to that name. Just like my &a = infix:<~>; gives you a function without any special syntax on top. (and this goes back to sub a(infix:<+>) {3 + 4}, i.e. sub a(x is parsed...) {}, mmh...)

Yes, what you're saying is true. And I'm not fundamentally opposed to making is parsed work for subs. It's more like, I don't see it as being on a critical path. More of an it-would-be-nice kind of thing.

One story that's missing currently for is parsed subs is, what parameters do they get from the is parsed regex? With macros, we're expecting/hoping that Q nodes will find their way into the parameters. Do subs get Q nodes too? Or do they get the "corresponding runtime values"? If the latter, how do we deal with the fact that expressions and identifiers have a value, but most other constructs (statements, traits, properties, argumentlists) don't?

@masak
Copy link
Owner Author

masak commented Aug 22, 2016

Now that we have regexes, I would like us to make is parsed work for something really really simple. Something like

macro statement:whoa() is parsed(/"whoa!"/) {
    return quasi @ Q::Statement {
        say("whoa!");
    }
}

whoa!;        # prints "whoa!\n"

I haven't tried this myself, nor thought about what it would take. But clearly something needs to be installed somewhere. Probably a decent starting point is the operators, which are an open set and which can be installed.

I'll accept PRs on this. If it's still open in a week or so, I'll try it myself. 😄

@vendethiel
Copy link
Collaborator

Not promising anything again, but it also sounds interesting. Should statement: add something to the statement category?

Should there be a statement:uds (user defined statement) that'd look at the is parsed list for the current scope?

@masak
Copy link
Owner Author

masak commented Aug 22, 2016

Not promising anything again, but it also sounds interesting. Should statement: add something to the statement category?

Yes, but note that that in itself has no observable effect except to change what the parser parses. There's no introspection into the statement category, for example. And until further notice, you can only subrule-call <statement>, not <statement:moo>.

Should there be a statement:uds (user defined statement) that'd look at the is parsed list for the current scope?

That could work, yes. (Though, again, I haven't thought deeply about it.) The thing to make sure is that things behave sanely with the old, hard-coded statement types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants