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,45 @@
1
+ require 'bel_parser/parsers/ast/node'
2
+
3
+ module BELParser
4
+ module Language
5
+ module Semantics
6
+ # ListFunctionSubject implements a {SemanticsFunction} that maps a
7
+ # {BELParser::Parsers::AST::Subject} to {SemanticsWarning} if a _list_
8
+ # {BELParser::Parsers::AST::Term} is used as the
9
+ # {BELParser::Parsers::AST::Subject} of a
10
+ # {BELParser::Parsers::AST::Statement}.
11
+ class ListFunctionSubject
12
+ include SemanticsFunction
13
+
14
+ private_class_method :new
15
+
16
+ def self.map(node, spec, _namespaces)
17
+ return nil unless node.is_a?(BELParser::Parsers::AST::Subject)
18
+
19
+ list_func = spec.function(:list)
20
+ return nil unless list_func
21
+
22
+ func_name = node.term.function.identifier.string_literal
23
+ sub_func = spec.function(func_name.to_sym)
24
+ ListFunctionSubjectWarning.new(node, spec) if sub_func == list_func
25
+ end
26
+ end
27
+
28
+ # ListFunctionSubjectWarning defines a {SemanticsWarning} that indicates
29
+ # that a _list_ {BELParser::Parsers::AST::Term} was used as the
30
+ # {BELParser::Parsers::AST::Subject} of a
31
+ # {BELParser::Parsers::AST::Statement}.
32
+ class ListFunctionSubjectWarning < SemanticsWarning
33
+ def initialize(subject_node, spec)
34
+ super(subject_node, spec)
35
+ end
36
+
37
+ def to_s
38
+ <<-MSG.gsub(/ {12}/, '').delete("\n")
39
+ List term is only valid in the Object of a Statement.
40
+ MSG
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,55 @@
1
+ require 'bel_parser/parsers/ast/node'
2
+
3
+ module BELParser
4
+ module Language
5
+ module Semantics
6
+ # MultipleSubjectObject implements a {SemanticsFunction} that maps a
7
+ # {BELParser::Parsers::AST::Statement} to a {SemanticsWarning} if the
8
+ # subject term is referenced as an argument of the object list term.
9
+ class MultipleSubjectObject
10
+ include SemanticsFunction
11
+
12
+ private_class_method :new
13
+
14
+ def self.map(stmt_node, spec, _namespaces)
15
+ return nil unless stmt_node.is_a?(BELParser::Parsers::AST::Statement)
16
+ return nil if stmt_node.relationship.string_literal.nil?
17
+ rel = spec.relationship(stmt_node.relationship.string_literal.to_sym)
18
+ return nil unless rel.listable?
19
+
20
+ list_func = spec.function(:list)
21
+ return nil unless list_func
22
+ return nil unless stmt_node.object.term?
23
+
24
+ map_subject_object(stmt_node, rel, spec)
25
+ end
26
+
27
+ def self.map_subject_object(stmt_node, rel, spec)
28
+ sub_term = stmt_node.subject.term
29
+ list_term = stmt_node.object.child
30
+
31
+ if list_term.arguments.any? { |arg| sub_term == arg.child }
32
+ MultipleSubjectObjectWarning.new(stmt_node, spec, rel)
33
+ end
34
+ end
35
+ end
36
+
37
+ # Represents a {SemanticsWarning} when a
38
+ # {BELParser::Parsers::AST::Statement} includes the subject term as an
39
+ # argument of an object list term.
40
+ class MultipleSubjectObjectWarning < SemanticsWarning
41
+ def initialize(stmt_node, spec, rel)
42
+ super(stmt_node, spec)
43
+ @rel = rel
44
+ end
45
+
46
+ def to_s
47
+ <<-MSG.gsub(/ {12}/, '').delete("\n")
48
+ A "#{@rel.long}" statement cannot use the subject term as an
49
+ object list() argument.
50
+ MSG
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,50 @@
1
+ require 'bel_parser/parsers/ast/node'
2
+
3
+ module BELParser
4
+ module Language
5
+ module Semantics
6
+ # NonCausalNestedStatement implements a {SemanticsFunction} that maps a
7
+ # nested {BELParser::Parsers::AST::Statement} to {SemanticsWarning} if
8
+ # the relationship is non-causal.
9
+ class NonCausalNestedStatement
10
+ include SemanticsFunction
11
+
12
+ private_class_method :new
13
+
14
+ def self.map(node, spec, _namespaces)
15
+ return nil unless node.is_a?(BELParser::Parsers::AST::Statement)
16
+ return nil unless node.object? && node.object.statement?
17
+
18
+ rel = node.relationship.string_literal.to_sym
19
+ unless spec.causal_relationships.include?(rel)
20
+ NonCausalNestedStatementWarning.new(node, spec, rel)
21
+ end
22
+ end
23
+ end
24
+
25
+ # Represents a {SemanticsWarning} when a nested
26
+ # {BELParser::Parsers::AST::Statement} has a non-causal relationship.
27
+ class NonCausalNestedStatementWarning < SemanticsWarning
28
+ attr_reader :non_causal_relationship
29
+
30
+ def initialize(stmt_node, spec, rel)
31
+ super(stmt_node, spec)
32
+ @non_causal_relationship = spec.relationship(rel)
33
+ end
34
+
35
+ def to_s
36
+ causal_relationships =
37
+ @specification
38
+ .causal_relationships
39
+ .map(&:long)
40
+ .join(', ')
41
+ <<-MSG.gsub(/ {12}/, '')
42
+ Nested statement is not a causal relationship.
43
+ The "#{non_causal_relationship.long}" relationship is not causal.
44
+ Causal Relationships: #{causal_relationships}
45
+ MSG
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,56 @@
1
+ require 'bel_parser/parsers/ast/node'
2
+
3
+ module BELParser
4
+ module Language
5
+ module Semantics
6
+ # NonObjectList implements a {SemanticsFunction} that maps a
7
+ # {BELParser::Parsers::AST::Object} to a {SemanticsWarning} if the
8
+ # object of a multiple relationship *is not* a list term.
9
+ class NonObjectList
10
+ include SemanticsFunction
11
+
12
+ private_class_method :new
13
+
14
+ def self.map(stmt_node, spec, _namespaces)
15
+ return nil unless stmt_node.is_a?(BELParser::Parsers::AST::Statement)
16
+ return nil if stmt_node.relationship.string_literal.nil?
17
+
18
+ list_func = spec.function(:list)
19
+ return nil unless list_func
20
+
21
+ rel = spec.relationship(stmt_node.relationship.string_literal.to_sym)
22
+ return nil unless rel.listable?
23
+
24
+ map_object(stmt_node.object, rel, list_func, spec)
25
+ end
26
+
27
+ def self.map_object(obj_node, rel, list_func, spec)
28
+ return NonObjectListWarning.new(
29
+ obj_node,
30
+ spec,
31
+ rel) unless obj_node.term?
32
+
33
+ obj_func = obj_node.child.function.identifier.string_literal
34
+ NonObjectListWarning.new(
35
+ obj_node,
36
+ spec,
37
+ rel) unless spec.function(obj_func.to_sym) == list_func
38
+ end
39
+ end
40
+
41
+ # Represents a {SemanticsWarning} when a
42
+ # multiple relationship {BELParser::Parsers::AST::Statement} does not
43
+ # reference an object list term.
44
+ class NonObjectListWarning < SemanticsWarning
45
+ def initialize(statement_node, spec, rel)
46
+ super(statement_node, spec)
47
+ @rel = rel
48
+ end
49
+
50
+ def to_s
51
+ %(The "#{@rel.long}" relationship must take a list() object term.)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,44 @@
1
+ require 'bel_parser/parsers/ast/node'
2
+
3
+ module BELParser
4
+ module Language
5
+ module Semantics
6
+ # RelationshipDeprecation implements a {SemanticsFunction} that maps a
7
+ # {BELParser::Parsers::AST::Relationship} to a {SemanticsWarning} if the
8
+ # referenced relationship is deprecated for the
9
+ # {BELParser::Language::Specification}.
10
+ class RelationshipDeprecation
11
+ include SemanticsFunction
12
+
13
+ private_class_method :new
14
+
15
+ def self.map(node, spec, _namespaces)
16
+ return nil unless node.is_a?(BELParser::Parsers::AST::Relationship)
17
+ return nil if node.string_literal.nil?
18
+
19
+ relationship_name = node.string_literal
20
+ rel = spec.relationship(relationship_name.to_sym)
21
+ return nil unless rel
22
+
23
+ RelationshipDeprecationWarning.new(node, spec, rel) if rel.deprecated?
24
+ end
25
+ end
26
+
27
+ # Represents a {SemanticsWarning} when a
28
+ # {BELParser::Parsers::AST::Relationship} references a deprecated
29
+ # relationship for the {BELParser::Language::Specification}.
30
+ class RelationshipDeprecationWarning < SemanticsWarning
31
+ attr_reader :deprecated_relationship
32
+
33
+ def initialize(relationship_node, spec, deprecated_relationship)
34
+ super(relationship_node, spec)
35
+ @deprecated_relationship = deprecated_relationship
36
+ end
37
+
38
+ def to_s
39
+ %(Relationship "#{deprecated_relationship}" is deprecated.)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,60 @@
1
+ require 'bel_parser/parsers/ast/node'
2
+
3
+ module BELParser
4
+ module Language
5
+ module Semantics
6
+ # RelationshipNotListable implements a {SemanticsFunction} that maps a
7
+ # {BELParser::Parsers::AST::Statement} to a {SemanticsWarning} if the
8
+ # relationship cannot be used for multiple terms in a list.
9
+ class RelationshipNotListable
10
+ include SemanticsFunction
11
+
12
+ private_class_method :new
13
+
14
+ def self.map(node, spec, _namespaces)
15
+ return nil unless node.is_a?(BELParser::Parsers::AST::Statement)
16
+ return nil unless node.relationship?
17
+ return nil unless node.object.term?
18
+
19
+ map_statement(node, spec)
20
+ end
21
+
22
+ def self.map_statement(stmt_node, spec)
23
+ list_func = spec.function(:list)
24
+ return nil unless list_func
25
+
26
+ obj_func = stmt_node.object.child.function.identifier.string_literal
27
+ return nil unless spec.function(obj_func.to_sym) == list_func
28
+
29
+ rel = spec.relationship(stmt_node.relationship.string_literal.to_sym)
30
+ return nil unless rel
31
+
32
+ RelationshipNotMultipleWarning.new(stmt_node, spec, rel) unless
33
+ rel.listable?
34
+ end
35
+ end
36
+
37
+ # Represents a {SemanticsWarning} when a statement has a relationship
38
+ # that cannot reference multiple objects.
39
+ class RelationshipNotMultipleWarning < SemanticsWarning
40
+ def initialize(statement_node, spec, rel)
41
+ super(statement_node, spec)
42
+ @rel = rel
43
+ end
44
+
45
+ def to_s
46
+ multiple_relationships =
47
+ @specification
48
+ .listable_relationships
49
+ .map(&:long)
50
+ .join(', ')
51
+ <<-MSG.gsub(/ {12}/, '').strip
52
+ Statement must use a multiple relationship with a list object.
53
+ The "#{@rel.long}" relationship cannot reference multiple objects.
54
+ Multiple Relationships: #{multiple_relationships}
55
+ MSG
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,83 @@
1
+ require 'bel_parser/parsers/ast/node'
2
+
3
+ module BELParser
4
+ module Language
5
+ module Semantics
6
+ # SignatureMapping implements a {SemanticsFunction} that maps
7
+ # a {BELParser::Parsers::AST::Node} to {SemanticsResult} by
8
+ # checking each {BELParser::Language::Signature signature} for
9
+ # the {BELParser::Language::Function}.
10
+ #
11
+ # @see BELParser::Language::Function#signatures
12
+ class SignatureMapping
13
+ include SemanticsFunction
14
+
15
+ private_class_method :new
16
+
17
+ # Map {BELParser::Parsers::AST::Term term} to BEL signatures
18
+ # defined by a {BELParser::Language::Specification}. The mapping
19
+ # includes both successful and failed signature matches.
20
+ def self.map(term_node, spec, _namespaces)
21
+ return nil unless term_node.is_a?(BELParser::Parsers::AST::Term)
22
+
23
+ function_name = term_node.function.identifier.string_literal
24
+ function = spec.function(function_name.to_sym)
25
+ return nil unless function
26
+
27
+ mapsig = method(:map_signature).to_proc.curry[term_node][spec]
28
+ function.signatures.map(&mapsig)
29
+ end
30
+
31
+ def self.map_signature(term_node, spec, signature)
32
+ results = BELParser::Language::Semantics.match(
33
+ term_node,
34
+ signature.semantic_ast,
35
+ spec)
36
+ if results.all?(&:success?)
37
+ SignatureMappingSuccess.new(term_node, spec, signature, results)
38
+ else
39
+ SignatureMappingWarning.new(term_node, spec, signature, results)
40
+ end
41
+ end
42
+ end
43
+
44
+ # SignatureMappingSuccess defines a {SemanticsResult} that indicates
45
+ # a successful signature match.
46
+ class SignatureMappingSuccess < SemanticsResult
47
+ attr_reader :signature
48
+ attr_reader :results
49
+
50
+ def initialize(term_node, spec, signature, results)
51
+ super(term_node, spec)
52
+ @signature = signature
53
+ @results = results
54
+ end
55
+
56
+ def to_s
57
+ <<-MSG.gsub(/ {12}/, '').gsub(/\n$/, '')
58
+ Term matched function signature: #{@signature.string_form}
59
+ MSG
60
+ end
61
+ end
62
+
63
+ # SignatureMappingWarning defines a {SemanticsWarning} that indicates
64
+ # an unsuccessful signature match.
65
+ class SignatureMappingWarning < SemanticsWarning
66
+ attr_reader :signature
67
+ attr_reader :results
68
+
69
+ def initialize(term_node, spec, signature, results)
70
+ super(term_node, spec)
71
+ @signature = signature
72
+ @results = results
73
+ end
74
+
75
+ def to_s
76
+ <<-MSG.gsub(/ {12}/, '').gsub(/\n$/, '')
77
+ Term did not match function signature: #{@signature.string_form}
78
+ MSG
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,784 @@
1
+ require 'bel_parser/quoting'
2
+ require_relative 'semantics_match'
3
+ require_relative 'semantics_result'
4
+ require_relative 'semantics_ast_warnings'
5
+ require_relative '../parsers/ast/node'
6
+
7
+ module BELParser
8
+ module Language
9
+ # Semantics capture BEL version-independent semantics for terms
10
+ # and statements.
11
+ module Semantics
12
+ # rubocop:disable Metrics/MethodLength
13
+ # rubocop:disable Metrics/AbcSize
14
+ def self.match(input_ast, semantic_ast, spec, match_results = [])
15
+ res = semantic_ast.match(input_ast, spec)
16
+ match_results.concat(res)
17
+ if res.flatten.all?(&:success?) && !semantic_ast.terminal?
18
+ return match_results if semantic_ast.children.empty?
19
+
20
+ var_test = semantic_ast.children.any? do |x|
21
+ x.is_a?(SemanticVariadicArguments)
22
+ end
23
+ if var_test
24
+ test_pairs =
25
+ input_ast
26
+ .children
27
+ .zip(semantic_ast.children)
28
+ .select do |pair|
29
+ !pair.include?(nil)
30
+ end
31
+
32
+ test_pairs.each do |(input_child, semantic_child)|
33
+ if semantic_child.is_a?(SemanticVariadicArguments)
34
+ input_children = input_ast.children
35
+ input_arguments =
36
+ input_children[input_children.index(input_child)..-1]
37
+ argument_pattern = semantic_child.children.first
38
+ input_arguments.each do |argument_child|
39
+ res = semantic_child.match(argument_child, spec)
40
+ match_results << res
41
+ if res.all?(&:success?)
42
+ param_or_term = argument_child.children.first
43
+ match(param_or_term, argument_pattern, spec, match_results)
44
+ end
45
+ end
46
+ else
47
+ match(input_child, semantic_child, spec, match_results)
48
+ end
49
+ end
50
+ else
51
+ semantic_ast
52
+ .children
53
+ .zip(input_ast.children)
54
+ .each do |semantic_child, input_child|
55
+ match(input_child, semantic_child, spec, match_results)
56
+ end
57
+ end
58
+ end
59
+ match_results.flatten
60
+ end
61
+
62
+ # Builder contains methods to build semantic AST nodes.
63
+ # A convenient {Builder.build} method allows you to use these
64
+ # methods within a block scope.
65
+ #
66
+ # see Builder.build
67
+ module Builder
68
+ def self.build(&block)
69
+ raise ArgumentError, 'expecting block' unless block_given?
70
+
71
+ builder = _builder_class.new
72
+ builder.instance_eval(&block)
73
+ builder.result
74
+ end
75
+
76
+ def self._builder_class
77
+ Class.new do
78
+ include Builder
79
+
80
+ attr_reader :result
81
+
82
+ def term(function, *arguments, **properties)
83
+ @result = super
84
+ end
85
+ end
86
+ end
87
+ private_class_method :_builder_class
88
+
89
+ def term(function, *arguments, **properties)
90
+ SemanticTerm.new([function, *arguments], **properties)
91
+ end
92
+
93
+ def function(identifier, **properties)
94
+ SemanticFunction.new([identifier], **properties)
95
+ end
96
+
97
+ def argument(param_or_term, **properties)
98
+ cls = param_or_term.class
99
+ if cls != SemanticParameter && cls != SemanticTerm
100
+ raise ArgumentError, 'expected SemanticParameter or SemanticTerm'
101
+ end
102
+
103
+ SemanticArgument.new([param_or_term], **properties)
104
+ end
105
+
106
+ def parameter(prefix, value, **properties)
107
+ SemanticParameter.new([prefix, value], **properties)
108
+ end
109
+
110
+ def identifier(*value_patterns, **properties)
111
+ SemanticIdentifier.new(value_patterns, **properties)
112
+ end
113
+
114
+ def prefix(*prefix_patterns, **properties)
115
+ SemanticPrefix.new(prefix_patterns, **properties)
116
+ end
117
+
118
+ def value(*value_patterns, **properties)
119
+ SemanticValue.new(value_patterns, **properties)
120
+ end
121
+
122
+ def any(**properties)
123
+ SemanticAny.new(**properties)
124
+ end
125
+
126
+ # rubocop:disable Style/PredicateName
127
+ def is_nil(**properties)
128
+ SemanticIsNil.new(**properties)
129
+ end
130
+
131
+ def has_namespace(**properties)
132
+ SemanticHasNamespace.new(**properties)
133
+ end
134
+
135
+ def has_encoding(**properties)
136
+ SemanticHasEncoding.new(**properties)
137
+ end
138
+
139
+ def function_of(*functions, **properties)
140
+ SemanticFunctionOf.new(functions, **properties)
141
+ end
142
+
143
+ def return_type_of(*return_types, **properties)
144
+ SemanticReturnTypeOf.new(return_types, **properties)
145
+ end
146
+
147
+ def namespace_of(*namespaces, **properties)
148
+ SemanticNamespaceOf.new(namespaces, **properties)
149
+ end
150
+
151
+ def encoding_of(*encoding_types, **properties)
152
+ SemanticEncodingOf.new(encoding_types, **properties)
153
+ end
154
+
155
+ def covalent_protein_modification_of(*mod_types, **properties)
156
+ SemanticCovalentProteinModificationOf.new(mod_types, **properties)
157
+ end
158
+
159
+ def amino_acid_of(*amino_acids, **properties)
160
+ SemanticAminoAcidOf.new(amino_acids, **properties)
161
+ end
162
+
163
+ def is_amino_acid_range_pattern(**properties)
164
+ SemanticIsAminoAcidRange.new(**properties)
165
+ end
166
+
167
+ def is_sequence_position(**properties)
168
+ SemanticIsSequencePosition.new(**properties)
169
+ end
170
+
171
+ def variadic_arguments(*params_or_terms, **properties)
172
+ SemanticVariadicArguments.new(params_or_terms, **properties)
173
+ end
174
+ end
175
+
176
+ # SemanticASTNode represents a node in the semantic tree structure.
177
+ class SemanticASTNode < AST::Node
178
+ def initialize(type, children = [], **properties)
179
+ super(type, children, properties)
180
+ end
181
+
182
+ def terminal?
183
+ false
184
+ end
185
+
186
+ protected
187
+
188
+ def updated(_ = nil, children = nil, properties = nil)
189
+ new_children = children || @children
190
+ new_properties = properties || {}
191
+
192
+ if @children == new_children && properties.nil?
193
+ self
194
+ else
195
+ # Maybe change call?
196
+ original_dup.send :initialize, new_children, new_properties
197
+ end
198
+ end
199
+
200
+ def success(node, spec)
201
+ [SemanticsResult.new(node, spec)]
202
+ end
203
+
204
+ def nil_node_warning(node, spec, expected)
205
+ [SemanticsNilNodeWarning.new(node, spec, expected)]
206
+ end
207
+
208
+ def not_nil_node_warning(node, spec)
209
+ [SemanticsNotNilNodeWarning.new(node, spec)]
210
+ end
211
+
212
+ def type_warning(node, spec, expected, actual)
213
+ [SemanticsTypeWarning.new(node, spec, expected, actual)]
214
+ end
215
+
216
+ def argument_length_warning(node, spec, expected, actual)
217
+ [SemanticsArgumentLengthWarning.new(node, spec, expected, actual)]
218
+ end
219
+
220
+ def missing_namespace_warning(node, spec)
221
+ [SemanticsMissingNamespaceWarning.new(node, spec)]
222
+ end
223
+
224
+ def invalid_namespace(node, spec, expected)
225
+ [SemanticsInvalidNamespaceWarning.new(node, spec, expected)]
226
+ end
227
+
228
+ def missing_encoding_warning(node, spec)
229
+ [SemanticsMissingEncodingWarning.new(node, spec)]
230
+ end
231
+
232
+ def invalid_encoding_warning(node, spec, expected)
233
+ [SemanticsInvalidEncodingWarning.new(node, spec, expected)]
234
+ end
235
+
236
+ def invalid_function_warning(node, spec, expected)
237
+ [SemanticsInvalidFunctionWarning.new(node, spec, expected)]
238
+ end
239
+
240
+ def invalid_return_type_warning(node, spec, expected)
241
+ [SemanticsInvalidReturnTypeWarning.new(node, spec, expected)]
242
+ end
243
+
244
+ def invalid_protein_modification_warning(node, spec, expected)
245
+ [SemanticsInvalidProteinModificationWarning.new(node, spec, expected)]
246
+ end
247
+
248
+ def invalid_amino_acid_warning(node, spec, expected)
249
+ [SemanticsInvalidAminoAcidWarning.new(node, spec, expected)]
250
+ end
251
+
252
+ def invalid_amino_acid_range_warning(node, spec)
253
+ [SemanticsInvalidAminoAcidRangeWarning.new(node, spec)]
254
+ end
255
+
256
+ def invalid_sequence_position_warning(node, spec)
257
+ [SemanticsInvalidSequencePositionWarning.new(node, spec)]
258
+ end
259
+ end
260
+
261
+ # AST node for Term is a semantic AST.
262
+ class SemanticTerm < SemanticASTNode
263
+ def initialize(children = [], **properties)
264
+ super(:term, children, properties)
265
+ end
266
+
267
+ def function
268
+ children[0]
269
+ end
270
+
271
+ def variadic_arguments?
272
+ children[1].type == :variadic_arguments
273
+ end
274
+
275
+ def arguments
276
+ children[1..-1]
277
+ end
278
+
279
+ def match(parse_node, spec)
280
+ return nil_node_warning(
281
+ parse_node,
282
+ spec,
283
+ BELParser::Parsers::AST::Term) if parse_node.nil?
284
+ return type_warning(
285
+ parse_node,
286
+ spec,
287
+ BELParser::Parsers::AST::Term,
288
+ parse_node) if parse_node.type != type
289
+
290
+ # Return success if semantic AST does not supply argument patterns.
291
+ if arguments.empty? || variadic_arguments?
292
+ success(parse_node, spec)
293
+ # Or, check argument length.
294
+ elsif arguments.length == parse_node.arguments.length
295
+ success(parse_node, spec)
296
+ else
297
+ argument_length_warning(
298
+ parse_node,
299
+ spec,
300
+ self,
301
+ parse_node)
302
+ end
303
+ end
304
+ end
305
+
306
+ # AST node for Statement is a semantic AST.
307
+ class SemanticStatement < SemanticASTNode
308
+ def initialize(children = [], **properties)
309
+ super(:statement, children, properties)
310
+ end
311
+
312
+ def match(parse_node, spec)
313
+ return nil_node_warning(
314
+ parse_node,
315
+ spec,
316
+ BELParser::Parsers::AST::Statement) if parse_node.nil?
317
+
318
+ if parse_node.type == type
319
+ success(parse_node, spec)
320
+ else
321
+ type_warning(
322
+ parse_node,
323
+ spec,
324
+ BELParser::Parsers::AST::Statement,
325
+ parse_node)
326
+ end
327
+ end
328
+ end
329
+
330
+ # AST node for Parameter is a semantic AST.
331
+ class SemanticParameter < SemanticASTNode
332
+ def initialize(children = [], **properties)
333
+ super(:parameter, children, properties)
334
+ end
335
+
336
+ def match(parse_node, spec)
337
+ return nil_node_warning(
338
+ parse_node,
339
+ spec,
340
+ BELParser::Parsers::AST::Parameter) if parse_node.nil?
341
+
342
+ if parse_node.type == type
343
+ success(parse_node, spec)
344
+ else
345
+ type_warning(
346
+ parse_node,
347
+ spec,
348
+ BELParser::Parsers::AST::Parameter,
349
+ parse_node)
350
+ end
351
+ end
352
+ end
353
+
354
+ # AST node for Function is a semantic AST.
355
+ class SemanticFunction < SemanticASTNode
356
+ def initialize(children = [], **properties)
357
+ super(:function, children, properties)
358
+ end
359
+
360
+ def match(parse_node, spec)
361
+ return nil_node_warning(
362
+ parse_node,
363
+ spec,
364
+ BELParser::Parsers::AST::Function) if parse_node.nil?
365
+
366
+ if parse_node.type == type
367
+ success(parse_node, spec)
368
+ else
369
+ type_warning(
370
+ parse_node,
371
+ spec,
372
+ BELParser::Parsers::AST::Function,
373
+ parse_node)
374
+ end
375
+ end
376
+ end
377
+
378
+ # AST node for Argument is a semantic AST.
379
+ class SemanticArgument < SemanticASTNode
380
+ def initialize(children = [], **properties)
381
+ super(:argument, children, properties)
382
+ end
383
+
384
+ def match(parse_node, spec)
385
+ return nil_node_warning(
386
+ parse_node,
387
+ spec,
388
+ BELParser::Parsers::AST::Argument) if parse_node.nil?
389
+
390
+ if parse_node.type == type
391
+ success(parse_node, spec)
392
+ else
393
+ type_warning(
394
+ parse_node,
395
+ spec,
396
+ BELParser::Parsers::AST::Argument,
397
+ parse_node)
398
+ end
399
+ end
400
+ end
401
+
402
+ # AST node for VariadicArguments is a semantic AST.
403
+ class SemanticVariadicArguments < SemanticASTNode
404
+ def initialize(children = [], **properties)
405
+ super(:variadic_arguments, children, properties)
406
+ end
407
+
408
+ def match(parse_node, spec)
409
+ return nil_node_warning(
410
+ parse_node,
411
+ spec,
412
+ BELParser::Parsers::AST::Argument) if parse_node.nil?
413
+
414
+ if parse_node.type == BELParser::Parsers::AST::Argument.ast_type
415
+ success(parse_node, spec)
416
+ else
417
+ type_warning(
418
+ parse_node,
419
+ spec,
420
+ BELParser::Parsers::AST::Argument,
421
+ parse_node)
422
+ end
423
+ end
424
+ end
425
+
426
+ # AST node for Prefix is a semantic AST.
427
+ class SemanticPrefix < SemanticASTNode
428
+ def initialize(children = [], **properties)
429
+ super(:prefix, children, properties)
430
+ end
431
+
432
+ def terminal?
433
+ true
434
+ end
435
+
436
+ def prefix_patterns
437
+ children
438
+ end
439
+
440
+ def match(parse_node, spec)
441
+ return nil_node_warning(
442
+ parse_node,
443
+ spec,
444
+ BELParser::Parsers::AST::Prefix) if parse_node.nil?
445
+
446
+ if parse_node.type != BELParser::Parsers::AST::Prefix.ast_type
447
+ return type_warning(
448
+ parse_node,
449
+ spec,
450
+ BELParser::Parsers::AST::Prefix,
451
+ parse_node)
452
+ end
453
+
454
+ prefix_patterns.map do |pattern|
455
+ pattern.match(parse_node, spec)
456
+ end
457
+ end
458
+ end
459
+
460
+ # AST node for Value is a semantic AST.
461
+ class SemanticValue < SemanticASTNode
462
+ def initialize(children = [], **properties)
463
+ super(:value, children, properties)
464
+ end
465
+
466
+ def terminal?
467
+ true
468
+ end
469
+
470
+ def value_patterns
471
+ children
472
+ end
473
+
474
+ def match(parse_node, spec)
475
+ return nil_node_warning(
476
+ parse_node,
477
+ spec,
478
+ BELParser::Parsers::AST::Value) if parse_node.nil?
479
+
480
+ if parse_node.type != BELParser::Parsers::AST::Value.ast_type
481
+ return type_warning(
482
+ parse_node,
483
+ spec,
484
+ BELParser::Parsers::AST::Value,
485
+ parse_node)
486
+ end
487
+
488
+ value_patterns.map do |pattern|
489
+ pattern.match(parse_node, spec)
490
+ end
491
+ end
492
+ end
493
+
494
+ # AST node for Nil is a semantic AST.
495
+ class SemanticIsNil < SemanticASTNode
496
+ def initialize(**properties)
497
+ super(:is_nil, [], properties)
498
+ end
499
+
500
+ def terminal?
501
+ true
502
+ end
503
+
504
+ def match(parse_node, spec)
505
+ if parse_node.nil?
506
+ success(parse_node, spec)
507
+ else
508
+ not_nil_node_warning(parse_node, spec)
509
+ end
510
+ end
511
+ end
512
+
513
+ # AST node for Identifier is a semantic AST.
514
+ class SemanticIdentifier < SemanticASTNode
515
+ def initialize(children = [], **properties)
516
+ super(:identifier, children, properties)
517
+ end
518
+
519
+ def terminal?
520
+ true
521
+ end
522
+
523
+ def value_patterns
524
+ children
525
+ end
526
+
527
+ def match(identifier, spec)
528
+ return nil_node_warning(
529
+ identifier,
530
+ spec,
531
+ BELParser::Parsers::AST::Identifier) if identifier.nil?
532
+
533
+ if identifier.type != BELParser::Parsers::AST::Identifier.ast_type
534
+ return type_warning(
535
+ identifier,
536
+ spec,
537
+ BELParser::Parsers::AST::Identifier,
538
+ identifier)
539
+ end
540
+
541
+ value_patterns.map { |pattern| pattern.match(identifier, spec) }
542
+ end
543
+ end
544
+
545
+ # AST node for Any is a semantic AST.
546
+ class SemanticAny < SemanticASTNode
547
+ def initialize(**properties)
548
+ super(:any, [], properties)
549
+ end
550
+
551
+ def match(parse_node, spec)
552
+ success(parse_node, spec)
553
+ end
554
+ end
555
+
556
+ # AST node for HasNamespace is a semantic AST.
557
+ class SemanticHasNamespace < SemanticASTNode
558
+ def initialize(**properties)
559
+ super(:has_namespace, [], properties)
560
+ end
561
+
562
+ def match(prefix, spec)
563
+ if prefix.respond_to?(:namespace) && prefix.namespace
564
+ success(prefix, spec)
565
+ else
566
+ missing_namespace_warning(prefix, spec)
567
+ end
568
+ end
569
+ end
570
+
571
+ # AST node for NamespaceOf is a semantic AST.
572
+ class SemanticNamespaceOf < SemanticASTNode
573
+ def initialize(namespaces, **properties)
574
+ super(:namespace_of, namespaces, properties)
575
+ end
576
+
577
+ def namespaces
578
+ children
579
+ end
580
+
581
+ def match(prefix_node, spec)
582
+ unless prefix_node.respond_to?(:namespace) && prefix_node.namespace
583
+ return invalid_namespace(prefix_node, spec, namespaces)
584
+ end
585
+
586
+ if namespaces.any? { |i| i == :* || i == input_namespace }
587
+ success(prefix_node, spec)
588
+ else
589
+ invalid_namespace(prefix_node, spec, namespaces)
590
+ end
591
+ end
592
+ end
593
+
594
+ # AST node for HasEncoding is a semantic AST.
595
+ class SemanticHasEncoding < SemanticASTNode
596
+ def initialize(**properties)
597
+ super(:has_encoding, [], properties)
598
+ end
599
+
600
+ def match(value_node, spec)
601
+ if value_node.respond_to?(:encoding) && value_node.encoding
602
+ success(value_node, spec)
603
+ else
604
+ missing_encoding_warning(value_node, spec)
605
+ end
606
+ end
607
+ end
608
+
609
+ # AST node for EncodingOf is a semantic AST.
610
+ class SemanticEncodingOf < SemanticASTNode
611
+ def initialize(encodings, **properties)
612
+ super(:encoding_of, encodings, properties)
613
+ end
614
+
615
+ def match_encoding
616
+ children
617
+ end
618
+
619
+ def match(value_node, spec)
620
+ unless value_node.respond_to?(:encoding) && value_node.encoding
621
+ return invalid_encoding_warning(value_node, spec, match_encoding)
622
+ end
623
+
624
+ input = value_node.encoding
625
+ match = match_encoding
626
+ enc_match = input.product(match).any? do |(value_enc, match_enc)|
627
+ value_enc.subtype_of?(match_enc)
628
+ end
629
+
630
+ if enc_match
631
+ success(value_node, spec)
632
+ else
633
+ invalid_encoding_warning(value_node, spec, match_encoding)
634
+ end
635
+ end
636
+ end
637
+
638
+ # AST node for FunctionOf is a semantic AST.
639
+ class SemanticFunctionOf < SemanticASTNode
640
+ def initialize(functions, **properties)
641
+ super(:function_of, functions, properties)
642
+ end
643
+
644
+ def functions
645
+ children
646
+ end
647
+
648
+ def match(identifier, spec)
649
+ return success(identifier, spec) if functions.include?(:*)
650
+
651
+ function = spec.function(identifier.string_literal.to_sym)
652
+ if functions.include?(function)
653
+ success(identifier, spec)
654
+ else
655
+ invalid_function_warning(identifier, spec, functions)
656
+ end
657
+ end
658
+ end
659
+
660
+ # AST node for ReturnTypeOf is a semantic AST.
661
+ class SemanticReturnTypeOf < SemanticASTNode
662
+ def initialize(return_types, **properties)
663
+ super(:return_type_of, return_types, properties)
664
+ end
665
+
666
+ def return_types
667
+ children
668
+ end
669
+
670
+ def match(identifier, spec)
671
+ return success(identifier, spec) if return_types.include?(:*)
672
+
673
+ function = spec.function(identifier.string_literal.to_sym)
674
+ return invalid_return_type_warning(
675
+ identifier,
676
+ spec,
677
+ return_types) unless function
678
+
679
+ if return_types.any? { |rt| function.return_type <= rt }
680
+ success(identifier, spec)
681
+ else
682
+ invalid_return_type_warning(identifier, spec, return_types)
683
+ end
684
+ end
685
+ end
686
+
687
+ # AST node for CovalentProteinModificationOf is a semantic AST.
688
+ class SemanticCovalentProteinModificationOf < SemanticASTNode
689
+ def initialize(mod_types, **properties)
690
+ properties[:hashed] = Hash[mod_types.map { |t| [t, true] }]
691
+ super(:covalent_protein_modification_of, mod_types, properties)
692
+ end
693
+
694
+ def covalent_protein_modification_types
695
+ children
696
+ end
697
+
698
+ def match(value_node, spec)
699
+ string_literal_sym = value_node.children[0].string_literal.to_sym
700
+ return success(value_node, spec) if @hashed[:*]
701
+
702
+ if @hashed.key?(string_literal_sym)
703
+ success(value_node, spec)
704
+ else
705
+ invalid_protein_modification_warning(
706
+ value_node,
707
+ spec,
708
+ @hashed.keys)
709
+ end
710
+ end
711
+ end
712
+
713
+ # AST node for AminoAcidOf is a semantic AST.
714
+ class SemanticAminoAcidOf < SemanticASTNode
715
+ def initialize(amino_acids, **properties)
716
+ properties[:hashed] = Hash[amino_acids.map { |t| [t, true] }]
717
+ super(:amino_acid_of, amino_acids, properties)
718
+ end
719
+
720
+ def amino_acids
721
+ children
722
+ end
723
+
724
+ def match(value_node, spec)
725
+ string_literal_sym = value_node.children[0].string_literal.to_sym
726
+ return success(value_node, spec) if @hashed[:*]
727
+
728
+ if @hashed.key?(string_literal_sym)
729
+ success(value_node, spec)
730
+ else
731
+ invalid_amino_acid_warning(value_node, spec, @hashed.keys)
732
+ end
733
+ end
734
+ end
735
+
736
+ # AST node for IsAminoAcidRange is a semantic AST.
737
+ class SemanticIsAminoAcidRange < SemanticASTNode
738
+ START_STOP = /[1-9][0-9]*_[1-9][0-9]*/
739
+ UNDETERMINED = /[1?]_[?*]/
740
+ UNKNOWN_START_STOP = '?'.freeze
741
+
742
+ include BELParser::Quoting
743
+
744
+ def initialize(**properties)
745
+ super(:is_amino_acid_range, [], properties)
746
+ end
747
+
748
+ def match(value_node, spec)
749
+ string_literal = unquote(value_node.children[0])
750
+ case string_literal
751
+ when START_STOP, UNDETERMINED, UNKNOWN_START_STOP
752
+ success(value_node, spec)
753
+ else
754
+ invalid_amino_acid_range_warning(value_node, spec)
755
+ end
756
+ end
757
+ end
758
+
759
+ # AST node for IsSequencePosition is a semantic AST.
760
+ class SemanticIsSequencePosition < SemanticASTNode
761
+ include BELParser::Quoting
762
+
763
+ def initialize(**properties)
764
+ super(:is_sequence_position, [], properties)
765
+ end
766
+
767
+ def match(value_node, spec)
768
+ string_literal = unquote(value_node.children[0].string_literal)
769
+ integer_position =
770
+ begin
771
+ Integer(string_literal)
772
+ rescue
773
+ nil
774
+ end
775
+ if integer_position && integer_position > 0
776
+ success(value_node, spec)
777
+ else
778
+ invalid_sequence_position_warning(value_node, spec)
779
+ end
780
+ end
781
+ end
782
+ end
783
+ end
784
+ end