Skip to content

let if statement declare variables in parent scope #41

Description

@jkeiser

if statements will have to participate in parsing before binding to do this. Participating will allow us to:

  • Treat the if block as if it were in scope
  • Treat if true f() as a block
  • Treat { if } and { if true } as errors

We will implement this by making the parser itself look up variables in a root scope before deciding they are undeclared variables. The IfValue would be a participant, and we'd feed it the token stream and let it go to town.

We might not yet be able to make these values participate as part of Berg, however: it depends whether we could actually pass the token (or expression) stream as a value, which might or might not be difficult since it's not currently a stream.

This also means FieldIndexes can be ast-local and not include fields in the root scope. That would mean it'd be an error to try to set true or false to something without declaring them locally. Finally, it means you probably need a separate token indicating a root field. This is probably all desirable.

This means it needs to happen somewhat early in the process, though right now the only requirement is it happen before the AST is fully written (so that it can emit the right errors) and before binding. A parse will probably be passed an input scope, from which it looks these things up.

Out Of Scope:

Try not to go overboard and do this with operators, eh?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions