Skip to content

Commit

Permalink
Merge pull request #6 from swimos/complex-attr
Browse files Browse the repository at this point in the history
Complex attr
  • Loading branch information
DobromirM authored Dec 10, 2021
2 parents ce1ae41 + ee65189 commit 95c677f
Show file tree
Hide file tree
Showing 26 changed files with 82 additions and 24 deletions.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ apply plugin: 'org.jetbrains.grammarkit'
sourceSets.main.java.srcDirs 'src/main/gen'

group 'org.swim'
version '1.1.0'
version '1.2.0'

repositories {
mavenCentral()
Expand All @@ -22,8 +22,9 @@ dependencies {

// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
version '2021.2.3'
plugins = ['PsiViewer:212-SNAPSHOT', 'com.intellij.java']
version '2021.3'
plugins = ['PsiViewer:213-SNAPSHOT', 'com.intellij.java']
updateSinceUntilBuild false
}

patchPluginXml {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ private static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) {
builder.after(ReconTypes.OPEN_BRACK).spaces(0);
builder.before(ReconTypes.OPEN_BRACK).spaces(0);
builder.before(ReconTypes.CLOSE_BRACK).spaces(0);
builder.between(ReconTypes.ATTRIBUTE, ReconTypes.ATTRIBUTE).lineBreakInCode();
builder.between(ReconTypes.ATTRIBUTE, ReconTypes.ATTRIBUTE).spaces(1);
builder.between(ReconTypes.ATTRIBUTE, ReconTypes.COMPLEX_ATTR_HEADER).none();
builder.between(ReconTypes.ATTR, ReconTypes.ATTRIBUTE).spaces(1);
builder.between(ReconTypes.CLOSE_BRACK, ReconTypes.ATTRIBUTE).spaces(1);
builder.between(ReconTypes.ATTRIBUTE, ReconTypes.PRIMITIVE).lineBreakInCode();
builder.between(ReconTypes.LITERAL, ReconTypes.ATTRIBUTE).lineBreakInCode();
builder.between(ReconTypes.ATTRIBUTE, ReconTypes.RECORD).spaceIf(settings.getCommonSettings(ReconLanguage.INSTANCE.getID()).SPACE_BEFORE_CLASS_LBRACE);
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/swim/language/Recon.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,36 @@
tokenTypeClass="org.swim.language.psi.ReconTokenType"
}

reconFile ::= (attribute | record | slots | blockItem | literal | operation | COMMENT | whiteSpace)*
reconFile ::= (slots | attribute | record | blockItem | literal | operation | COMMENT | whiteSpace)*

blockItem ::= OPEN_BRACK? SP* (literal SP* (attribute SP* CLOSE_BRACK? operation? whiteSpace* blockItem?)?
| ((attribute SP* CLOSE_BRACK? operation?) SP*)+ ((primitive !COL)
| whiteSpace* !(OPEN_CRL_BRACK | ATTR | literal) complexAttrHeader
| (blockItem !COL) | record)?)
| COMMENT

complexAttrHeader ::= blockItem CLOSE_BRACK?

operation ::= whiteSpace* OPERATOR whiteSpace*

primitive ::= DATA | IDENT | STRING | NUM | BOOL | HEX

literal ::= record | primitive

attribute ::= ATTR SP* (whiteSpace* OPEN_BRACK attr_block? CLOSE_BRACK)?
attribute ::= ATTR SP* (whiteSpace* OPEN_BRACK (attribute | attr_block)? CLOSE_BRACK)? attribute?

attr_block ::= whiteSpace* attr_slots whiteSpace*

attr_slots ::= (empty_slot SP* (NL | SEP) whiteSpace* attr_slots?) | (slot SP* (((whiteSpace* SEP) | NL) whiteSpace* attr_slots?)?)

slots ::= (empty_slot SP* (NL | SEP) whiteSpace* slots?) | (slot SP* (((whiteSpace* SEP) | NL) whiteSpace* slots?)?)

slot ::= blockItem (whiteSpace* COL whiteSpace* blockItem)?
slot ::= (blockItem | attribute) (whiteSpace* COL whiteSpace* (blockItem | attribute))?

empty_slot ::= blockItem whiteSpace* COL

block ::= whiteSpace* slots whiteSpace*

record ::= whiteSpace* OPEN_CRL_BRACK block? whiteSpace* CLOSE_CRL_BRACK
record ::= SP* OPEN_CRL_BRACK block? whiteSpace* CLOSE_CRL_BRACK

whiteSpace ::= NL | SP
7 changes: 7 additions & 0 deletions src/test/java/ReconCodeFormattingTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ public void testFormatting() {
tests.add("attr-after-slot-expand.recon");
tests.add("attr-collapse.recon");
tests.add("attr-expand.recon");
tests.add("attr-in-attr-header-expand.recon");
tests.add("attr-nested-body-collapse.recon");
tests.add("attr-nested-collapse.recon");
tests.add("attr-nested-expand.recon");
tests.add("attr-nested-format.recon");
tests.add("attr-record-collapse.recon");
tests.add("attr-record-no-change.recon");
tests.add("attr-spaces-between.recon");
tests.add("attr-slot-expand.recon");
tests.add("cellular-collapse.recon");
tests.add("cellular-expand.recon");
tests.add("client-config-collapse.recon");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@tag(@first @second(1) {
1,
name: 2,
true
}
@test)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@first {
@second(@third)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@first(@attr)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@tag(@first @second(1) {
1,
name: 2,
true
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@first(@attr)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@attr(a: 1)
{
}
5 changes: 5 additions & 0 deletions src/test/testData/formatting/expected/attr-slot-expand.recon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@path {
host: "warp://127.0.0.2:9001",
node: foo,
lane: bar
}: 1
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
@foo()
@bar()
@baz()
@foo() @bar() @baz()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@tag(@first@second(1){1,name:2,true}@test)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@first {
@second (@third)
}
2 changes: 2 additions & 0 deletions src/test/testData/formatting/input/attr-nested-collapse.recon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@first
(@attr)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@tag(@first @second(1) { 1, name: 2, true })
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@first(@attr)
4 changes: 4 additions & 0 deletions src/test/testData/formatting/input/attr-record-collapse.recon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@attr(a: 1)
{

}
1 change: 1 addition & 0 deletions src/test/testData/formatting/input/attr-slot-expand.recon
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@path{host: "warp://127.0.0.2:9001",node: foo,lane: bar}:1
6 changes: 1 addition & 5 deletions src/test/testData/formatting/input/cellular-collapse.recon
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,7 @@ optional



cellular



: @fabric {
cellular: @fabric {
@plane(class


Expand Down
7 changes: 6 additions & 1 deletion src/test/testData/formatting/input/cellular-expand.recon

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
@config

{
@config {



Expand Down
3 changes: 2 additions & 1 deletion src/test/testData/formatting/input/rosa-expand.recon
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@kernel(class:'swim.meta.MetaKernel')rosa:@fabric{@plane(class:"swim.rosa.RosaPlane")@node{pattern:"/satellite/:id",@agent(class:"swim.rosa.SatelliteAgent")}@node{pattern:"/operator/:id",@agent(class:"swim.rosa.OperatorAgent")}@node{uri:"/notso",@agent(class:"swim.rosa.NotsoAgent")}@node{uri:"/conjunction",@agent(class:"swim.rosa.ConjunctionAgent")}@node{uri:"/spaceTrack",@agent(class:"swim.rosa.SpaceTrackAgent")}}@web(port:9001){space:"rosa",@websocket{serverCompressionLevel:0,clientCompressionLevel:0}}
@kernel(class:'swim.meta.MetaKernel')rosa:@fabric{@plane(class:"swim.rosa.RosaPlane")
@node{pattern:"/satellite/:id",@agent(class:"swim.rosa.SatelliteAgent")}@node{pattern:"/operator/:id",@agent(class:"swim.rosa.OperatorAgent")}@node{uri:"/notso",@agent(class:"swim.rosa.NotsoAgent")}@node{uri:"/conjunction",@agent(class:"swim.rosa.ConjunctionAgent")}@node{uri:"/spaceTrack",@agent(class:"swim.rosa.SpaceTrackAgent")}}@web(port:9001){space:"rosa",@websocket{serverCompressionLevel:0,clientCompressionLevel:0}}
6 changes: 5 additions & 1 deletion src/test/testData/formatting/input/tmforum-expand.recon
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
@kernel(class:"swim.store.db.DbStoreKernel",optional:true)@kernel(class:"swim.meta.MetaKernel")@kernel(class:"swim.cellular.CellularUiRouter")@web(port:9003){space:"cellular",@websocket{serverCompressionLevel:0,clientCompressionLevel:0,}}cellular:@fabric{@plane(class:"swim.cellular.CellularPlane")@node{pattern:"/site/:id",@agent(class:"swim.cellular.agent.SiteAgent")}@node{uri:"/country/US/state/CA"@agent(class:"swim.cellular.agent.RegionAgent"){seed:"seed/country/US/state/CA.recon"}@agent(class:"swim.cellular.agent.RanAgent"){seed:"seed/country/US/state/CA-sites.csv"}}@node{uri:"/country/US"@agent(class:"swim.cellular.agent.RegionAgent"){seed:"seed/country/US.recon"}}}
@kernel(class:"swim.store.db.DbStoreKernel",optional:true)
@kernel(class:"swim.meta.MetaKernel")
@kernel(class:"swim.cellular.CellularUiRouter")
@web(port:9003){space:"cellular",@websocket{serverCompressionLevel:0,clientCompressionLevel:0,}}cellular:@fabric{@plane(class:"swim.cellular.CellularPlane")
@node{pattern:"/site/:id",@agent(class:"swim.cellular.agent.SiteAgent")}@node{uri:"/country/US/state/CA"@agent(class:"swim.cellular.agent.RegionAgent"){seed:"seed/country/US/state/CA.recon"}@agent(class:"swim.cellular.agent.RanAgent"){seed:"seed/country/US/state/CA-sites.csv"}}@node{uri:"/country/US"@agent(class:"swim.cellular.agent.RegionAgent"){seed:"seed/country/US.recon"}}}
4 changes: 3 additions & 1 deletion src/test/testData/formatting/input/trafficware-expand.recon
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
@kernel(class:'swim.store.db.DbStoreKernel')@kernel(class:'swim.meta.MetaKernel')http:@web(port:9002){space:"traffic-app"@websocket{serverCompressionLevel:0,clientCompressionLevel:0,}}traffic-app:@fabric{@plane(class:"it.swim.traffic.TrafficApp")@node{pattern:"/intersection/:country/:state/:city/:id"@agent(class:"it.swim.traffic.gateway.CityIntersectionAgent")}@node{pattern:"/intersection/:country/:state/:city/:id"@agent(class:"it.swim.traffic.gateway.CityIntersectionAgent")}@node{pattern:"/city/:id"@agent(class:"it.swim.traffic.gateway.CityAgent")}@node{pattern:"/country/:id"@agent(class:"it.swim.traffic.gateway.CountryAgent")}@node{pattern:"/customer/:customer"@agent(class:"it.swim.traffic.gateway.api.CustomerAgent")}@node{uri:"/customers/all"@agent(class:"it.swim.traffic.gateway.api.CustomersAgent")}@node{uri:"/country/US"@agent(class:"it.swim.traffic.gateway.CountryAgent")}@store{path:"/tmp/swim/tw-gateway"}}
@kernel(class:'swim.store.db.DbStoreKernel')
@kernel(class:'swim.meta.MetaKernel')http:@web(port:9002){space:"traffic-app"@websocket{serverCompressionLevel:0,clientCompressionLevel:0,}}traffic-app:@fabric{@plane(class:"it.swim.traffic.TrafficApp")
@node{pattern:"/intersection/:country/:state/:city/:id"@agent(class:"it.swim.traffic.gateway.CityIntersectionAgent")}@node{pattern:"/intersection/:country/:state/:city/:id"@agent(class:"it.swim.traffic.gateway.CityIntersectionAgent")}@node{pattern:"/city/:id"@agent(class:"it.swim.traffic.gateway.CityAgent")}@node{pattern:"/country/:id"@agent(class:"it.swim.traffic.gateway.CountryAgent")}@node{pattern:"/customer/:customer"@agent(class:"it.swim.traffic.gateway.api.CustomerAgent")}@node{uri:"/customers/all"@agent(class:"it.swim.traffic.gateway.api.CustomersAgent")}@node{uri:"/country/US"@agent(class:"it.swim.traffic.gateway.CountryAgent")}@store{path:"/tmp/swim/tw-gateway"}}
5 changes: 4 additions & 1 deletion src/test/testData/formatting/input/transit-expand.recon
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Server A
@kernel(class:'swim.store.db.DbStoreKernel',optional:true)@kernel(class:"swim.meta.MetaKernel",optional: true)@kernel(class:"swim.cluster.ClusterKernel",optional:true)transit:@fabric{@plane(class:"swim.transit.TransitPlane")@mesh{@part{key: partA
@kernel(class:'swim.store.db.DbStoreKernel',optional:true)
@kernel(class:"swim.meta.MetaKernel",optional: true)
@kernel(class:"swim.cluster.ClusterKernel",optional:true)transit:@fabric{@plane(class:"swim.transit.TransitPlane")
@mesh{@part{key: partA
predicate:(@node("/country/:id")||@node("/state/:country/:state")||@node("/agency/:country/:state/:id")||@node("/vehicle/:country/:state/:agency/:id"))&&@hash(0x00000000, 0x7fffffff)
@host{
#uri: "warp://localhost:9008"
Expand Down

0 comments on commit 95c677f

Please sign in to comment.