pione 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/History.txt +11 -0
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/bin/pione-log +5 -0
- data/example/CountChar/CountChar.pione +1 -1
- data/example/SieveOfEratosthenes/SieveOfEratosthenes.pione +39 -38
- data/lib/pione.rb +14 -35
- data/lib/pione/agent/input-generator.rb +38 -40
- data/lib/pione/agent/logger.rb +52 -19
- data/lib/pione/agent/rule-provider.rb +5 -8
- data/lib/pione/agent/task-worker.rb +25 -32
- data/lib/pione/agent/tuple-space-client.rb +22 -14
- data/lib/pione/command.rb +21 -0
- data/lib/pione/command/basic-command.rb +267 -84
- data/lib/pione/command/child-process.rb +21 -18
- data/lib/pione/command/daemon-process.rb +9 -8
- data/lib/pione/command/front-owner-command.rb +8 -25
- data/lib/pione/command/pione-broker.rb +27 -24
- data/lib/pione/command/pione-clean.rb +6 -6
- data/lib/pione/command/pione-client.rb +143 -128
- data/lib/pione/command/pione-log.rb +61 -0
- data/lib/pione/command/pione-relay-account-db.rb +40 -38
- data/lib/pione/command/pione-relay-client-db.rb +38 -42
- data/lib/pione/command/pione-relay.rb +19 -20
- data/lib/pione/command/pione-syntax-checker.rb +70 -45
- data/lib/pione/command/pione-task-worker.rb +56 -66
- data/lib/pione/command/pione-tuple-space-provider.rb +36 -45
- data/lib/pione/command/pione-tuple-space-receiver.rb +34 -32
- data/lib/pione/command/pione-tuple-space-viewer.rb +63 -47
- data/lib/pione/location.rb +10 -0
- data/lib/pione/location/basic-location.rb +272 -0
- data/lib/pione/location/dropbox-location.rb +139 -0
- data/lib/pione/location/ftp-location.rb +156 -0
- data/lib/pione/location/local-location.rb +116 -0
- data/lib/pione/log.rb +10 -0
- data/lib/pione/log/domain-info.rb +72 -0
- data/lib/pione/log/process-log.rb +176 -0
- data/lib/pione/log/process-record.rb +189 -0
- data/lib/pione/log/xes-log.rb +105 -0
- data/lib/pione/model/assignment.rb +88 -80
- data/lib/pione/model/binary-operator.rb +74 -68
- data/lib/pione/model/block.rb +218 -207
- data/lib/pione/model/boolean.rb +123 -112
- data/lib/pione/model/call-rule.rb +72 -65
- data/lib/pione/model/data-expr.rb +596 -290
- data/lib/pione/model/float.rb +108 -103
- data/lib/pione/model/integer.rb +133 -129
- data/lib/pione/model/message.rb +79 -72
- data/lib/pione/model/package.rb +42 -38
- data/lib/pione/model/parameters.rb +265 -236
- data/lib/pione/model/rule-expr.rb +247 -242
- data/lib/pione/model/rule-io.rb +137 -133
- data/lib/pione/model/rule.rb +307 -292
- data/lib/pione/model/string.rb +110 -99
- data/lib/pione/model/variable-table.rb +300 -271
- data/lib/pione/model/variable.rb +88 -83
- data/lib/pione/option.rb +13 -0
- data/lib/pione/option/child-process-option.rb +19 -0
- data/lib/pione/{command-option → option}/common-option.rb +6 -5
- data/lib/pione/option/option-interface.rb +73 -0
- data/lib/pione/{command-option → option}/presence-notifier-option.rb +4 -3
- data/lib/pione/option/task-worker-owner-option.rb +24 -0
- data/lib/pione/{command-option → option}/tuple-space-provider-option.rb +6 -4
- data/lib/pione/option/tuple-space-provider-owner-option.rb +18 -0
- data/lib/pione/option/tuple-space-receiver-option.rb +8 -0
- data/lib/pione/parser/common-parser.rb +3 -2
- data/lib/pione/parser/expr-parser.rb +6 -1
- data/lib/pione/patch/em-ftpd-patch.rb +21 -0
- data/lib/pione/patch/rinda-patch.rb +31 -23
- data/lib/pione/rule-handler/action-handler.rb +35 -25
- data/lib/pione/rule-handler/basic-handler.rb +92 -18
- data/lib/pione/rule-handler/flow-handler.rb +104 -98
- data/lib/pione/rule-handler/root-handler.rb +11 -0
- data/lib/pione/system/common.rb +10 -0
- data/lib/pione/system/file-cache.rb +103 -84
- data/lib/pione/system/global.rb +67 -12
- data/lib/pione/system/init.rb +20 -0
- data/lib/pione/transformer/expr-transformer.rb +6 -1
- data/lib/pione/tuple-space/data-finder.rb +33 -6
- data/lib/pione/tuple-space/tuple-space-receiver.rb +4 -3
- data/lib/pione/tuple-space/tuple-space-server-interface.rb +58 -13
- data/lib/pione/tuple-space/tuple-space-server.rb +13 -11
- data/lib/pione/tuple-space/update-criteria.rb +8 -7
- data/lib/pione/tuple/base-location-tuple.rb +9 -0
- data/lib/pione/tuple/basic-tuple.rb +7 -7
- data/lib/pione/tuple/data-tuple.rb +5 -2
- data/lib/pione/tuple/lift-tuple.rb +14 -0
- data/lib/pione/tuple/rule-tuple.rb +1 -1
- data/lib/pione/tuple/task-tuple.rb +5 -1
- data/lib/pione/version.rb +1 -1
- data/pione.gemspec +5 -1
- data/test/location/spec_basic-location.rb +35 -0
- data/test/location/spec_ftp-location.rb +100 -0
- data/test/location/spec_local-location.rb +99 -0
- data/test/log/data/sample.log +1003 -0
- data/test/log/spec_xes-log.rb +11 -0
- data/test/model/spec_data-expr.rb +249 -6
- data/test/model/spec_data-expr.yml +45 -0
- data/test/parser/spec_expr-parser.yml +4 -0
- data/test/spec_data-finder.rb +13 -7
- data/test/spec_data-finder.yml +42 -13
- data/test/system/spec_file-cache.rb +39 -0
- data/test/test-util.rb +226 -1
- data/test/transformer/spec_expr-transformer.rb +12 -1
- metadata +107 -24
- data/bin/pione-search-log +0 -30
- data/lib/pione/command-option/basic-option.rb +0 -42
- data/lib/pione/command-option/child-process-option.rb +0 -17
- data/lib/pione/command-option/daemon-option.rb +0 -12
- data/lib/pione/command-option/task-worker-owner-option.rb +0 -17
- data/lib/pione/command-option/tuple-space-provider-owner-option.rb +0 -16
- data/lib/pione/command-option/tuple-space-receiver-option.rb +0 -12
- data/lib/pione/command/tuple-space-provider-owner.rb +0 -6
- data/lib/pione/resource/basic-resource.rb +0 -92
- data/lib/pione/resource/dropbox-resource.rb +0 -106
- data/lib/pione/resource/ftp.rb +0 -84
- data/lib/pione/resource/local.rb +0 -113
- data/lib/pione/tuple/base-uri-tuple.rb +0 -9
- data/lib/pione/tuple/shift-tuple.rb +0 -13
- data/lib/pione/util/log.rb +0 -79
- data/test/spec_resource.rb +0 -73
@@ -0,0 +1,61 @@
|
|
1
|
+
module Pione
|
2
|
+
module Command
|
3
|
+
# PioneLog is a command for viewing PIONE log or converting into other formats.
|
4
|
+
class PioneLog < BasicCommand
|
5
|
+
define_info do
|
6
|
+
set_name "pione-log"
|
7
|
+
set_banner "View and convert PIONE log."
|
8
|
+
end
|
9
|
+
|
10
|
+
define_option do
|
11
|
+
default :format, :xes
|
12
|
+
default :trace_filter, []
|
13
|
+
default :output, Location["local:./output"]
|
14
|
+
|
15
|
+
option("--agent-activity[=TYPE]", "output only agent activity log") do |data, name|
|
16
|
+
data[:trace_filter] << Proc.new do |trace|
|
17
|
+
trace.attributes.include?(XES.string("pione:traceType", "agent_activity")) and
|
18
|
+
(name.nil? or trace.events.first.org_resource == name)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
option("--rule-process", "generate rule process log") do |data|
|
23
|
+
data[:trace_filter] << Proc.new do |trace|
|
24
|
+
trace.attributes.include?(XES.string("pione:traceType", "rule_process"))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
option("--task-process", "generate task process log") do |data|
|
29
|
+
data[:trace_filter] << Proc.new do |trace|
|
30
|
+
trace.attributes.include?(XES.string("pione:traceType", "task_process"))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
option("--location=LOCATION", "set log location of PIONE process") do |data, location|
|
35
|
+
data[:output] = Location[location]
|
36
|
+
end
|
37
|
+
|
38
|
+
option("--format=(XES|JSON|HTML)", "set format type") do |data, name|
|
39
|
+
data[:format] = name.downcase.to_sym
|
40
|
+
end
|
41
|
+
|
42
|
+
validate do |data|
|
43
|
+
unless data[:output].exist?
|
44
|
+
abort("File or directory not found in the location: %s" % data[:output].uri.to_s)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
start do
|
50
|
+
Log::ProcessLog[option[:format]].tap do |formatter|
|
51
|
+
if formatter
|
52
|
+
$stdout.puts(formatter.read(option[:output]).format(option[:trace_filter]))
|
53
|
+
$stdout.flush
|
54
|
+
else
|
55
|
+
abort("Unknown format: %s" % option[:format])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -1,63 +1,66 @@
|
|
1
1
|
module Pione
|
2
2
|
module Command
|
3
|
+
# PioneRelayAccountDB is a command that adds, deletes, shows your accounts
|
4
|
+
# of relay servers.
|
3
5
|
class PioneRelayAccountDB < BasicCommand
|
4
|
-
|
6
|
+
define_info do
|
7
|
+
set_name "pione-relay-account-db"
|
8
|
+
set_banner "Add, delete, or show your accounts of relay servers."
|
9
|
+
end
|
5
10
|
|
6
|
-
|
7
|
-
|
8
|
-
|
11
|
+
define_option do
|
12
|
+
option("-a", "--add", "add an account") do |data|
|
13
|
+
data[:action] = :add
|
14
|
+
end
|
9
15
|
|
10
|
-
|
11
|
-
|
12
|
-
|
16
|
+
option("-d", "--delete", "delete an account") do |data|
|
17
|
+
data[:action] = :delete
|
18
|
+
end
|
13
19
|
|
14
|
-
|
15
|
-
|
16
|
-
|
20
|
+
option("-l", "--list", "list accounts") do |data|
|
21
|
+
data[:action] = :list
|
22
|
+
end
|
17
23
|
|
18
|
-
|
19
|
-
|
20
|
-
|
24
|
+
option("-r realm", "--realm realm", "realm name") do |data, realm|
|
25
|
+
data[:realm] = realm
|
26
|
+
end
|
21
27
|
|
22
|
-
|
23
|
-
|
24
|
-
|
28
|
+
option("-u name", "--user name", "user name") do |data, name|
|
29
|
+
data[:name] = name
|
30
|
+
end
|
25
31
|
|
26
|
-
|
27
|
-
|
28
|
-
|
32
|
+
option("-p password", "--password password", "password") do |data, password|
|
33
|
+
data[:password] = password
|
34
|
+
end
|
29
35
|
|
30
|
-
|
31
|
-
|
32
|
-
|
36
|
+
option("-f path", "--file path", "account db path") do |data, path|
|
37
|
+
Global.relay_account_db_path = path
|
38
|
+
end
|
33
39
|
|
34
|
-
|
35
|
-
|
40
|
+
validate do |data|
|
41
|
+
abort("error: -a, -d, or -l") unless data[:action]
|
42
|
+
end
|
36
43
|
end
|
37
44
|
|
38
45
|
def initialize
|
39
|
-
@
|
46
|
+
@realm = nil
|
40
47
|
@name = nil
|
41
48
|
@password = nil
|
42
49
|
end
|
43
50
|
|
44
|
-
|
45
|
-
abort("error: -a, -d, or -l") unless @action
|
46
|
-
end
|
47
|
-
|
48
|
-
def prepare
|
51
|
+
prepare do
|
49
52
|
# set account db
|
50
53
|
Global.relay_account_db = RelayAccountDB.new(Global.relay_account_db_path)
|
51
54
|
|
52
55
|
# set realm
|
53
|
-
if [:add, :delete].include?(
|
54
|
-
@realm = HighLine.new.ask("Realm: ") unless @realm
|
56
|
+
if [:add, :delete].include?(option[:action])
|
57
|
+
@realm = option[:realm] || HighLine.new.ask("Realm: ") unless @realm
|
55
58
|
end
|
56
59
|
|
57
60
|
# set name and password
|
58
|
-
if
|
59
|
-
@name = HighLine.new.ask("Name: ")
|
60
|
-
unless @password
|
61
|
+
if option[:action] == :add
|
62
|
+
@name = option[:name] || HighLine.new.ask("Name: ")
|
63
|
+
unless @password = option[:password]
|
61
64
|
@password = HighLine.new.ask("Password: "){|q| q.echo = "*"}
|
62
65
|
password = HighLine.new.ask("Re-enter password: "){|q| q.echo = "*"}
|
63
66
|
abort("error: password mismatch") unless @password == password
|
@@ -65,9 +68,9 @@ TXT
|
|
65
68
|
end
|
66
69
|
end
|
67
70
|
|
68
|
-
|
71
|
+
start do
|
69
72
|
db = Global.relay_account_db
|
70
|
-
case
|
73
|
+
case option[:action]
|
71
74
|
when :add
|
72
75
|
db.add(@realm, @name, @password)
|
73
76
|
db.save
|
@@ -78,7 +81,6 @@ TXT
|
|
78
81
|
puts "%s accounts in %s" % [db.realms.size, Global.relay_account_db_path]
|
79
82
|
db.realms.each {|realm| puts "%s:%s" % [realm, db[realm].name]}
|
80
83
|
end
|
81
|
-
terminate
|
82
84
|
end
|
83
85
|
end
|
84
86
|
end
|
@@ -1,79 +1,75 @@
|
|
1
1
|
module Pione
|
2
2
|
module Command
|
3
|
+
# PioneRelayClientDB is a command that adds, deletes, or shows clients in
|
4
|
+
# relay server.
|
3
5
|
class PioneRelayClientDB < BasicCommand
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Add, delete, or show clients in this relay server.
|
8
|
-
TXT
|
9
|
-
|
10
|
-
define_option("-a", "--add", "add a client") do
|
11
|
-
@action = :add
|
6
|
+
define_info do
|
7
|
+
set_name "pione-relay-client-db"
|
8
|
+
set_banner "Add, delete, or show clients in this relay server."
|
12
9
|
end
|
13
10
|
|
14
|
-
define_option
|
15
|
-
|
16
|
-
|
11
|
+
define_option do
|
12
|
+
option("-a", "--add", "add a client") do |data|
|
13
|
+
data[:action] = :add
|
14
|
+
end
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
option("-d", "--delete", "delete a client") do |data|
|
17
|
+
data[:action] = :delete
|
18
|
+
end
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
option("-l", "--list", "list clients") do |data|
|
21
|
+
data[:action] = :list
|
22
|
+
end
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
option("-u name", "--user name", "user name") do |data, name|
|
25
|
+
data[:name] = name
|
26
|
+
end
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
option("-p password", "--password password", "password") do |data, password|
|
29
|
+
data[:password] = password
|
30
|
+
end
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
@password = nil
|
38
|
-
end
|
32
|
+
option("-f path", "--file path", "client db path") do |data, path|
|
33
|
+
Global.relay_client_db_path = path
|
34
|
+
end
|
39
35
|
|
40
|
-
|
41
|
-
|
36
|
+
validate do |data|
|
37
|
+
abort("error: -a, -d, or -l") unless data[:action]
|
38
|
+
end
|
42
39
|
end
|
43
40
|
|
44
|
-
|
41
|
+
prepare do
|
45
42
|
# set client db
|
46
43
|
Global.relay_client_db = RelayClientDB.new(Global.relay_client_db_path)
|
47
44
|
|
48
45
|
# set name
|
49
|
-
if [:add, :delete].include?(
|
50
|
-
|
46
|
+
if [:add, :delete].include?(option[:action])
|
47
|
+
option[:name] = HighLine.new.ask("Name: ") unless option[:name]
|
51
48
|
end
|
52
49
|
|
53
50
|
# set password
|
54
|
-
if
|
55
|
-
unless
|
56
|
-
|
51
|
+
if option[:action] == :add
|
52
|
+
unless option[:password]
|
53
|
+
option[:password] = HighLine.new.ask("Password: "){|q| q.echo = "*"}
|
57
54
|
password = HighLine.new.ask("Re-enter password: "){|q| q.echo = "*"}
|
58
|
-
abort("error: password mismatch") unless
|
55
|
+
abort("error: password mismatch") unless option[:password] == password
|
59
56
|
end
|
60
57
|
end
|
61
58
|
end
|
62
59
|
|
63
|
-
|
64
|
-
case
|
60
|
+
start do
|
61
|
+
case option[:action]
|
65
62
|
when :add
|
66
|
-
Global.relay_client_db.add(
|
63
|
+
Global.relay_client_db.add(option[:name], option[:password])
|
67
64
|
Global.relay_client_db.save
|
68
65
|
when :delete
|
69
|
-
Global.relay_client_db.delete(
|
66
|
+
Global.relay_client_db.delete(option[:name])
|
70
67
|
Global.relay_client_db.save
|
71
68
|
when :list
|
72
69
|
names = Global.relay_client_db.names
|
73
70
|
puts "%s clients in %s" % [names.size, Global.relay_client_db_path]
|
74
71
|
names.each {|user| puts user}
|
75
72
|
end
|
76
|
-
terminate
|
77
73
|
end
|
78
74
|
end
|
79
75
|
end
|
@@ -1,42 +1,41 @@
|
|
1
1
|
module Pione
|
2
2
|
module Command
|
3
|
+
# PioneRelay is a command for connecting relay server.
|
3
4
|
class PioneRelay < FrontOwnerCommand
|
4
|
-
|
5
|
-
"
|
5
|
+
define_info do
|
6
|
+
set_name "pione-relay"
|
7
|
+
set_tail {|cmd| "--relay-port %s" % cmd.option[:relay_port]}
|
8
|
+
set_banner "Run relay process for connecting between clients and brokers."
|
6
9
|
end
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
TXT
|
11
|
+
define_option do
|
12
|
+
default :relay_port, Global.relay_port
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
define_option("--relay-port port", "set relay port") do |port|
|
17
|
-
@relay_port = port
|
18
|
-
end
|
14
|
+
option("--realm name", "set relay realm name for client authentification") do |data, name|
|
15
|
+
Global.relay_realm = name
|
16
|
+
end
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
option("--relay-port port", "set relay port") do |data, port|
|
19
|
+
data[:relay_port] = port
|
20
|
+
end
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
validate do |data|
|
23
|
+
abort("error: no realm name") if Global.relay_realm.nil? or Global.relay_realm.empty?
|
24
|
+
abort("error: no relay port") unless data[:relay_port]
|
25
|
+
end
|
27
26
|
end
|
28
27
|
|
29
28
|
def create_front
|
30
29
|
Front::RelayFront.new(self)
|
31
30
|
end
|
32
31
|
|
33
|
-
|
32
|
+
start do
|
34
33
|
# wake up tuple space provider process
|
35
34
|
Pione::TupleSpaceProvider.instance
|
36
35
|
|
37
36
|
puts DRb.front.uri
|
38
37
|
DRb::DRbServer.new(
|
39
|
-
"relay://:%s" %
|
38
|
+
"relay://:%s" % data[:relay_port],
|
40
39
|
nil,
|
41
40
|
{:SSLCertName => Global.relay_ssl_certname}
|
42
41
|
)
|
@@ -1,52 +1,79 @@
|
|
1
1
|
module Pione
|
2
2
|
module Command
|
3
|
+
# PioneSyntaxChecker is a command for checking syntax tree and model of the
|
4
|
+
# PIONE document.
|
3
5
|
class PioneSyntaxChecker < BasicCommand
|
4
|
-
|
6
|
+
define_info do
|
7
|
+
set_name "pione-syntax-checker"
|
8
|
+
set_banner "Print syntax tree of PIONE notation."
|
9
|
+
end
|
5
10
|
|
6
|
-
|
7
|
-
|
8
|
-
|
11
|
+
define_option do
|
12
|
+
default :readline_mode, true
|
13
|
+
default :transform, false
|
9
14
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
15
|
+
option('-e', '--expr=EXPR', 'check the expression string and exit') do |data, e|
|
16
|
+
data[:expr] = e
|
17
|
+
data[:readline_mode] = false
|
18
|
+
end
|
14
19
|
|
15
|
-
|
16
|
-
|
17
|
-
|
20
|
+
option('-t', '--transformer', 'show transformer result') do |data|
|
21
|
+
data[:transform] = true
|
22
|
+
end
|
18
23
|
|
19
|
-
|
20
|
-
|
21
|
-
|
24
|
+
option('-f', '--file=PATH', 'check syntax of the document') do |data, path|
|
25
|
+
data[:document] = path
|
26
|
+
data[:readline_mode] = false
|
27
|
+
end
|
22
28
|
end
|
23
29
|
|
24
30
|
def initialize
|
25
|
-
@
|
31
|
+
@history = File.join(Global.dot_pione_dir, "pione-history")
|
26
32
|
end
|
27
33
|
|
28
|
-
|
34
|
+
prepare do
|
29
35
|
require 'pp'
|
30
|
-
@history = File.join(Global.dot_pione_dir, "pione-history")
|
31
|
-
trap_int
|
32
36
|
end
|
33
37
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
print_result(@expr)
|
43
|
-
end
|
38
|
+
start do
|
39
|
+
case action_mode
|
40
|
+
when :readline
|
41
|
+
action_readline_mode
|
42
|
+
when :file
|
43
|
+
print_result(Pathname.new(option[:document]).read)
|
44
|
+
when :expr
|
45
|
+
print_result(option[:expr])
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
49
|
+
terminate(:pre) do
|
50
|
+
save_history if readline_mode?
|
51
|
+
end
|
52
|
+
|
47
53
|
private
|
48
54
|
|
49
|
-
|
55
|
+
# Return action mode.
|
56
|
+
#
|
57
|
+
# @return [Symbol]
|
58
|
+
# action mode
|
59
|
+
def action_mode
|
60
|
+
return :readline if readline_mode?
|
61
|
+
return :file if option[:document]
|
62
|
+
return :expr if option[:expr]
|
63
|
+
end
|
64
|
+
|
65
|
+
# Return true if readline mode is enabled.
|
66
|
+
#
|
67
|
+
# @return [Boolean]
|
68
|
+
# true if readline mode is enabled
|
69
|
+
def readline_mode?
|
70
|
+
option[:readline_mode]
|
71
|
+
end
|
72
|
+
|
73
|
+
# Action readline mode.
|
74
|
+
#
|
75
|
+
# @return [void]
|
76
|
+
def action_readline_mode
|
50
77
|
require 'readline'
|
51
78
|
restore_history
|
52
79
|
buf = ""
|
@@ -74,40 +101,36 @@ TXT
|
|
74
101
|
# don't record if it is an empty line
|
75
102
|
Readline::HISTORY.pop
|
76
103
|
end
|
77
|
-
# print parsing result
|
78
|
-
print_result(buf)
|
79
104
|
end
|
80
105
|
end
|
81
106
|
|
82
|
-
#
|
107
|
+
# Print parsing result of the string.
|
108
|
+
#
|
109
|
+
# @param str [String]
|
110
|
+
# PIONE expression
|
111
|
+
# @return [void]
|
83
112
|
def print_result(str)
|
84
113
|
begin
|
85
114
|
puts Terminal.green("syntax:")
|
86
115
|
stree = DocumentParser.new.parse(str)
|
87
116
|
pp stree
|
88
|
-
if
|
117
|
+
if option[:transform]
|
89
118
|
puts Terminal.green("model:")
|
90
119
|
pp DocumentTransformer.new.apply(stree)
|
91
120
|
end
|
92
121
|
rescue Pione::Parser::ParserError, Parslet::ParseFailed => e
|
93
122
|
msg = "Pione syntax error: %s (%s)" % [e.message, e.class.name]
|
94
|
-
|
123
|
+
readline_mode? ? puts(msg) : abort(msg)
|
95
124
|
rescue Pione::Model::PioneModelTypeError,
|
96
125
|
Pione::Model::VariableBindingError => e
|
97
126
|
msg = "Pione model error: %s (%s)" % [e.message, e.class.name]
|
98
|
-
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
# Makes trap Ctr+C
|
103
|
-
def trap_int
|
104
|
-
trap("INT") do
|
105
|
-
save_history
|
106
|
-
exit
|
127
|
+
readline_mode? ? puts(msg) : abort(msg)
|
107
128
|
end
|
108
129
|
end
|
109
130
|
|
110
|
-
#
|
131
|
+
# Restore readline's history.
|
132
|
+
#
|
133
|
+
# @return [void]
|
111
134
|
def restore_history
|
112
135
|
if File.exist?(@history)
|
113
136
|
File.readlines(@history).reverse.each do |line|
|
@@ -116,7 +139,9 @@ TXT
|
|
116
139
|
end
|
117
140
|
end
|
118
141
|
|
119
|
-
#
|
142
|
+
# Save history to file.
|
143
|
+
#
|
144
|
+
# @return [void]
|
120
145
|
def save_history
|
121
146
|
File.open(@history, "w+") do |file|
|
122
147
|
Readline::HISTORY.to_a.reverse[0..100].each do |line|
|