diff --git a/doc/grammar-schema.json b/doc/grammar-schema.json new file mode 100644 index 00000000..9fc50189 --- /dev/null +++ b/doc/grammar-schema.json @@ -0,0 +1,256 @@ +{ + "type": "object", + + "required": [ + "name", + "rules" + ], + + "additionalProperties": false, + + "properties": { + "name": { + "type": "string", + "pattern": "^[a-zA-Z_]\\w*" + }, + + "rules": { + "type": "object", + "patternProperties": { + "^[a-zA-Z_]\\w*$": { + "$ref": "#/definitions/rule" + } + }, + "additionalProperties": false + }, + + "extras": { + "type": "array", + "items": { + "$ref": "#/definitions/rule" + } + }, + + "conflicts": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "string", + "pattern": "^[a-zA-Z_]\\w*$" + } + } + } + }, + + "definitions": { + "blank-rule": { + "type": "object", + "properties": { + "type": { + "type": "string", + "pattern": "^BLANK$" + } + }, + "required": ["type"] + }, + + "string-rule": { + "type": "object", + "properties": { + "type": { + "type": "string", + "pattern": "^STRING$" + }, + "value": { + "type": "string" + } + }, + "required": ["type", "value"] + }, + + "pattern-rule": { + "type": "object", + "properties": { + "type": { + "type": "string", + "pattern": "^PATTERN$" + }, + "value": {"type": "string"} + }, + "required": ["type", "value"] + }, + + "symbol-rule": { + "required": ["name"], + "type": "object", + "properties": { + "type": { + "type": "string", + "pattern": "^SYMBOL$" + }, + "name": {"type": "string"} + }, + "required": ["type", "name"] + }, + + "seq-rule": { + "type": "object", + "properties": { + "type": { + "type": "string", + "pattern": "^SEQ$" + }, + "members": { + "type": "array", + "items": { + "$ref": "#/definitions/rule" + } + } + }, + "required": ["type", "members"] + }, + + "choice-rule": { + "type": "object", + "properties": { + "type": { + "type": "string", + "pattern": "^CHOICE$" + }, + "members": { + "type": "array", + "items": { + "$ref": "#/definitions/rule" + } + } + }, + "required": ["type", "members"] + }, + + "repeat-rule": { + "type": "object", + "properties": { + "type": { + "type": "string", + "pattern": "^REPEAT$" + }, + "content": { + "$ref": "#/definitions/rule" + } + }, + "required": ["type", "content"] + }, + + "repeat1-rule": { + "type": "object", + "properties": { + "type": { + "type": "string", + "pattern": "^REPEAT1$" + }, + "content": { + "$ref": "#/definitions/rule" + } + }, + "required": ["type", "content"] + }, + + "token-rule": { + "type": "object", + "properties": { + "type": { + "type": "string", + "pattern": "^TOKEN$" + }, + "content": { + "$ref": "#/definitions/rule" + } + }, + "required": ["type", "content"] + }, + + "error-rule": { + "type": "object", + "properties": { + "type": { + "type": "string", + "pattern": "^ERROR$" + }, + "content": { + "$ref": "#/definitions/rule" + } + }, + "required": ["type", "content"] + }, + + "prec-rule": { + "type": "object", + "properties": { + "type": { + "type": "string", + "pattern": "^PREC$" + }, + "value": { + "type": "integer" + }, + "content": { + "$ref": "#/definitions/rule" + } + }, + "required": ["type", "content", "value"] + }, + + "prec-left-rule": { + "type": "object", + "properties": { + "type": { + "type": "string", + "pattern": "^PREC_LEFT$" + }, + "value": { + "type": "integer" + }, + "content": { + "$ref": "#/definitions/rule" + } + }, + "required": ["type", "content", "value"] + }, + + "prec-right-rule": { + "type": "object", + "properties": { + "type": { + "type": "string", + "pattern": "^PREC_RIGHT$" + }, + "value": { + "type": "integer" + }, + "content": { + "$ref": "#/definitions/rule" + } + }, + "required": ["type", "content", "value"] + }, + + "rule": { + "oneOf": [ + { "$ref": "#/definitions/blank-rule" }, + { "$ref": "#/definitions/string-rule" }, + { "$ref": "#/definitions/pattern-rule" }, + { "$ref": "#/definitions/symbol-rule" }, + { "$ref": "#/definitions/seq-rule" }, + { "$ref": "#/definitions/choice-rule" }, + { "$ref": "#/definitions/repeat1-rule" }, + { "$ref": "#/definitions/repeat-rule" }, + { "$ref": "#/definitions/token-rule" }, + { "$ref": "#/definitions/error-rule" }, + { "$ref": "#/definitions/prec-rule" }, + { "$ref": "#/definitions/prec-left-rule" }, + { "$ref": "#/definitions/prec-right-rule" } + ] + } + } +}