dhallish 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f528e78ecd6b920d3a5a3d302e0493a39c09576a5a574c40b4b71c0f41bc9201
4
+ data.tar.gz: 190f7133c192fa5d9836705b48f6d6f0c6884e7f84a4b6d23a23c2eae788402f
5
+ SHA512:
6
+ metadata.gz: b196bb386fa62efdeafb7f698f18ae4a1ec4a6966d6fa251190a240d7affd8395f3fb17e0742d6855a678a94197794641c27a2e001cd08e7a9bca2787db4faf9
7
+ data.tar.gz: ef0e34ffc81493a29591476ca12592b74414cef0fc2f9286ccc9fb44f021ed923b653531a917e5052cdb60c8b3fed2f74a8eb1e0d6b07a1fb36114bfe787c414
data/bin/dhallish ADDED
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ time1 = Time.now
4
+
5
+ this_file = File.realpath(__FILE__)
6
+ require File.expand_path("../lib/dhallish.rb", File.dirname(this_file))
7
+ require 'json'
8
+
9
+ time2 = Time.now
10
+
11
+ pretty_json = false
12
+ show_type = false
13
+ read_from_file = nil
14
+ measure_time = false
15
+
16
+ ARGV.each { |arg|
17
+ case arg
18
+ when "--pretty"
19
+ pretty_json = true
20
+ when "--type"
21
+ show_type = true
22
+ when "--time"
23
+ measure_time = true
24
+ else
25
+ if File.file?(arg)
26
+ read_from_file = arg
27
+ else
28
+ STDERR.puts "usage: dhallish [--type | --pretty] [file.dhall]"
29
+ exit! 1
30
+ end
31
+ end
32
+ }
33
+
34
+ if read_from_file.nil?
35
+ input = $stdin.read
36
+ else
37
+ file = File.open(read_from_file)
38
+ input = file.read
39
+ file.close
40
+ end
41
+
42
+ time3 = Time.now
43
+
44
+ begin
45
+ res, type = Dhallish::evaluate(input)
46
+ rescue DhallError => err
47
+ STDERR.puts err
48
+ exit! 1
49
+ else
50
+ if show_type
51
+ puts type.to_s
52
+ elsif pretty_json
53
+ json = JSON.parse(Dhallish::to_json res)
54
+ puts JSON.pretty_generate(json)
55
+ else
56
+ puts Dhallish::to_json res
57
+ end
58
+ end
59
+
60
+ time4 = Time.now
61
+ if measure_time
62
+ puts ""
63
+ puts "time loading dhallish.rb: #{time2 - time1}"
64
+ puts "time for typecheck+evaluate: #{time4 - time3}"
65
+ end