grammar_nt.y 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. %include {
  2. /** @brief Lemon parser grammar for N-Triples.
  3. *
  4. * The `lemon' parser generator executable must be in your PATH:
  5. * https://sqlite.org/src/doc/trunk/doc/lemon.html
  6. *
  7. * To generate the parser, run: `lemon ${FILE}'
  8. */
  9. #include "codec.h"
  10. }
  11. %name NTParse
  12. %token_type { LSUP_Term * }
  13. %token_prefix "T_"
  14. %default_type { void * }
  15. %extra_argument { LSUP_GraphIterator *it }
  16. // Rules.
  17. ntriplesDoc ::= triples EOF.
  18. triples ::= eol.
  19. triples ::= triple eol.
  20. triples ::= triples triple eol.
  21. %type triple { LSUP_Triple * }
  22. %destructor triple { LSUP_triple_free ($$); }
  23. triple(A) ::= ws subject(S) ws predicate(P) ws object(O) ws DOT. {
  24. A = LSUP_triple_new (S, P, O);
  25. LSUP_graph_add_iter (it, A);
  26. }
  27. %type subject { LSUP_Term * }
  28. %destructor subject { (void)(it); LSUP_term_free ($$); }
  29. subject ::= IRIREF.
  30. subject ::= BNODE.
  31. %type predicate { LSUP_Term * }
  32. %destructor predicate { LSUP_term_free ($$); }
  33. predicate ::= IRIREF.
  34. %type object { LSUP_Term * }
  35. %destructor object { LSUP_term_free ($$); }
  36. object ::= IRIREF.
  37. object ::= BNODE.
  38. object ::= LITERAL.
  39. eol ::= EOL.
  40. eol ::= eol EOL.
  41. ws ::=.
  42. ws ::= WS.