Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Conditionals Syntactic Shorthands #192

Closed
kammoh opened this issue Jun 13, 2016 · 4 comments
Closed

Conditionals Syntactic Shorthands #192

kammoh opened this issue Jun 13, 2016 · 4 comments

Comments

@kammoh
Copy link
Contributor

kammoh commented Jun 13, 2016

Current FIRRTL spec mentions a "syntactical shorthand" for else-when chains (in 5.9.1: Syntactic Shorthands) which is not supported by the current Scala implementation (I guess some of the other shorthands are not supported either). I was wondering if this is something which is planned to be implemented in the future or if it's probable that the spec is going to drop this altogether.

@azidar
Copy link
Contributor

azidar commented Jun 13, 2016

@jackkoenig are there plans to support this in the Scala implementation?

@jackkoenig
Copy link
Contributor

So it turns out that the shorthand for else-when chains is difficult to support in the current implementation of the parser. They were supported until recently, but I dropped them with the addition of source locators. The problem how do we correctly deal with source locators on shorthand when statements? ie.

when condition : @[when source locator]
    some <= connection @[connect source locator]

So how do we do this on shorthand whens?

; Like so?
when condition : @[when source locator] (some <= connection @[connect source locator])

; Or perhaps
when condition : (some <= connection @[connect source locator]) @[when source locator]

The main issue is not with the ANTLR-generated parser but with how this is handled in the preprocess step (ie. Translator). I do not have plans to add support in the short term because the Translator has been a real time sink. In my opinion, one of the following 3 things should happen:

  1. Translator is replaced by a 2nd ANTLR grammar that does the preprocess step
  2. The primary ANTLR grammar handles white space scoping and Translator can be deleted
  3. White space scoping is abandoned in favor of brackets

In any of the above cases, these syntactical shorthands should be relatively easy to support although it is a reasonable question why shorthand is needed in an IR.

For the record, register shorthand is supported because there's only 1 source locator so there was no ambiguity to deal with.

@azidar
Copy link
Contributor

azidar commented Jun 15, 2016

Sounds like the plan is to support it eventually :)

@azidar azidar closed this as completed Jun 15, 2016
@kammoh
Copy link
Contributor Author

kammoh commented Jun 20, 2016

Hi,
Just made a PR (#194) regarding this issue, adapting @jackkoenig 's solution "2", handling while-space scoping in the lexer. I've also made some clean-up to the parser code, which showed up to be quite brittle.

jackkoenig pushed a commit that referenced this issue Jul 21, 2016
Indentation support for the ANTLR parser
    - some clean-up of the parser code (TODO: file input could be improved, more clean-up)
    - get rid of Translator and specify all syntactic rules in antlr4 grammer
    - support for else-when shorthand in the grammar
    - rename Begin to Block which makes more sense
jackkoenig added a commit that referenced this issue Jun 28, 2018
Implemented by adding a Boolean to check for alternating invocations of object
Module.apply and the constructor of abstract class Module.
Fixes #192
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants