How can I contruct a `X?` concrete syntax value?

148 views Asked by At

I have this concrete syntax:

syntax SomeMore = [...] SyncBlock? sync;
syntax SyncBlock = "sync" "{" SyncStatement* stats "}";
syntax SyncStatement = [...];

[SyncBlock]"sync { <syncStrings> }" seems to work, but when I try to use it as a SyncBlock? and assign it:

SyncBlock? sync = [SyncBlock?]"sync { <syncStrings> }"

it does not work: inline parsing not supported on SyncBlock?, what is the easiest way to build up a value of this X?-type?

Can I convert a SyncBlock to a SyncBlock? somehow?

Something like this also doesn’t work: syncBlock = (SyncBlock?)`sync { <SyncStatement* syncs>}`;

P.S. SyncBlock? syncBlock = … results in Ambiguous code (internal error), SyncBlock? syncBlock = …. Probably due to a ternary operator ambiguity?

1

There are 1 answers

1
Tim On BEST ANSWER

I found a workaround, not ideal, but it works. It seems that the ? in the types introduces some difficulties, but can be circumvented using an "alias" for this type:

I changed the grammar to:

syntax SomeMore = [...] MaybeSyncBlock sync;
syntax MaybeSyncBlock = SyncBlock?;
syntax SyncBlock = "sync" "{" SyncStatement* stats "}";
syntax SyncStatement = [...];

Now this works:

MaybeSyncBlock syncBlock = [MaybeSyncBlock]"sync { <syncStrings> }";