anz-bank / sysl

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

Deprecate unsupported parenthetical primitive constraints #1044

Open andrewemeryanz opened 4 years ago

andrewemeryanz commented 4 years ago

Purpose

Following on from this comment, the Sysl parser currently parses parenthetical primitive constraints that have never been officially supported. Consider the following examples of types that parse correctly but have never been officially supported:

int(4)           # primitive: INT, constraint: { length: { max: 4 } }
int(4.8)         # primitive: INT, constraint: { length: { max: 4 } }
string(4.8)      # primitive: STRING, constraint: { length: { max: 4 } }

The following is the list of officially supported parenthetical primitive type constraints and their expected representation:

decimal(4.8)     # primitive: DECIMAL, constraint: { precision: 4, scale: 8 }
string(4)        # primitive: STRING, constraint: { length: { max: 4 } }
string(4..8)     # primitive: STRING, constraint: { length: { min: 4, max: 8 } }

All other representations should be considered invalid.

Suggested approaches

The corpus of Sysl files should first be searched to see if any of the unsupported representations are being used. The parser should then either fail or warn when an unsupported representation is discovered (depending on how widely the representation can be found in use).

andrewemeryanz commented 4 years ago

@marcelocantos Could you comment on the correctness of this statement:

The following is the list of officially supported parenthetical primitive type constraints and their expected representation:

decimal(4.8)     # primitive: DECIMAL, constraint: { precision: 4, scale: 8 }
string(4)        # primitive: STRING, constraint: { length: { max: 4 } }
string(4..8)     # primitive: STRING, constraint: { length: { min: 4, max: 8 } }

Also, should we consider supporting the bitWidth constraint (from this issue) as the general approach to numeric types? For example, the representation of the following types would be (taking into considering their currently parsed values):

decimal(4)      # primitive: DECIMAL, constraint: { bitWidth: 4, length: { max: 4 } }
int(4)          # primitive: INT, constraint: { bitWidth: 4, length: { max: 4 } }
float(4)        # primitive: FLOAT, constraint: { bitWidth: 4 }