bel_parser 1.0.0.alpha.27-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (332) hide show
  1. checksums.yaml +7 -0
  2. data/.gemspec-java +32 -0
  3. data/CHANGELOG.md +10 -0
  4. data/LICENSE +191 -0
  5. data/README.md +20 -0
  6. data/VERSION +1 -0
  7. data/bin/bel2_validator +62 -0
  8. data/bin/bel_script_reader +132 -0
  9. data/lib/bel/translator/plugins/bel_script.rb +38 -0
  10. data/lib/bel/translator/plugins/bel_script/bel_citation_serialization.rb +125 -0
  11. data/lib/bel/translator/plugins/bel_script/bel_discrete_serialization.rb +109 -0
  12. data/lib/bel/translator/plugins/bel_script/bel_top_down_serialization.rb +100 -0
  13. data/lib/bel/translator/plugins/bel_script/nanopub_serialization.rb +79 -0
  14. data/lib/bel/translator/plugins/bel_script/reader.rb +39 -0
  15. data/lib/bel/translator/plugins/bel_script/translator.rb +37 -0
  16. data/lib/bel/translator/plugins/bel_script/writer.rb +180 -0
  17. data/lib/bel_parser.rb +23 -0
  18. data/lib/bel_parser/ast_filter.rb +44 -0
  19. data/lib/bel_parser/ast_generator.rb +83 -0
  20. data/lib/bel_parser/expression.rb +3 -0
  21. data/lib/bel_parser/expression/filter.rb +31 -0
  22. data/lib/bel_parser/expression/parser.rb +72 -0
  23. data/lib/bel_parser/expression/validator.rb +79 -0
  24. data/lib/bel_parser/language.rb +114 -0
  25. data/lib/bel_parser/language/amino_acid.rb +68 -0
  26. data/lib/bel_parser/language/apply_namespace_encoding.rb +98 -0
  27. data/lib/bel_parser/language/base_specification.rb +82 -0
  28. data/lib/bel_parser/language/covalent_protein_modification.rb +56 -0
  29. data/lib/bel_parser/language/expression_validator.rb +68 -0
  30. data/lib/bel_parser/language/function.rb +67 -0
  31. data/lib/bel_parser/language/relationship.rb +102 -0
  32. data/lib/bel_parser/language/semantics.rb +40 -0
  33. data/lib/bel_parser/language/semantics/deeply_nested_statement.rb +65 -0
  34. data/lib/bel_parser/language/semantics/function_deprecation.rb +43 -0
  35. data/lib/bel_parser/language/semantics/list_function_subject.rb +45 -0
  36. data/lib/bel_parser/language/semantics/multiple_subject_object.rb +55 -0
  37. data/lib/bel_parser/language/semantics/non_causal_nested_statement.rb +50 -0
  38. data/lib/bel_parser/language/semantics/non_object_list.rb +56 -0
  39. data/lib/bel_parser/language/semantics/relationship_deprecation.rb +44 -0
  40. data/lib/bel_parser/language/semantics/relationship_not_listable.rb +60 -0
  41. data/lib/bel_parser/language/semantics/signature_mapping.rb +83 -0
  42. data/lib/bel_parser/language/semantics_ast.rb +784 -0
  43. data/lib/bel_parser/language/semantics_ast_warnings.rb +180 -0
  44. data/lib/bel_parser/language/semantics_function.rb +16 -0
  45. data/lib/bel_parser/language/semantics_match.rb +28 -0
  46. data/lib/bel_parser/language/semantics_result.rb +33 -0
  47. data/lib/bel_parser/language/semantics_type_warning.rb +22 -0
  48. data/lib/bel_parser/language/semantics_warning.rb +27 -0
  49. data/lib/bel_parser/language/signature.rb +39 -0
  50. data/lib/bel_parser/language/specification.rb +118 -0
  51. data/lib/bel_parser/language/syntax.rb +38 -0
  52. data/lib/bel_parser/language/syntax/invalid_function.rb +39 -0
  53. data/lib/bel_parser/language/syntax/invalid_relationship.rb +42 -0
  54. data/lib/bel_parser/language/syntax/undefined_namespace.rb +49 -0
  55. data/lib/bel_parser/language/syntax/undefined_namespace_value.rb +44 -0
  56. data/lib/bel_parser/language/syntax_error.rb +32 -0
  57. data/lib/bel_parser/language/syntax_function.rb +16 -0
  58. data/lib/bel_parser/language/syntax_result.rb +32 -0
  59. data/lib/bel_parser/language/syntax_warning.rb +27 -0
  60. data/lib/bel_parser/language/version1_0.rb +20 -0
  61. data/lib/bel_parser/language/version1_0/functions/abundance.rb +83 -0
  62. data/lib/bel_parser/language/version1_0/functions/biological_process.rb +83 -0
  63. data/lib/bel_parser/language/version1_0/functions/catalytic_activity.rb +114 -0
  64. data/lib/bel_parser/language/version1_0/functions/cell_secretion.rb +83 -0
  65. data/lib/bel_parser/language/version1_0/functions/cell_surface_expression.rb +83 -0
  66. data/lib/bel_parser/language/version1_0/functions/chaperone_activity.rb +114 -0
  67. data/lib/bel_parser/language/version1_0/functions/complex_abundance.rb +115 -0
  68. data/lib/bel_parser/language/version1_0/functions/composite_abundance.rb +81 -0
  69. data/lib/bel_parser/language/version1_0/functions/degradation.rb +83 -0
  70. data/lib/bel_parser/language/version1_0/functions/fusion.rb +287 -0
  71. data/lib/bel_parser/language/version1_0/functions/gene_abundance.rb +122 -0
  72. data/lib/bel_parser/language/version1_0/functions/gtp_bound_activity.rb +113 -0
  73. data/lib/bel_parser/language/version1_0/functions/kinase_activity.rb +114 -0
  74. data/lib/bel_parser/language/version1_0/functions/list.rb +114 -0
  75. data/lib/bel_parser/language/version1_0/functions/micro_rna_abundance.rb +85 -0
  76. data/lib/bel_parser/language/version1_0/functions/molecular_activity.rb +82 -0
  77. data/lib/bel_parser/language/version1_0/functions/pathology.rb +83 -0
  78. data/lib/bel_parser/language/version1_0/functions/peptidase_activity.rb +112 -0
  79. data/lib/bel_parser/language/version1_0/functions/phosphatase_activity.rb +112 -0
  80. data/lib/bel_parser/language/version1_0/functions/products.rb +79 -0
  81. data/lib/bel_parser/language/version1_0/functions/protein_abundance.rb +234 -0
  82. data/lib/bel_parser/language/version1_0/functions/protein_modification.rb +179 -0
  83. data/lib/bel_parser/language/version1_0/functions/reactants.rb +79 -0
  84. data/lib/bel_parser/language/version1_0/functions/reaction.rb +86 -0
  85. data/lib/bel_parser/language/version1_0/functions/ribosylation_activity.rb +114 -0
  86. data/lib/bel_parser/language/version1_0/functions/rna_abundance.rb +122 -0
  87. data/lib/bel_parser/language/version1_0/functions/substitution.rb +93 -0
  88. data/lib/bel_parser/language/version1_0/functions/transcriptional_activity.rb +114 -0
  89. data/lib/bel_parser/language/version1_0/functions/translocation.rb +98 -0
  90. data/lib/bel_parser/language/version1_0/functions/transport_activity.rb +115 -0
  91. data/lib/bel_parser/language/version1_0/functions/truncation.rb +81 -0
  92. data/lib/bel_parser/language/version1_0/relationships/acts_in.rb +61 -0
  93. data/lib/bel_parser/language/version1_0/relationships/analogous.rb +41 -0
  94. data/lib/bel_parser/language/version1_0/relationships/association.rb +42 -0
  95. data/lib/bel_parser/language/version1_0/relationships/biomarker_for.rb +42 -0
  96. data/lib/bel_parser/language/version1_0/relationships/causes_no_change.rb +50 -0
  97. data/lib/bel_parser/language/version1_0/relationships/decreases.rb +63 -0
  98. data/lib/bel_parser/language/version1_0/relationships/directly_decreases.rb +56 -0
  99. data/lib/bel_parser/language/version1_0/relationships/directly_increases.rb +56 -0
  100. data/lib/bel_parser/language/version1_0/relationships/has_component.rb +62 -0
  101. data/lib/bel_parser/language/version1_0/relationships/has_components.rb +61 -0
  102. data/lib/bel_parser/language/version1_0/relationships/has_member.rb +48 -0
  103. data/lib/bel_parser/language/version1_0/relationships/has_members.rb +57 -0
  104. data/lib/bel_parser/language/version1_0/relationships/has_modification.rb +54 -0
  105. data/lib/bel_parser/language/version1_0/relationships/has_product.rb +60 -0
  106. data/lib/bel_parser/language/version1_0/relationships/has_variant.rb +54 -0
  107. data/lib/bel_parser/language/version1_0/relationships/includes.rb +59 -0
  108. data/lib/bel_parser/language/version1_0/relationships/increases.rb +63 -0
  109. data/lib/bel_parser/language/version1_0/relationships/is_a.rb +48 -0
  110. data/lib/bel_parser/language/version1_0/relationships/negative_correlation.rb +50 -0
  111. data/lib/bel_parser/language/version1_0/relationships/orthologous.rb +48 -0
  112. data/lib/bel_parser/language/version1_0/relationships/positive_correlation.rb +46 -0
  113. data/lib/bel_parser/language/version1_0/relationships/prognostic_biomarker_for.rb +44 -0
  114. data/lib/bel_parser/language/version1_0/relationships/rate_limiting_step_of.rb +53 -0
  115. data/lib/bel_parser/language/version1_0/relationships/reactant_in.rb +60 -0
  116. data/lib/bel_parser/language/version1_0/relationships/sub_process_of.rb +55 -0
  117. data/lib/bel_parser/language/version1_0/relationships/transcribed_to.rb +53 -0
  118. data/lib/bel_parser/language/version1_0/relationships/translated_to.rb +54 -0
  119. data/lib/bel_parser/language/version1_0/relationships/translocates.rb +57 -0
  120. data/lib/bel_parser/language/version1_0/return_types/abundance.rb +20 -0
  121. data/lib/bel_parser/language/version1_0/return_types/any.rb +74 -0
  122. data/lib/bel_parser/language/version1_0/return_types/biological_process.rb +17 -0
  123. data/lib/bel_parser/language/version1_0/return_types/catalytic_activity.rb +20 -0
  124. data/lib/bel_parser/language/version1_0/return_types/chaperone_activity.rb +20 -0
  125. data/lib/bel_parser/language/version1_0/return_types/complex_abundance.rb +17 -0
  126. data/lib/bel_parser/language/version1_0/return_types/fusion.rb +17 -0
  127. data/lib/bel_parser/language/version1_0/return_types/gene_abundance.rb +17 -0
  128. data/lib/bel_parser/language/version1_0/return_types/gtp_bound_activity.rb +20 -0
  129. data/lib/bel_parser/language/version1_0/return_types/kinase_activity.rb +20 -0
  130. data/lib/bel_parser/language/version1_0/return_types/list.rb +17 -0
  131. data/lib/bel_parser/language/version1_0/return_types/micro_rna_abundance.rb +17 -0
  132. data/lib/bel_parser/language/version1_0/return_types/molecular_activity.rb +20 -0
  133. data/lib/bel_parser/language/version1_0/return_types/pathology.rb +17 -0
  134. data/lib/bel_parser/language/version1_0/return_types/peptidase_activity.rb +20 -0
  135. data/lib/bel_parser/language/version1_0/return_types/phosphatase_activity.rb +20 -0
  136. data/lib/bel_parser/language/version1_0/return_types/products.rb +17 -0
  137. data/lib/bel_parser/language/version1_0/return_types/protein_abundance.rb +17 -0
  138. data/lib/bel_parser/language/version1_0/return_types/protein_modification.rb +17 -0
  139. data/lib/bel_parser/language/version1_0/return_types/reactants.rb +17 -0
  140. data/lib/bel_parser/language/version1_0/return_types/ribosylation_activity.rb +20 -0
  141. data/lib/bel_parser/language/version1_0/return_types/rna_abundance.rb +17 -0
  142. data/lib/bel_parser/language/version1_0/return_types/substitution.rb +17 -0
  143. data/lib/bel_parser/language/version1_0/return_types/transcriptional_activity.rb +20 -0
  144. data/lib/bel_parser/language/version1_0/return_types/transport_activity.rb +20 -0
  145. data/lib/bel_parser/language/version1_0/return_types/truncation.rb +17 -0
  146. data/lib/bel_parser/language/version1_0/value_encodings/abundance.rb +21 -0
  147. data/lib/bel_parser/language/version1_0/value_encodings/any.rb +74 -0
  148. data/lib/bel_parser/language/version1_0/value_encodings/biological_process.rb +21 -0
  149. data/lib/bel_parser/language/version1_0/value_encodings/complex_abundance.rb +21 -0
  150. data/lib/bel_parser/language/version1_0/value_encodings/gene_abundance.rb +21 -0
  151. data/lib/bel_parser/language/version1_0/value_encodings/micro_rna_abundance.rb +21 -0
  152. data/lib/bel_parser/language/version1_0/value_encodings/pathology.rb +21 -0
  153. data/lib/bel_parser/language/version1_0/value_encodings/protein_abundance.rb +21 -0
  154. data/lib/bel_parser/language/version1_0/value_encodings/rna_abundance.rb +21 -0
  155. data/lib/bel_parser/language/version2_0.rb +20 -0
  156. data/lib/bel_parser/language/version2_0/functions/abundance.rb +161 -0
  157. data/lib/bel_parser/language/version2_0/functions/activity.rb +118 -0
  158. data/lib/bel_parser/language/version2_0/functions/biological_process.rb +84 -0
  159. data/lib/bel_parser/language/version2_0/functions/cell_secretion.rb +83 -0
  160. data/lib/bel_parser/language/version2_0/functions/cell_surface_expression.rb +83 -0
  161. data/lib/bel_parser/language/version2_0/functions/complex_abundance.rb +190 -0
  162. data/lib/bel_parser/language/version2_0/functions/composite_abundance.rb +81 -0
  163. data/lib/bel_parser/language/version2_0/functions/degradation.rb +83 -0
  164. data/lib/bel_parser/language/version2_0/functions/fragment.rb +116 -0
  165. data/lib/bel_parser/language/version2_0/functions/from_location.rb +85 -0
  166. data/lib/bel_parser/language/version2_0/functions/fusion.rb +203 -0
  167. data/lib/bel_parser/language/version2_0/functions/gene_abundance.rb +192 -0
  168. data/lib/bel_parser/language/version2_0/functions/list.rb +114 -0
  169. data/lib/bel_parser/language/version2_0/functions/location.rb +83 -0
  170. data/lib/bel_parser/language/version2_0/functions/micro_rna_abundance.rb +163 -0
  171. data/lib/bel_parser/language/version2_0/functions/molecular_activity.rb +86 -0
  172. data/lib/bel_parser/language/version2_0/functions/pathology.rb +83 -0
  173. data/lib/bel_parser/language/version2_0/functions/products.rb +79 -0
  174. data/lib/bel_parser/language/version2_0/functions/protein_abundance.rb +270 -0
  175. data/lib/bel_parser/language/version2_0/functions/protein_modification.rb +172 -0
  176. data/lib/bel_parser/language/version2_0/functions/reactants.rb +79 -0
  177. data/lib/bel_parser/language/version2_0/functions/reaction.rb +86 -0
  178. data/lib/bel_parser/language/version2_0/functions/rna_abundance.rb +192 -0
  179. data/lib/bel_parser/language/version2_0/functions/to_location.rb +84 -0
  180. data/lib/bel_parser/language/version2_0/functions/translocation.rb +91 -0
  181. data/lib/bel_parser/language/version2_0/functions/variant.rb +80 -0
  182. data/lib/bel_parser/language/version2_0/relationships/acts_in.rb +61 -0
  183. data/lib/bel_parser/language/version2_0/relationships/analogous.rb +45 -0
  184. data/lib/bel_parser/language/version2_0/relationships/association.rb +42 -0
  185. data/lib/bel_parser/language/version2_0/relationships/biomarker_for.rb +46 -0
  186. data/lib/bel_parser/language/version2_0/relationships/causes_no_change.rb +50 -0
  187. data/lib/bel_parser/language/version2_0/relationships/decreases.rb +63 -0
  188. data/lib/bel_parser/language/version2_0/relationships/directly_decreases.rb +56 -0
  189. data/lib/bel_parser/language/version2_0/relationships/directly_increases.rb +56 -0
  190. data/lib/bel_parser/language/version2_0/relationships/has_component.rb +62 -0
  191. data/lib/bel_parser/language/version2_0/relationships/has_components.rb +61 -0
  192. data/lib/bel_parser/language/version2_0/relationships/has_member.rb +48 -0
  193. data/lib/bel_parser/language/version2_0/relationships/has_members.rb +57 -0
  194. data/lib/bel_parser/language/version2_0/relationships/has_modification.rb +54 -0
  195. data/lib/bel_parser/language/version2_0/relationships/has_product.rb +60 -0
  196. data/lib/bel_parser/language/version2_0/relationships/has_variant.rb +54 -0
  197. data/lib/bel_parser/language/version2_0/relationships/includes.rb +59 -0
  198. data/lib/bel_parser/language/version2_0/relationships/increases.rb +63 -0
  199. data/lib/bel_parser/language/version2_0/relationships/is_a.rb +48 -0
  200. data/lib/bel_parser/language/version2_0/relationships/negative_correlation.rb +50 -0
  201. data/lib/bel_parser/language/version2_0/relationships/orthologous.rb +48 -0
  202. data/lib/bel_parser/language/version2_0/relationships/positive_correlation.rb +46 -0
  203. data/lib/bel_parser/language/version2_0/relationships/prognostic_biomarker_for.rb +48 -0
  204. data/lib/bel_parser/language/version2_0/relationships/rate_limiting_step_of.rb +53 -0
  205. data/lib/bel_parser/language/version2_0/relationships/reactant_in.rb +60 -0
  206. data/lib/bel_parser/language/version2_0/relationships/regulates.rb +51 -0
  207. data/lib/bel_parser/language/version2_0/relationships/sub_process_of.rb +55 -0
  208. data/lib/bel_parser/language/version2_0/relationships/transcribed_to.rb +53 -0
  209. data/lib/bel_parser/language/version2_0/relationships/translated_to.rb +54 -0
  210. data/lib/bel_parser/language/version2_0/relationships/translocates.rb +57 -0
  211. data/lib/bel_parser/language/version2_0/return_types/abundance.rb +20 -0
  212. data/lib/bel_parser/language/version2_0/return_types/activity.rb +20 -0
  213. data/lib/bel_parser/language/version2_0/return_types/any.rb +74 -0
  214. data/lib/bel_parser/language/version2_0/return_types/biological_process.rb +17 -0
  215. data/lib/bel_parser/language/version2_0/return_types/complex_abundance.rb +17 -0
  216. data/lib/bel_parser/language/version2_0/return_types/fragment.rb +20 -0
  217. data/lib/bel_parser/language/version2_0/return_types/from_location.rb +20 -0
  218. data/lib/bel_parser/language/version2_0/return_types/fusion.rb +17 -0
  219. data/lib/bel_parser/language/version2_0/return_types/gene_abundance.rb +17 -0
  220. data/lib/bel_parser/language/version2_0/return_types/list.rb +17 -0
  221. data/lib/bel_parser/language/version2_0/return_types/location.rb +20 -0
  222. data/lib/bel_parser/language/version2_0/return_types/micro_rna_abundance.rb +17 -0
  223. data/lib/bel_parser/language/version2_0/return_types/molecular_activity.rb +20 -0
  224. data/lib/bel_parser/language/version2_0/return_types/pathology.rb +17 -0
  225. data/lib/bel_parser/language/version2_0/return_types/products.rb +17 -0
  226. data/lib/bel_parser/language/version2_0/return_types/protein_abundance.rb +17 -0
  227. data/lib/bel_parser/language/version2_0/return_types/protein_modification.rb +17 -0
  228. data/lib/bel_parser/language/version2_0/return_types/reactants.rb +17 -0
  229. data/lib/bel_parser/language/version2_0/return_types/rna_abundance.rb +17 -0
  230. data/lib/bel_parser/language/version2_0/return_types/to_location.rb +20 -0
  231. data/lib/bel_parser/language/version2_0/return_types/variant.rb +20 -0
  232. data/lib/bel_parser/language/version2_0/value_encodings/abundance.rb +21 -0
  233. data/lib/bel_parser/language/version2_0/value_encodings/activity.rb +21 -0
  234. data/lib/bel_parser/language/version2_0/value_encodings/any.rb +74 -0
  235. data/lib/bel_parser/language/version2_0/value_encodings/biological_process.rb +21 -0
  236. data/lib/bel_parser/language/version2_0/value_encodings/complex_abundance.rb +21 -0
  237. data/lib/bel_parser/language/version2_0/value_encodings/gene_abundance.rb +21 -0
  238. data/lib/bel_parser/language/version2_0/value_encodings/location.rb +21 -0
  239. data/lib/bel_parser/language/version2_0/value_encodings/micro_rna_abundance.rb +21 -0
  240. data/lib/bel_parser/language/version2_0/value_encodings/pathology.rb +21 -0
  241. data/lib/bel_parser/language/version2_0/value_encodings/protein_abundance.rb +21 -0
  242. data/lib/bel_parser/language/version2_0/value_encodings/protein_modification.rb +21 -0
  243. data/lib/bel_parser/language/version2_0/value_encodings/rna_abundance.rb +21 -0
  244. data/lib/bel_parser/mixin/line_continuator.rb +15 -0
  245. data/lib/bel_parser/mixin/line_mapping.rb +14 -0
  246. data/lib/bel_parser/parsers/ast/node.rb +987 -0
  247. data/lib/bel_parser/parsers/ast/sexp.rb +8 -0
  248. data/lib/bel_parser/parsers/bel_script.rb +5 -0
  249. data/lib/bel_parser/parsers/bel_script/define_annotation.rb +5920 -0
  250. data/lib/bel_parser/parsers/bel_script/define_annotation.rl +141 -0
  251. data/lib/bel_parser/parsers/bel_script/define_namespace.rb +1780 -0
  252. data/lib/bel_parser/parsers/bel_script/define_namespace.rl +121 -0
  253. data/lib/bel_parser/parsers/bel_script/set.rb +5008 -0
  254. data/lib/bel_parser/parsers/bel_script/set.rl +116 -0
  255. data/lib/bel_parser/parsers/bel_script/set_document.rb +7722 -0
  256. data/lib/bel_parser/parsers/bel_script/set_document.rl +97 -0
  257. data/lib/bel_parser/parsers/bel_script/unset.rb +706 -0
  258. data/lib/bel_parser/parsers/bel_script/unset.rl +95 -0
  259. data/lib/bel_parser/parsers/common.rb +5 -0
  260. data/lib/bel_parser/parsers/common/blank_line.rb +211 -0
  261. data/lib/bel_parser/parsers/common/blank_line.rl +81 -0
  262. data/lib/bel_parser/parsers/common/comment_line.rb +245 -0
  263. data/lib/bel_parser/parsers/common/comment_line.rl +97 -0
  264. data/lib/bel_parser/parsers/common/common.rb +7 -0
  265. data/lib/bel_parser/parsers/common/common.rl +13 -0
  266. data/lib/bel_parser/parsers/common/identifier.rb +289 -0
  267. data/lib/bel_parser/parsers/common/identifier.rl +106 -0
  268. data/lib/bel_parser/parsers/common/list.rb +2388 -0
  269. data/lib/bel_parser/parsers/common/list.rl +146 -0
  270. data/lib/bel_parser/parsers/common/string.rb +271 -0
  271. data/lib/bel_parser/parsers/common/string.rl +107 -0
  272. data/lib/bel_parser/parsers/expression.rb +7 -0
  273. data/lib/bel_parser/parsers/expression/comment.rb +239 -0
  274. data/lib/bel_parser/parsers/expression/comment.rl +97 -0
  275. data/lib/bel_parser/parsers/expression/nested_statement.rb +17802 -0
  276. data/lib/bel_parser/parsers/expression/nested_statement.rl +141 -0
  277. data/lib/bel_parser/parsers/expression/observed_term.rb +7291 -0
  278. data/lib/bel_parser/parsers/expression/observed_term.rl +92 -0
  279. data/lib/bel_parser/parsers/expression/parameter.rb +1506 -0
  280. data/lib/bel_parser/parsers/expression/parameter.rl +97 -0
  281. data/lib/bel_parser/parsers/expression/relationship.rb +254 -0
  282. data/lib/bel_parser/parsers/expression/relationship.rl +98 -0
  283. data/lib/bel_parser/parsers/expression/simple_statement.rb +10475 -0
  284. data/lib/bel_parser/parsers/expression/simple_statement.rl +112 -0
  285. data/lib/bel_parser/parsers/expression/term.rb +3989 -0
  286. data/lib/bel_parser/parsers/expression/term.rl +157 -0
  287. data/lib/bel_parser/parsers/line_parser.rb +92 -0
  288. data/lib/bel_parser/parsers/mixin/buffer.rb +10 -0
  289. data/lib/bel_parser/parsers/nonblocking_io_wrapper.rb +50 -0
  290. data/lib/bel_parser/parsers/serializer.rb +205 -0
  291. data/lib/bel_parser/quoting.rb +177 -0
  292. data/lib/bel_parser/resource/concept.rb +56 -0
  293. data/lib/bel_parser/resource/concept_scheme.rb +35 -0
  294. data/lib/bel_parser/resource/dataset.rb +34 -0
  295. data/lib/bel_parser/resource/eager_reader.rb +89 -0
  296. data/lib/bel_parser/resource/eager_sparql_reader.rb +51 -0
  297. data/lib/bel_parser/resource/file_resource.rb +21 -0
  298. data/lib/bel_parser/resource/file_resource_value.rb +24 -0
  299. data/lib/bel_parser/resource/jena_tdb_reader.rb +246 -0
  300. data/lib/bel_parser/resource/lru_cache.rb +111 -0
  301. data/lib/bel_parser/resource/lru_reader.rb +34 -0
  302. data/lib/bel_parser/resource/reader.rb +18 -0
  303. data/lib/bel_parser/resource/resource_url_reader.rb +181 -0
  304. data/lib/bel_parser/resource/sparql_reader.rb +179 -0
  305. data/lib/bel_parser/resource/value.rb +31 -0
  306. data/lib/bel_parser/script.rb +8 -0
  307. data/lib/bel_parser/script/filter.rb +35 -0
  308. data/lib/bel_parser/script/first_node.rb +21 -0
  309. data/lib/bel_parser/script/keywords.rb +32 -0
  310. data/lib/bel_parser/script/nanopub_mapper.rb +182 -0
  311. data/lib/bel_parser/script/parser.rb +51 -0
  312. data/lib/bel_parser/script/state/annotation_definition.rb +62 -0
  313. data/lib/bel_parser/script/state/bel_version.rb +36 -0
  314. data/lib/bel_parser/script/state/document_property.rb +29 -0
  315. data/lib/bel_parser/script/state/namespace_definition.rb +32 -0
  316. data/lib/bel_parser/script/state/set.rb +82 -0
  317. data/lib/bel_parser/script/state/unset.rb +46 -0
  318. data/lib/bel_parser/script/state_aggregator.rb +49 -0
  319. data/lib/bel_parser/script/state_function.rb +10 -0
  320. data/lib/bel_parser/script/syntax/expression_validation.rb +46 -0
  321. data/lib/bel_parser/script/syntax/invalid_regex_pattern.rb +49 -0
  322. data/lib/bel_parser/script/syntax/undefined_annotation.rb +61 -0
  323. data/lib/bel_parser/script/syntax/undefined_annotation_value.rb +84 -0
  324. data/lib/bel_parser/script/syntax/unresolvable_namespace.rb +54 -0
  325. data/lib/bel_parser/script/syntax/unsupported_bel_version.rb +59 -0
  326. data/lib/bel_parser/script/validator.rb +65 -0
  327. data/lib/bel_parser/vendor/ast.rb +17 -0
  328. data/lib/bel_parser/vendor/ast/node.rb +254 -0
  329. data/lib/bel_parser/vendor/ast/processor.rb +12 -0
  330. data/lib/bel_parser/vendor/ast/processor/mixin.rb +282 -0
  331. data/lib/bel_parser/vendor/ast/sexp.rb +30 -0
  332. metadata +390 -0
@@ -0,0 +1,21 @@
1
+ require_relative '../../version2_0'
2
+ require_relative 'abundance'
3
+
4
+ module BELParser
5
+ module Language
6
+ module Version2_0
7
+ module ValueEncodings
8
+ # GeneAbundance value encoding.
9
+ class GeneAbundance < Abundance
10
+ # Return the {Symbol} value.
11
+ #
12
+ # @note This method should be overridden in subclasses.
13
+ def self.to_sym
14
+ raise_not_implemented(__method__) if self != GeneAbundance
15
+ :G
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../../version2_0'
2
+ require_relative 'any'
3
+
4
+ module BELParser
5
+ module Language
6
+ module Version2_0
7
+ module ValueEncodings
8
+ # Location value encoding.
9
+ class Location < Any
10
+ # Return the {Symbol} value.
11
+ #
12
+ # @note This method should be overridden in subclasses.
13
+ def self.to_sym
14
+ raise_not_implemented(__method__) if self != Location
15
+ :L
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../../version2_0'
2
+ require_relative 'rna_abundance'
3
+
4
+ module BELParser
5
+ module Language
6
+ module Version2_0
7
+ module ValueEncodings
8
+ # Micro RNA abundance value encoding.
9
+ class MicroRNAAbundance < RNAAbundance
10
+ # Return the {Symbol} value.
11
+ #
12
+ # @note This method should be overridden in subclasses.
13
+ def self.to_sym
14
+ raise_not_implemented(__method__) if self != MicroRNAAbundance
15
+ :M
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../../version2_0'
2
+ require_relative 'biological_process'
3
+
4
+ module BELParser
5
+ module Language
6
+ module Version2_0
7
+ module ValueEncodings
8
+ # Pathology value encoding.
9
+ class Pathology < BiologicalProcess
10
+ # Return the {Symbol} value.
11
+ #
12
+ # @note This method should be overridden in subclasses.
13
+ def self.to_sym
14
+ raise_not_implemented(__method__) if self != Pathology
15
+ :O
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../../version2_0'
2
+ require_relative 'abundance'
3
+
4
+ module BELParser
5
+ module Language
6
+ module Version2_0
7
+ module ValueEncodings
8
+ # ProteinAbundance value encoding.
9
+ class ProteinAbundance < Abundance
10
+ # Return the {Symbol} value.
11
+ #
12
+ # @note This method should be overridden in subclasses.
13
+ def self.to_sym
14
+ raise_not_implemented(__method__) if self != ProteinAbundance
15
+ :P
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../../version2_0'
2
+ require_relative 'any'
3
+
4
+ module BELParser
5
+ module Language
6
+ module Version2_0
7
+ module ValueEncodings
8
+ # ProteinModification value encoding.
9
+ class ProteinModification < Any
10
+ # Return the {Symbol} value.
11
+ #
12
+ # @note This method should be overridden in subclasses.
13
+ def self.to_sym
14
+ raise_not_implemented(__method__) if self != ProteinModification
15
+ :E
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../../version2_0'
2
+ require_relative 'abundance'
3
+
4
+ module BELParser
5
+ module Language
6
+ module Version2_0
7
+ module ValueEncodings
8
+ # RNAAbundance value encoding.
9
+ class RNAAbundance < Abundance
10
+ # Return the {Symbol} value.
11
+ #
12
+ # @note This method should be overridden in subclasses.
13
+ def self.to_sym
14
+ raise_not_implemented(__method__) if self != RNAAbundance
15
+ :R
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ module BELParser
2
+ # LineContinuator is a mixin for line expansions for BEL Script.
3
+ module LineContinuator
4
+ LINE_CONTINUATOR = "\\\n".freeze
5
+
6
+ def expand_line_continuator(line_enumerator)
7
+ line = line_enumerator.next
8
+ while line.end_with?(LINE_CONTINUATOR)
9
+ line.chomp!(LINE_CONTINUATOR)
10
+ line += line_enumerator.next
11
+ end
12
+ line
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module BELParser
2
+ # LineMapping module.
3
+ module LineMapping
4
+ def normalize_line_terminator(line)
5
+ return nil unless line
6
+ line.sub(/[\r\n]+$/, '') + "\n"
7
+ end
8
+
9
+ def map_lines(line_enumerator)
10
+ line_enumerator
11
+ .map { |line| normalize_line_terminator(line) }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,987 @@
1
+ require 'bel_parser/vendor/ast'
2
+
3
+ module BELParser
4
+ module Parsers
5
+ # BEL AST module.
6
+ module AST
7
+ # @raise ArgumentError if _argument_ is not _expected_
8
+ def self.assert_is_a(expected, actual, argument)
9
+ msg = ->(x, y, z) { "Expected #{x} of #{y}, but got #{z}" }
10
+ return if actual.is_a? expected
11
+ raise ArgumentError, msg.call(expected, argument, actual.class)
12
+ end
13
+
14
+ # BEL application-specific AST node.
15
+ #
16
+ # All BEL AST nodes have a basic set of properties. Additional
17
+ # properties may be specified by subclasses. Each class in
18
+ # the hierarchy describes its type through the class variable
19
+ # _ast_type_. This is equivalent to its _type_ instance variable
20
+ # but the former is not used by the AST library itself.
21
+ #
22
+ # @see Node.ast_type
23
+ # @see Node.initialize
24
+ #
25
+ class Node < ::AST::Node
26
+ # AST node type
27
+ @ast_type = :node
28
+ # Basic AST node has no meaning
29
+ @has_semantics = false
30
+
31
+ # New BEL AST node.
32
+ #
33
+ # @param [Symbol] type The node type symbol @param [Array]
34
+ # children Optional children of node @param [Hash] properties
35
+ # Optional supported node properties
36
+ #
37
+ # === Supported properties - +line_number+ -> {#line_number} -
38
+ # +character_range+ -> {#character_range}, {#range_start},
39
+ # {#range_end}
40
+ # - +complete+ -> {#complete?}
41
+ #
42
+ # @raise ArgumentError If _children_ is not an Array or
43
+ # _properties_
44
+ # is not a Hash
45
+ def initialize(type, children = [], properties = {})
46
+ AST.assert_is_a(Array, children, 'children')
47
+ AST.assert_is_a(Hash, properties, 'properties')
48
+ super(type, children, properties)
49
+ end
50
+
51
+ # Get the class AST node type. @return [Symbol]
52
+ class << self; attr_reader :ast_type end
53
+
54
+ # Get whether this class AST node has semantics. @return
55
+ # [boolean]
56
+ class << self; attr_reader :has_semantics end
57
+
58
+ # Get the line number where this AST node originates.
59
+ attr_reader :line_number
60
+
61
+ # Get the character range enclosing this AST node. It is defined
62
+ # as the close interval containing all the characters of this
63
+ # AST node.
64
+ attr_reader :character_range
65
+
66
+ # Get/Set the complete property.
67
+ attr_accessor :complete
68
+
69
+ # Get the syntax errors for this AST node.
70
+ def syntax_errors
71
+ (@syntax_errors ||= [])
72
+ end
73
+
74
+ # Add a syntax error to thie AST node.
75
+ def add_syntax_error(syntax_error)
76
+ syntax_errors << syntax_error
77
+ end
78
+
79
+ # Get the start of the character range enclosing this AST node.
80
+ def range_start
81
+ @character_range[0]
82
+ end
83
+
84
+ # Get _a_ in the character range [a, b].
85
+ alias range_a range_start
86
+
87
+ # Get the end of the character range enclosing this AST node.
88
+ def range_end
89
+ @character_range[1]
90
+ end
91
+
92
+ # Get _b_ in the character range [a, b].
93
+ alias range_b range_end
94
+
95
+ # Get whether the AST node can be considered _complete_.
96
+ def complete?
97
+ @complete
98
+ end
99
+
100
+ # Get whether the AST node should be considered _incomplete_.
101
+ def incomplete?
102
+ !@complete
103
+ end
104
+
105
+ def traverse(&block)
106
+ if block_given?
107
+ yield self
108
+ children.each do |child_node|
109
+ child_node.traverse(&block) if child_node.respond_to?(:traverse)
110
+ end
111
+ else
112
+ enum_for(:traverse)
113
+ end
114
+ end
115
+
116
+ def freeze
117
+ # no freeze...nothing I want to be able to modify properties!
118
+ self
119
+ end
120
+
121
+ def updated(children = nil, properties = nil)
122
+ new_children = children || @children
123
+ new_properties = properties || {}
124
+
125
+ if @children == new_children && properties.nil?
126
+ self
127
+ elsif instance_of? Node
128
+ original_dup.send :initialize, @type, new_children, new_properties
129
+ else # self.is_a? Node
130
+ original_dup.send :initialize, new_children, new_properties
131
+ end
132
+ end
133
+
134
+ # Concatenates `array` with `children` and returns the resulting
135
+ # node.
136
+ #
137
+ # @return [Node]
138
+ def concat(array)
139
+ updated(@children + array.to_a)
140
+ end
141
+
142
+ alias + concat
143
+
144
+ # Appends `element` to `children` and returns the resulting node.
145
+ #
146
+ # @return [Node]
147
+ def append(element)
148
+ updated(@children + [element])
149
+ end
150
+
151
+ alias << append
152
+ end
153
+
154
+ # AST node representing a blank line.
155
+ class BlankLine < Node
156
+ # AST node type
157
+ @ast_type = :blank_line
158
+ # Blank lines have no meaning
159
+ @has_semantics = false
160
+
161
+ # New BlankLine AST node.
162
+ #
163
+ # @see Node#initialize Node class for basic properties
164
+ def initialize(children = [], properties = {})
165
+ super(BlankLine.ast_type, children, properties)
166
+ end
167
+ end
168
+
169
+ # AST node representing a statement comment.
170
+ class Comment < Node
171
+ # AST node type
172
+ @ast_type = :comment
173
+ # Comments have no meaning
174
+ @has_semantics = false
175
+
176
+ # New Comment AST node.
177
+ #
178
+ # @see Node#initialize Node class for basic properties
179
+ def initialize(children = [], properties = {})
180
+ super(Comment.ast_type, children, properties)
181
+ end
182
+ end
183
+
184
+ # AST node representing a line comment.
185
+ class CommentLine < Node
186
+ # AST node type
187
+ @ast_type = :comment_line
188
+ # Comment lines have no meaning
189
+ @has_semantics = false
190
+
191
+ # New CommentLine AST node.
192
+ #
193
+ # @see Node#initialize Node class for basic properties
194
+ def initialize(children = [], properties = {})
195
+ super(CommentLine.ast_type, children, properties)
196
+ end
197
+ end
198
+
199
+ # AST node representing the definition of an annotation.
200
+ class AnnotationDefinition < Node
201
+ # AST node type
202
+ @ast_type = :annotation_definition
203
+ # Content is has semantic meaning
204
+ @has_semantics = true
205
+
206
+ # New AnnotationDefinition AST node.
207
+ #
208
+ # @see Node#initialize Node class for basic properties
209
+ def initialize(children = [], properties = {})
210
+ super(AnnotationDefinition.ast_type, children, properties)
211
+ end
212
+
213
+ # Get the annotation definition's keyword.
214
+ def keyword
215
+ children[0]
216
+ end
217
+
218
+ # Get the annotation definition's domain.
219
+ def domain
220
+ children[1]
221
+ end
222
+ end
223
+
224
+ # AST node representing the function of a BEL term.
225
+ #
226
+ # === Special node properties - _return_type_: {#return_type}
227
+ #
228
+ class Function < Node
229
+ # AST node type
230
+ @ast_type = :function
231
+ # Functions have semantic meaning
232
+ @has_semantics = true
233
+
234
+ # New Function AST node.
235
+ #
236
+ # @see Node#initialize Node class for basic properties
237
+ def initialize(children = [], properties = {})
238
+ super(Function.ast_type, children, properties)
239
+ end
240
+
241
+ # Get the function's identifier.
242
+ def identifier
243
+ children[0]
244
+ end
245
+
246
+ # Get the return type property.
247
+ attr_reader :return_type
248
+ end
249
+
250
+ # AST node representing the definition of a namespace.
251
+ class NamespaceDefinition < Node
252
+ # AST node type
253
+ @ast_type = :namespace_definition
254
+ # Namespace definitions have semantic meaning
255
+ @has_semantics = true
256
+
257
+ # New NamespaceDefinition AST node.
258
+ #
259
+ # @see Node#initialize Node class for basic properties
260
+ def initialize(children = [], properties = {})
261
+ super(NamespaceDefinition.ast_type, children, properties)
262
+ end
263
+
264
+ # Get the namespace definition's keyword.
265
+ def keyword
266
+ children[0]
267
+ end
268
+
269
+ # Get the namespace definition's domain.
270
+ def domain
271
+ children[1]
272
+ end
273
+ end
274
+
275
+ # AST node representing a keyword (e.g. definitions).
276
+ class Keyword < Node
277
+ # AST node type
278
+ @ast_type = :keyword
279
+ # Keywords have semantic meaning
280
+ @has_semantics = true
281
+
282
+ # New Keyword AST node.
283
+ #
284
+ # @see Node#initialize Node class for basic properties
285
+ def initialize(children = [], properties = {})
286
+ super(Keyword.ast_type, children, properties)
287
+ end
288
+
289
+ # Get the keyword's identifier.
290
+ def identifier
291
+ children[0]
292
+ end
293
+ end
294
+
295
+ # AST node representing a domain (e.g. Url, Uri, List, Pattern).
296
+ class Domain < Node
297
+ # AST node type
298
+ @ast_type = :domain
299
+ # Domains have semantic meaning
300
+ @has_semantics = true
301
+
302
+ # New Domain AST node.
303
+ #
304
+ # @see Node#initialize Node class for basic properties
305
+ def initialize(children = [], properties = {})
306
+ super(Domain.ast_type, children, properties)
307
+ end
308
+
309
+ # Determine if this is a LIST domain.
310
+ def list?
311
+ children[0] && children[0].is_a?(List)
312
+ end
313
+
314
+ # Determine if this is a PATTERN domain.
315
+ def pattern?
316
+ children[0] && children[0].is_a?(Pattern)
317
+ end
318
+
319
+ # Determine if this is a URL domain.
320
+ def url?
321
+ children[0] && children[0].is_a?(Url)
322
+ end
323
+
324
+ # Get the domain's Url.
325
+ def child
326
+ children[0]
327
+ end
328
+ end
329
+
330
+ # AST node representing a URL.
331
+ class Url < Node
332
+ # AST node type
333
+ @ast_type = :url
334
+ # Urls have semantic meaning
335
+ @has_semantics = true
336
+
337
+ # New Url AST node.
338
+ #
339
+ # @see Node#initialize Node class for basic properties
340
+ def initialize(children = [], properties = {})
341
+ super(Url.ast_type, children, properties)
342
+ end
343
+
344
+ # Get the url's string.
345
+ def string
346
+ children[0]
347
+ end
348
+ end
349
+
350
+ # AST node representing a Pattern.
351
+ class Pattern < Node
352
+ # AST node type
353
+ @ast_type = :pattern
354
+ # Patterns have semantic meaning
355
+ @has_semantics = true
356
+
357
+ # New Pattern AST node.
358
+ #
359
+ # @see Node#initialize Node class for basic properties
360
+ def initialize(children = [], properties = {})
361
+ super(Pattern.ast_type, children, properties)
362
+ end
363
+
364
+ # Get the pattern's string.
365
+ def string
366
+ children[0]
367
+ end
368
+ end
369
+
370
+ # AST node representing the definition of a namespace.
371
+ class Identifier < Node
372
+ # AST node type
373
+ @ast_type = :identifier
374
+ # Identifier have no semantics
375
+ @has_semantics = false
376
+
377
+ # New Identifier AST node.
378
+ #
379
+ # @see Node#initialize Node class for basic properties
380
+ def initialize(children = [], properties = {})
381
+ super(Identifier.ast_type, children, properties)
382
+ end
383
+
384
+ # Get the string literal.
385
+ def string_literal
386
+ children[0]
387
+ end
388
+ end
389
+
390
+ # AST node representing a list.
391
+ class List < Node
392
+ # AST node type
393
+ @ast_type = :list
394
+ # List have semantics (content is meaningful)
395
+ @has_semantics = true
396
+
397
+ # New List AST node.
398
+ #
399
+ # @see Node#initialize Node class for basic properties
400
+ def initialize(children = [], properties = {})
401
+ super(List.ast_type, children, properties)
402
+ end
403
+
404
+ def list_items
405
+ children
406
+ end
407
+ end
408
+
409
+ # AST node representing a list item.
410
+ class ListItem < Node
411
+ # AST node type
412
+ @ast_type = :list_item
413
+ # List items have semantics (content is meaningful)
414
+ @has_semantics = true
415
+
416
+ # New ListItem AST node.
417
+ #
418
+ # @see Node#initialize Node class for basic properties
419
+ def initialize(children = [], properties = {})
420
+ super(ListItem.ast_type, children, properties)
421
+ end
422
+ end
423
+
424
+ # AST node representing an argument.
425
+ class Argument < Node
426
+ # AST node type
427
+ @ast_type = :argument
428
+ # Arguments have semantics (position is meaningful)
429
+ @has_semantics = true
430
+
431
+ # New Argument AST node.
432
+ #
433
+ # @see Node#initialize Node class for basic properties
434
+ def initialize(children = [], properties = {})
435
+ super(Argument.ast_type, children, properties)
436
+ end
437
+
438
+ # Does the argument have a {Parameter} child?
439
+ def parameter?
440
+ children[0].is_a?(Parameter)
441
+ end
442
+
443
+ # Does the argument have a {Term} child?
444
+ def term?
445
+ children[0].is_a?(Term)
446
+ end
447
+
448
+ # Get the {Parameter} or {Term} child.
449
+ def child
450
+ children[0]
451
+ end
452
+ end
453
+
454
+ # AST node representing a parameter.
455
+ #
456
+ # === Special node properties - _namespace_: {#namespace}
457
+ #
458
+ class Prefix < Node
459
+ # AST node type
460
+ @ast_type = :prefix
461
+ # Prefix have semantics (indicates namespace)
462
+ @has_semantics = true
463
+
464
+ # New Prefix AST node.
465
+ #
466
+ # @see Node#initialize Node class for basic properties
467
+ def initialize(children = [], properties = {})
468
+ super(Prefix.ast_type, children, properties)
469
+ end
470
+
471
+ # Get the identifier for the prefix.
472
+ def identifier
473
+ children[0]
474
+ end
475
+
476
+ # Get/Set the namespace property.
477
+ attr_accessor :namespace
478
+ end
479
+
480
+ # AST node representing a parameter.
481
+ class Parameter < Node
482
+ # AST node type
483
+ @ast_type = :parameter
484
+ # Parameters have semantics (encodings, namespaces)
485
+ @has_semantics = true
486
+
487
+ # New Parameter AST node.
488
+ #
489
+ # @see Node#initialize Node class for basic properties
490
+ def initialize(children = [], properties = {})
491
+ super(Parameter.ast_type, children, properties)
492
+ end
493
+
494
+ # Get the prefix for the parameter.
495
+ def prefix
496
+ children[0]
497
+ end
498
+
499
+ # Get the value for the parameter.
500
+ def value
501
+ children[1]
502
+ end
503
+ end
504
+
505
+ # AST node representing a relationship.
506
+ class Relationship < Node
507
+ # AST node type
508
+ @ast_type = :relationship
509
+ # Relationship have no semantics, statements do
510
+ @has_semantics = false
511
+
512
+ # New Relationship AST node.
513
+ #
514
+ # @see Node#initialize Node class for basic properties
515
+ def initialize(children = [], properties = {})
516
+ super(Relationship.ast_type, children, properties)
517
+ end
518
+
519
+ # Get the string literal.
520
+ def string_literal
521
+ children[0]
522
+ end
523
+ end
524
+
525
+ # AST node representing a set.
526
+ class Set < Node
527
+ # AST node type
528
+ @ast_type = :set
529
+ # Set has semantics (what was set?)
530
+ @has_semantics = true
531
+
532
+ # New Set AST node.
533
+ #
534
+ # @see Node#initialize Node class for basic properties
535
+ def initialize(children = [], properties = {})
536
+ super(Set.ast_type, children, properties)
537
+ end
538
+
539
+ # Get what is being set.
540
+ def name
541
+ children[0]
542
+ end
543
+
544
+ # Get the value of what is being set.
545
+ def value
546
+ children[1]
547
+ end
548
+ end
549
+
550
+ # AST node representing a document property (e.g. +SET DOCUMENT
551
+ # ...+).
552
+ class DocumentProperty < Node
553
+ # AST node type
554
+ @ast_type = :document_property
555
+ # DocumentProperty has semantics (what was set?)
556
+ @has_semantics = true
557
+
558
+ # New DocumentProperty AST node.
559
+ #
560
+ # @see Node#initialize Node class for basic properties
561
+ def initialize(children = [], properties = {})
562
+ super(DocumentProperty.ast_type, children, properties)
563
+ end
564
+
565
+ # Get what is being set.
566
+ def name
567
+ children[0]
568
+ end
569
+
570
+ # Get the value of what is being set.
571
+ def value
572
+ children[1]
573
+ end
574
+ end
575
+
576
+ # AST node representing a statement.
577
+ class Statement < Node
578
+ # AST node type
579
+ @ast_type = :statement
580
+ # Statements have semantics
581
+ @has_semantics = true
582
+
583
+ # New Statement AST node.
584
+ #
585
+ # @see Node#initialize Node class for basic properties
586
+ def initialize(children = [], properties = {})
587
+ super(Statement.ast_type, children, properties)
588
+ end
589
+
590
+ # Get the subject of the statement.
591
+ def subject
592
+ children[0]
593
+ end
594
+
595
+ def relationship?
596
+ children[1] && children[1].is_a?(Relationship)
597
+ end
598
+
599
+ # Get the relationship of the nested statement.
600
+ def relationship
601
+ relationship? ? children[1] : nil
602
+ end
603
+
604
+ def object?
605
+ children[2] && children[2].is_a?(Object)
606
+ end
607
+
608
+ # Get the object of the nested statement.
609
+ def object
610
+ object? ? children[2] : nil
611
+ end
612
+
613
+ def comment?
614
+ children[-1] && children[-1].is_a?(Comment)
615
+ end
616
+
617
+ def comment
618
+ comment? ? children[-1] : nil
619
+ end
620
+ end
621
+
622
+ # AST node representing a nested statement.
623
+ class NestedStatement < Node
624
+ # AST node type
625
+ @ast_type = :nested_statement
626
+ # Nested statements have semantics
627
+ @has_semantics = true
628
+
629
+ # New NestedStatement AST node.
630
+ #
631
+ # @see Node#initialize Node class for basic properties
632
+ def initialize(children = [], properties = {})
633
+ super(NestedStatement.ast_type, children, properties)
634
+ end
635
+
636
+ # Get the statement.
637
+ def statement
638
+ children[0]
639
+ end
640
+ end
641
+
642
+ # AST node representing a observed term statement.
643
+ class ObservedTerm < Node
644
+ # AST node type
645
+ @ast_type = :observed_term
646
+ # Observed terms have semantics
647
+ @has_semantics = true
648
+
649
+ # New ObservedTerm AST node.
650
+ #
651
+ # @see Node#initialize Node class for basic properties
652
+ def initialize(children = [], properties = {})
653
+ super(ObservedTerm.ast_type, children, properties)
654
+ end
655
+
656
+ # Get the statement.
657
+ def statement
658
+ children[0]
659
+ end
660
+ end
661
+
662
+ # AST node representing a simple statement.
663
+ class SimpleStatement < Node
664
+ # AST node type
665
+ @ast_type = :simple_statement
666
+ # Simple statements have semantics
667
+ @has_semantics = true
668
+
669
+ # New SimpleStatement AST node.
670
+ #
671
+ # @see Node#initialize Node class for basic properties
672
+ def initialize(children = [], properties = {})
673
+ super(SimpleStatement.ast_type, children, properties)
674
+ end
675
+
676
+ # Get the statement.
677
+ def statement
678
+ children[0]
679
+ end
680
+ end
681
+
682
+ # AST node representing the subject of a statement.
683
+ class Subject < Node
684
+ # AST node type
685
+ @ast_type = :subject
686
+ # Subject have semantics
687
+ @has_semantics = true
688
+
689
+ # New Subject AST node.
690
+ #
691
+ # @see Node#initialize Node class for basic properties
692
+ def initialize(children = [], properties = {})
693
+ super(Subject.ast_type, children, properties)
694
+ end
695
+
696
+ # Get the subject's term.
697
+ def term
698
+ children[0]
699
+ end
700
+ end
701
+
702
+ # AST node representing the object of a statement.
703
+ class Object < Node
704
+ # AST node type
705
+ @ast_type = :object
706
+ # Object have semantics
707
+ @has_semantics = true
708
+
709
+ # New Object AST node.
710
+ #
711
+ # @see Node#initialize Node class for basic properties
712
+ def initialize(children = [], properties = {})
713
+ super(Object.ast_type, children, properties)
714
+ end
715
+
716
+ # Does the object have a {Term} child?
717
+ def term?
718
+ children[0].is_a?(Term)
719
+ end
720
+
721
+ # Does the object have a {Statement} child?
722
+ def statement?
723
+ children[0].is_a?(Statement)
724
+ end
725
+
726
+ # Get the {Term} or {Statement} child.
727
+ def child
728
+ children[0]
729
+ end
730
+ end
731
+
732
+ # AST node representing a UTF-8 encoded string
733
+ class String < Node
734
+ # AST node type
735
+ @ast_type = :string
736
+ # String have no semantic meaning
737
+ @has_semantics = false
738
+
739
+ # New String AST node.
740
+ #
741
+ # @see Node#initialize Node class for basic properties
742
+ def initialize(children = [], properties = {})
743
+ super(String.ast_type, children, properties)
744
+ end
745
+
746
+ # Get the string literal.
747
+ def string_literal
748
+ children[0]
749
+ end
750
+ end
751
+
752
+ # AST node representing a term.
753
+ class Term < Node
754
+ # AST node type
755
+ @ast_type = :term
756
+ # Terms have semantics
757
+ @has_semantics = true
758
+
759
+ # New Term AST node.
760
+ #
761
+ # @see Node#initialize Node class for basic properties
762
+ def initialize(children = [], properties = {})
763
+ super(Term.ast_type, children, properties)
764
+ end
765
+
766
+ # Get the term's function.
767
+ def function
768
+ children[0]
769
+ end
770
+
771
+ # Get the term's arguments.
772
+ def arguments
773
+ children[1..-1]
774
+ end
775
+
776
+ # Get the term's function semantics.
777
+ attr_reader :function_semantics
778
+
779
+ # Sets the term's function semantics.
780
+ def function_semantics=(function_semantics)
781
+ if !function_semantics.nil? &&
782
+ !function_semantics.is_a?(BELParser::Language::Signature)
783
+ raise(
784
+ ArgumentError,
785
+ 'function_semantics: expected nil or Signature')
786
+ end
787
+ assign_properties(function_semantics: function_semantics)
788
+ end
789
+ end
790
+
791
+ # AST node representing an unset.
792
+ class Unset < Node
793
+ # AST node type
794
+ @ast_type = :unset
795
+ # Unset has semantics; what was unset?
796
+ @has_semantics = true
797
+
798
+ # New Unset AST node.
799
+ #
800
+ # @see Node#initialize Node class for basic properties
801
+ def initialize(children = [], properties = {})
802
+ super(Unset.ast_type, children, properties)
803
+ end
804
+
805
+ # Get what is being unset.
806
+ def name
807
+ children[0]
808
+ end
809
+ end
810
+
811
+ # AST node representing a name.
812
+ class Name < Node
813
+ # AST node type
814
+ @ast_type = :name
815
+ # Name has semantics (name of property or annotation).
816
+ @has_semantics = true
817
+
818
+ # New Name AST node.
819
+ #
820
+ # @see Node#initialize Node class for basic properties
821
+ def initialize(children = [], properties = {})
822
+ super(Name.ast_type, children, properties)
823
+ end
824
+
825
+ def identifier
826
+ children[0]
827
+ end
828
+ end
829
+
830
+ # AST node representing a value.
831
+ #
832
+ # === Special node properties - _encoding_: {#encoding}
833
+ #
834
+ class Value < Node
835
+ # AST node type
836
+ @ast_type = :value
837
+ # Values have semantics (encodings)
838
+ @has_semantics = true
839
+
840
+ # New Value AST node.
841
+ #
842
+ # @see Node#initialize Node class for basic properties
843
+ def initialize(children = [], properties = {})
844
+ super(Value.ast_type, children, properties)
845
+ end
846
+
847
+ # Get/Set the namespace prefix.
848
+ attr_accessor :prefix
849
+
850
+ # Get/Set the value's encoding.
851
+ attr_accessor :encoding
852
+
853
+ # Get/Set the value's namespace.
854
+ attr_accessor :namespace
855
+
856
+ # Get/Set the value from the purported namespace.
857
+ attr_accessor :namespace_value
858
+ end
859
+
860
+ # Sexp defines a module that creates {BELParser::Parsers::AST::Node
861
+ # AST nodes} using S-expression syntax.
862
+ #
863
+ # @see https://en.wikipedia.org/wiki/S-expression S-expression
864
+ module Sexp
865
+ def nested_statement(*children)
866
+ NestedStatement.new(children)
867
+ end
868
+
869
+ def simple_statement(*children)
870
+ SimpleStatement.new(children)
871
+ end
872
+
873
+ def observed_term(*children)
874
+ ObservedTerm.new(children)
875
+ end
876
+
877
+ def statement(*children)
878
+ Statement.new(children)
879
+ end
880
+
881
+ def subject(*children)
882
+ Subject.new(children)
883
+ end
884
+
885
+ def object(*children)
886
+ Object.new(children)
887
+ end
888
+
889
+ def relationship(*children)
890
+ Relationship.new(children)
891
+ end
892
+
893
+ def term(*children)
894
+ Term.new(children)
895
+ end
896
+
897
+ def function(*children)
898
+ Function.new(children)
899
+ end
900
+
901
+ def argument(*children)
902
+ Argument.new(children)
903
+ end
904
+
905
+ def parameter(*children)
906
+ Parameter.new(children)
907
+ end
908
+
909
+ def prefix(*children)
910
+ Prefix.new(children)
911
+ end
912
+
913
+ def name(*children)
914
+ Name.new(children)
915
+ end
916
+
917
+ def value(*children)
918
+ Value.new(children)
919
+ end
920
+
921
+ def identifier(*children)
922
+ Identifier.new(children)
923
+ end
924
+
925
+ def string(*children)
926
+ String.new(children)
927
+ end
928
+
929
+ def list(*children)
930
+ List.new(children)
931
+ end
932
+
933
+ def list_item(*children)
934
+ ListItem.new(children)
935
+ end
936
+
937
+ def comment(*children)
938
+ Comment.new(children)
939
+ end
940
+
941
+ def comment_line(*children)
942
+ CommentLine.new(children)
943
+ end
944
+
945
+ def blank_line
946
+ BlankLine.new
947
+ end
948
+
949
+ def set(*children)
950
+ Set.new(children)
951
+ end
952
+
953
+ def unset(*children)
954
+ Unset.new(children)
955
+ end
956
+
957
+ def document_property(*children)
958
+ DocumentProperty.new(children)
959
+ end
960
+
961
+ def annotation_definition(*children)
962
+ AnnotationDefinition.new(children)
963
+ end
964
+
965
+ def namespace_definition(*children)
966
+ NamespaceDefinition.new(children)
967
+ end
968
+
969
+ def keyword(*children)
970
+ Keyword.new(children)
971
+ end
972
+
973
+ def domain(*children)
974
+ Domain.new(children)
975
+ end
976
+
977
+ def url(*children)
978
+ Url.new(children)
979
+ end
980
+
981
+ def pattern(*children)
982
+ Pattern.new(children)
983
+ end
984
+ end
985
+ end
986
+ end
987
+ end