I created a data structure for a framework I'm working on. it look like this
version: 1.0
name: Joshua Kensington
type: Doctor
media: http://some.page.com/media
color: #ffe339
This data structure currently has a specific set of known keys and well-defined value types for each and I tend to make this data structure into a standard so it might be expended, meaning that there might be more keys or more values that will be added in later versions.
I'm using chevrotain framework to create a lexer and a parser and I was struggling to figure out which is the best approach.
I've came up with these:
tokenizing the structure as a key: value set where keys will be defined as "key" token, the colon will be "colon" and the value will be a general "string literal" token.
the parser will cunsume {key}{colon}{string literal}
That way I can add more keys and values later on but I will have to create a new component that will validate the data against the version definition
tokenizing the structure as key: value type set where keys will be defined as "key" and colon as "colon" but for each value type, I will create a token of its own: a boolean, a url, a color, string, sets etc.
this will give me a better control over the allowed types but I still wouldn't be able to strict value types to certain keys
tokenizing each known key separately and each value type and let the parser define the allowed combinations.
This will spare me the validation process but it will add an overhead for each time the data structure definition will change
I thought that it is not that bad if users will add unknown keys because the data structure version will ensure that the keys that supposed to be there, will be there. also, I want to support missing keys when they are irrelevant (like when the users won't add "media" key if they don't use it)
So, what is the accepted standard regarding lexing data structures like this, are there any other strategies or is there a rule of thumb regarding this matter?
I couldn't find a proper guide or article so I came up with a solution that seems reasonable for who it may be of value
key:value pairs for foreword compatibility. they are obviously not being validated but value types are being tokenized.