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

Allow empty target properties block #551

Merged
merged 6 commits into from
Sep 29, 2021

Conversation

oowekyala
Copy link
Collaborator

@oowekyala oowekyala commented Sep 28, 2021

This is especially handy when you comment out a target property. For now if the block happens to be empty you get a really unfriendly parsing error:

lfc: error: no viable alternative at input '}'
--> ../sandbox/R.lf:3:1
  |
2 |  // timeout: 3 sec
3 | };
  | ^^ no viable alternative at input '}'
  |
4 | main reactor R(p: int(2)) {

lfc: error: missing '}' at ';'
--> ../sandbox/R.lf:3:2
  |
2 |  // timeout: 3 sec
3 | };
  |  ^^ missing '}' at ';'
  |
4 | main reactor R(p: int(2)) {

lfc: fatal error: Aborting due to 2 previous errors

With this change, this produces no error anymore. If there is a need to produce an error (which here, I don't think there is) it should be produced by the validator instead.

Note that this also allows empty dictionary values, eg

target C {
   clock-sync-options: { /* everything defaulted */ }
}

I think this is fine for the same reasons (commenting out bindings).

I think it would be nice to make arrays in target properties accept empty arrays too. But this would require that the value of target properties be checked more thoroughly, so I'm leaving this for later.


Note: this branch is also merged in the PR #488

This is especially handy when you comment out a target property.
For now if the block happens to be empty you get a really unfriendly error:

lfc: fatal error: Unable to validate resource. Reason:
no viable alternative at input '}'
missing '}' at ';'
Unrecognized target parameter: null. Recognized parameters are: build, build-type, clock-sync, clock-sync-options, cmake-include, compiler, docker, external-runtime-path, fast, files, flags, coordination, coordination-options, keepalive, logging, no-compile, no-runtime-validation, protobufs, runtime-version, threads, timeout, tracing.
Copy link
Collaborator

@cmnrd cmnrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was bugging me as well, but I never got to opening an issue or fixing it. Thanks!

I think we should be aware that this grammar rule also allows target Foo { , }, but this is probably fine.

@codecov
Copy link

codecov bot commented Sep 28, 2021

Codecov Report

Merging #551 (ce66faf) into master (4a3b8cd) will increase coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #551      +/-   ##
============================================
+ Coverage     66.36%   66.39%   +0.02%     
- Complexity     3462     3465       +3     
============================================
  Files           132      132              
  Lines         22294    22321      +27     
  Branches       2883     2886       +3     
============================================
+ Hits          14795    14819      +24     
- Misses         6352     6354       +2     
- Partials       1147     1148       +1     
Impacted Files Coverage Δ
org.lflang/xtend-gen/org/lflang/TargetConfig.java 100.00% <0.00%> (ø)
org.lflang/src/org/lflang/TargetProperty.java 85.75% <0.00%> (+0.03%) ⬆️
.../xtend-gen/org/lflang/generator/GeneratorBase.java 56.67% <0.00%> (+0.93%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4a3b8cd...ce66faf. Read the comment docs.

@Soroosh129
Copy link
Contributor

Thanks for fixing this rather annoying issue.

Copy link
Member

@lhstrh lhstrh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good idea! I left a suggestion for improvement.

org.lflang/src/org/lflang/LinguaFranca.xtext Outdated Show resolved Hide resolved
org.lflang.tests/src/org/lflang/tests/LFParsingTest.java Outdated Show resolved Hide resolved
oowekyala and others added 2 commits September 29, 2021 15:31
Co-authored-by: Marten Lohstroh <[email protected]>
Copy link
Member

@lhstrh lhstrh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Let's merge this.

@lhstrh lhstrh merged commit c412652 into lf-lang:master Sep 29, 2021
@oowekyala oowekyala mentioned this pull request Sep 29, 2021
5 tasks
@oowekyala oowekyala deleted the make-grammar-more-forgiving branch September 29, 2021 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants