Added user defined attribute declarations.

This is such that if you mis-spell an attribute, it doesn't get
silently ignored.

Bug: 18294628
Change-Id: I10013f5b2a21048b7daba2e9410678f528e09761
Tested: on Linux.
This commit is contained in:
Wouter van Oortmerssen
2014-11-17 17:27:26 -08:00
parent 0ce53c96c3
commit 0952143971
7 changed files with 45 additions and 14 deletions

View File

@@ -1,12 +1,15 @@
# Formal Grammar of the schema language
schema = include*
( namespace\_decl | type\_decl | enum\_decl | root\_decl | object )*
( namespace\_decl | type\_decl | enum\_decl | root\_decl |
attribute\_decl | object )*
include = `include` string\_constant `;`
namespace\_decl = `namespace` ident ( `.` ident )* `;`
attribute\_decl = `attribute` string\_constant `;`
type\_decl = ( `table` | `struct` ) ident metadata `{` field\_decl+ `}`
enum\_decl = ( `enum` | `union` ) ident [ `:` type ] metadata `{` commasep(

View File

@@ -9,6 +9,8 @@ first:
namespace MyGame;
attribute "priority";
enum Color : byte { Red = 1, Green, Blue }
union Any { Monster, Weapon, Pickup }
@@ -211,7 +213,8 @@ in the corresponding C++ code. Multiple such lines per item are allowed.
Attributes may be attached to a declaration, behind a field, or after
the name of a table/struct/enum/union. These may either have a value or
not. Some attributes like `deprecated` are understood by the compiler,
others are simply ignored (like `priority` in the example above), but are
user defined ones need to be declared with the attribute declaration
(like `priority` in the example above), and are
available to query if you parse the schema at runtime.
This is useful if you write your own code generators/editors etc., and
you wish to add additional information specific to your tool (such as a