bel_parser 1.0.0.alpha.39 → 1.0.0.alpha.40
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/bin/bel_debug_ast +75 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49dc04e6434ed52aa219e556b0530d85fb76d5c0
|
4
|
+
data.tar.gz: 67394227d0f35686728dec0a69bdef1e8ea29d47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20da1b048d27a0caca8fafa18f94750611112b1ce872308beb0953caa7d2e16c47907196a406a897d3c6ae3c87f440fb83c71175b2731f0a6cec034e86658c0d
|
7
|
+
data.tar.gz: af8d8cad4e43a61b7903a3d2840a158190a44ae4cecb3a61be18188ce4477b0f2f1b7676b7be775c79165bd310f4e2d5e07fd18090538fcc7cb984439934f3d8
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.0.alpha.
|
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.
|
4
|
+
version: 1.0.0.alpha.40
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Bargnesi
|
@@ -28,6 +28,7 @@ dependencies:
|
|
28
28
|
description: Implements language versions 1.0 and 2.0.
|
29
29
|
email: abargnesi@selventa.com
|
30
30
|
executables:
|
31
|
+
- bel_debug_ast
|
31
32
|
- bel2_validator
|
32
33
|
- bel_script_reader
|
33
34
|
extensions: []
|
@@ -39,6 +40,7 @@ files:
|
|
39
40
|
- README.md
|
40
41
|
- VERSION
|
41
42
|
- bin/bel2_validator
|
43
|
+
- bin/bel_debug_ast
|
42
44
|
- bin/bel_script_reader
|
43
45
|
- lib/bel/translator/plugins/bel_script.rb
|
44
46
|
- lib/bel/translator/plugins/bel_script/bel_citation_serialization.rb
|