;;; elot-owl-grammar.el --- OWL Manchester Syntax grammar for peg.el  -*- lexical-binding: t; -*-

;; Copyright (C) 2024, 2025, 2026 Johan W. Klüwer

;; Author: Johan W. Klüwer <johan.w.kluwer@gmail.com>
;; URL: https://github.com/johanwk/elot
;; SPDX-License-Identifier: GPL-3.0-or-later

;; This file is not part of GNU Emacs.

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Generated by peggy-to-peg.el from owl-manchester.peggy.
;; Do not edit by hand -- edit the .peggy file and run
;; "make grammar && make install" from the repository root
;; to regenerate.

;;; Code:

(require 'peg)

(define-peg-ruleset elot-owl-grammar
  (class-expression () or-expression)
  (or-expression () (and and-expression (* (and ws "or" ws and-expression))))
  (and-expression () (and primary-expression (* (and ws "and" ws primary-expression))))
  (primary-expression () (or (and "not" ws primary-expression) atomic-expression))
  (atomic-expression () (or restriction datatype-restriction class-iri "Thing" "Nothing" (and "{" ows individual-list ows "}") (and "(" ows class-expression ows ")")))
  (sub-property-chain () (and object-property-expression (+ (and ws "o" (not name-char) ws object-property-expression))))
  (restriction () (or (and object-property-expression ws "some" ws primary-expression) (and object-property-expression ws "only" ws primary-expression) (and object-property-expression ws "value" ws literal) (and object-property-expression ws "value" ws individual-iri) (and object-property-expression ws "min" ws integer (opt (and ws primary-expression))) (and object-property-expression ws "max" ws integer (opt (and ws primary-expression))) (and object-property-expression ws "exactly" ws integer (opt (and ws primary-expression))) (and object-property-expression ws "Self")))
  (object-property-expression () (or (and "inverse" ws "(" ows object-property-iri ows ")") (and "inverse" ws object-property-iri) object-property-iri))
  (data-range () (and data-conjunction (* (and ws "or" ws data-conjunction))))
  (data-conjunction () (and data-primary (* (and ws "and" ws data-primary))))
  (data-primary () (or (and "not" ws data-primary) data-atomic))
  (data-atomic () (or datatype-restriction datatype-iri (and "{" ows literal-list ows "}") (and "(" ows data-range ows ")")))
  (datatype-restriction () (and datatype-iri ows "[" ows facet-restriction (* (and ows "," ows facet-restriction)) ows "]"))
  (facet-restriction () (and facet ws literal))
  (facet () (or "minLength" "maxLength" "length" "pattern" "langRange" "<=" ">=" "<" ">"))
  (fact () (and single-fact (* (and ows "," ows single-fact))))
  (single-fact () (or (and "not" ws object-property-iri ws (or literal individual)) (and object-property-iri ws (or literal individual))))
  (individual () (or node-id individual-iri))
  (node-id () (and "_:" local-name))
  (class-expression-list () (and class-expression (* (and ows "," ows class-expression))))
  (class-expression-2-list () (and class-expression (+ (and ows "," ows class-expression))))
  (object-property-expression-list () (and object-property-expression (* (and ows "," ows object-property-expression))))
  (object-property-expression-2-list () (and object-property-expression (+ (and ows "," ows object-property-expression))))
  (individual-list () (and individual (* (and ows "," ows individual))))
  (individual-2-list () (and individual (+ (and ows "," ows individual))))
  (literal-list () (and literal (* (and ows "," ows literal))))
  (class-iri () iri)
  (object-property-iri () iri)
  (datatype-iri () iri)
  (individual-iri () iri)
  (iri () (or full-iri prefixed-name bare-name))
  (full-iri () (and "<" (+ (and (not ">") (any))) ">"))
  (prefixed-name () (or (and prefix ":" local-name) (and ":" local-name)))
  (individual-iri-list () (and individual (* (and ws "," ws individual))))
  (bare-name () (and (not keyword-boundary) bare-local-name))
  (keyword-boundary () (or (and "and" (not name-char)) (and "or" (not name-char)) (and "not" (not name-char)) (and "some" (not name-char)) (and "only" (not name-char)) (and "value" (not name-char)) (and "min" (not name-char)) (and "max" (not name-char)) (and "exactly" (not name-char)) (and "Self" (not name-char)) (and "Thing" (not name-char)) (and "Nothing" (not name-char)) (and "inverse" (not name-char)) (and "o" (not name-char)) (and "minLength" (not name-char)) (and "maxLength" (not name-char)) (and "length" (not name-char)) (and "pattern" (not name-char)) (and "langRange" (not name-char))))
  (name-char () (or (range ?a ?z) (range ?A ?Z) (range ?0 ?9) "_" "." ":" "/" "-"))
  (prefix () (+ (or (range ?a ?z) (range ?A ?Z) (range ?0 ?9) "_" "-")))
  (local-name () (and (or (range ?a ?z) (range ?A ?Z) "_" (range ?0 ?9) ":") (* (or (or (range ?a ?z) (range ?A ?Z) (range ?0 ?9) "_" ":" "/" "-") (and "." (or (range ?a ?z) (range ?A ?Z) (range ?0 ?9) "_" "." ":" "/" "-"))))))
  (bare-local-name () (and (or (range ?a ?z) (range ?A ?Z) "_") (* (or (or (range ?a ?z) (range ?A ?Z) (range ?0 ?9) "_" ":" "/" "-") (and "." (or (range ?a ?z) (range ?A ?Z) (range ?0 ?9) "_" "." ":" "/" "-"))))))
  (literal () (or (and "\"" (* (and (not "\"") (any))) "\"" (opt (or (and "^^" datatype-iri) (and "@" language-tag)))) floating-point-literal decimal-literal integer-literal))
  (language-tag () (and (+ (or (range ?a ?z) (range ?A ?Z))) (* (and "-" (+ (or (range ?a ?z) (range ?A ?Z) (range ?0 ?9)))))))
  (integer-literal () (and (opt (or "+" "-")) digits (not (or "." (or "e" "E" "f" "F")))))
  (decimal-literal () (and (opt (or "+" "-")) digits "." digits (not (or "e" "E" "f" "F"))))
  (floating-point-literal () (or (and (opt (or "+" "-")) digits (opt (and "." digits)) (or "e" "E") (opt (or "+" "-")) digits (opt (or "f" "F"))) (and (opt (or "+" "-")) digits (opt (and "." digits)) (or "f" "F"))))
  (digits () (+ (range ?0 ?9)))
  (integer () (+ (range ?0 ?9)))
  (ws () (+ (or " " "\t" "\n" "\r")))
  (ows () (* (or " " "\t" "\n" "\r"))))

(provide 'elot-owl-grammar)

;;; elot-owl-grammar.el ends here
