bel_parser 1.0.0.alpha.39-java → 1.0.0.alpha.40-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/bin/bel_debug_ast +75 -0
  4. metadata +3 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7551ea8874262a96c2623bccbc0b78873f9d1f3
4
- data.tar.gz: bd52f9cd988e9eb57fcea386da40ec33b71f7b32
3
+ metadata.gz: 30e9b124b70baa5376df25c5a4bb2bc4c1f71ec3
4
+ data.tar.gz: fcd4c0420366cf1be080fbd375afbd1361095545
5
5
  SHA512:
6
- metadata.gz: 7d348dbd7674466b52d19a357b1561b9e02e6a7748931da8e0a32cee14c0b58fcdf11df308dce3e5f47360f1f15d079c07e967f3739a8098ed2384387675b64e
7
- data.tar.gz: c288f3d3f77eae55d791ce8f272990a3c67b753a3fb7a77a0518cd6048974af9602a21ee01f20d0da79d5a02f85f0bf68f7d9b50b7e1d63a39d070ff93dca88f
6
+ metadata.gz: 1a895fada40d46968dec3e75798f13f29e50e6910c7395368bd55df4613db6441119dc056c9ca70ada8581bb49b02d7fd331f4642bec1238048c58b79c365bf9
7
+ data.tar.gz: 9ba3b8f935d458b5ddcd91f2fe216b49a4a1aab2ad6e4869869053a49d63e1dbc0b74171d40252ed80088ece168b42060f09ecb7d5cccd42c2d13db61d297341
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0.alpha.39
1
+ 1.0.0.alpha.40
data/bin/bel_debug_ast ADDED
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(
3
+ File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib'))
4
+
5
+ require 'optparse'
6
+ require 'bel_parser'
7
+
8
+ options = {}
9
+ OptionParser.new do |opts|
10
+ opts.banner = <<-USAGE.gsub(/^ {4}/, '')
11
+ Debug the AST.
12
+
13
+ Read from a BEL file.
14
+ usage: #$PROGRAM_NAME --file [FILE]
15
+
16
+ Read from standard input.
17
+ usage: #$PROGRAM_NAME
18
+ USAGE
19
+
20
+ opts.on('-f', '--file FILE', 'BEL script file to read.') do |bel|
21
+ options[:file] = bel
22
+ end
23
+
24
+ opts.on('-c', '--[no-]complete', 'Output only complete AST.') do |c|
25
+ options[:complete] = c
26
+ end
27
+ end.parse!
28
+
29
+ file = options[:file]
30
+ io =
31
+ if file
32
+ File.open(file, external_encoding: 'UTF-8')
33
+ else
34
+ $stdin
35
+ end
36
+ puts options[:complete]
37
+
38
+ class ::AST::Node
39
+
40
+ def _metadata
41
+ ivars = instance_variables - [:@type, :@children, :@hash]
42
+ ivars.map { |iv| [iv, instance_variable_get(iv)] }.to_s
43
+ end
44
+ private :_metadata
45
+
46
+ def to_sexp(indent=0)
47
+ indented = " " * indent
48
+ sexp = "#{indented}(#{fancy_type} #{_metadata}"
49
+
50
+ first_node_child = children.index do |child|
51
+ child.is_a?(::AST::Node) || child.is_a?(Array)
52
+ end || children.count
53
+
54
+ children.each_with_index do |child, idx|
55
+ if child.is_a?(::AST::Node) && idx >= first_node_child
56
+ sexp << "\n#{child.to_sexp(indent + 1)}"
57
+ else
58
+ sexp << " #{child.inspect}"
59
+ end
60
+ end
61
+
62
+ sexp << ")"
63
+
64
+ sexp
65
+ end
66
+ end
67
+
68
+ BELParser::ASTGenerator.new(io).each do |result|
69
+ line_number, line, asts = result
70
+ puts line
71
+ asts.each do |ast|
72
+ next if options[:complete] && ast.incomplete?
73
+ puts ast.to_sexp(1)
74
+ end
75
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bel_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.alpha.39
4
+ version: 1.0.0.alpha.40
5
5
  platform: java
6
6
  authors:
7
7
  - Anthony Bargnesi
@@ -42,6 +42,7 @@ dependencies:
42
42
  description: Implements language versions 1.0 and 2.0.
43
43
  email: abargnesi@selventa.com
44
44
  executables:
45
+ - bel_debug_ast
45
46
  - bel2_validator
46
47
  - bel_script_reader
47
48
  extensions: []
@@ -53,6 +54,7 @@ files:
53
54
  - README.md
54
55
  - VERSION
55
56
  - bin/bel2_validator
57
+ - bin/bel_debug_ast
56
58
  - bin/bel_script_reader
57
59
  - lib/bel/translator/plugins/bel_script.rb
58
60
  - lib/bel/translator/plugins/bel_script/bel_citation_serialization.rb