nt_grammar.y 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 "graph.h"
  10. }
  11. %token_type { LSUP_Term * }
  12. %token_prefix "T_"
  13. %type triple { LSUP_SerTriple * }
  14. %destructor triple { LSUP_striple_free ($$); }
  15. %type subject { LSUP_Term * }
  16. %destructor subject { LSUP_term_free ($$); }
  17. %type predicate { LSUP_Term * }
  18. %destructor predicate { LSUP_term_free ($$); }
  19. %type object { LSUP_Term * }
  20. %destructor object { LSUP_term_free ($$); }
  21. %default_type { void * }
  22. %extra_argument { LSUP_GraphIterator *it }
  23. // Rules.
  24. ntriplesDoc ::= triples EOF. { TRACE (STR, "Parsed N-Triples document.\n"); }
  25. triples ::= eol.
  26. triples ::= triple eol.
  27. triples ::= triples triple eol.
  28. triple(A) ::= ws subject(S) ws predicate(P) ws object(O) ws DOT. {
  29. A = LSUP_striple_new (
  30. LSUP_buffer_new_from_term (S),
  31. LSUP_buffer_new_from_term (P),
  32. LSUP_buffer_new_from_term (O)
  33. );
  34. LSUP_graph_add_iter (it, A);
  35. LSUP_term_free (S);
  36. LSUP_term_free (P);
  37. LSUP_term_free (O);
  38. }
  39. subject ::= IRIREF.
  40. subject ::= BNODE.
  41. predicate ::= IRIREF.
  42. object ::= IRIREF.
  43. object ::= BNODE.
  44. object ::= LITERAL.
  45. eol ::= EOL.
  46. eol ::= eol EOL.
  47. ws ::=.
  48. ws ::= WS.