anz-bank / sysl

Sysl (pronounced "sizzle") is a system specification language
https://sysl.io
Apache License 2.0
122 stars 42 forks source link

Syntax union issue #976

Closed ericzhang6222 closed 4 years ago

ericzhang6222 commented 4 years ago

Description

As https://sysl.io/docs/lang-spec/#union !union string, int32 should work, but it can't actually.

Steps to Reproduce

  1. Created Sysl file demo.sysl
    
    Project:
    App:
        Simple

Simple: !type User: id <: string ping <: StringOrInt32

!union StringOrInt32:
    a
    b

!alias a:
    string

!alias b:
    int32

!union string, int32
2. Run command `sysl datamodel -j Project -d demo.sysl`
### Expected behavior
It can run successfully and output diagram

### Actual behavior
It is crashed and output error:

$ sysl datamodel -j Project -d demo.sysl line 20:11 mismatched input 'string' expecting {TEXT_LINE, Name, E_Name} ERRO[0000] demo.sysl has syntax errors

It can't pass Sysl syntax parsing.

And the alternative option is:

!union StringOrInt32: a b

!alias a: string !alias b: int32


### Your Environment
```sh
$ sysl info
Build:
  Version         :  v0.155.0
  Git Commit   : 7f4486576e79474836ac6e8377458aab7239dd9e
  Date              : 2020-07-29T08:14:51Z
  Go Version   : go1.14 darwin/amd64
  OS                 : darwin/amd64
ChloePlanet commented 4 years ago

According to sysl2/sysl/tests/union.sysl in #170, the right syntax is

Test:
    !type A: ...
    !type B: ...
    !type C: ...

    !union U:
        A
        B
        C
ericzhang6222 commented 4 years ago

Fixed by https://github.com/anz-bank/sysl-website/pull/58

andrewemeryanz commented 4 years ago

@ChloePlanet Is it by design that aliases don't support primitive types or is it a bug? Could aliases support primitive types:

!alias StringInt:
    string
    int
anzdaddy commented 4 years ago

It's an implementation gap. We should support unions of any type, including aliases and direct primitives:

!union StringInt:
    string
    int
ericzhang6222 commented 4 years ago

Avro to Sysl transformation is depending on this issue, change priority to P0 to fix ASAP.

andrewemeryanz commented 4 years ago

This fix also needs to support sequences and sets:

!union StringSequenceAddressSet:
    sequence of string
    set of Address