pione 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.s3cfg +42 -0
- data/.travis.yml +18 -4
- data/.yardopts +1 -0
- data/Gemfile +3 -0
- data/History.txt +14 -0
- data/Procfile +7 -0
- data/Rakefile +25 -0
- data/bin/pione-interactive +6 -0
- data/bin/{pione-compiler → pione-notification-listener} +1 -1
- data/bin/{pione-broker → pione-task-worker-broker} +1 -1
- data/doc/man/pione-list-param.md +36 -0
- data/example/ActionError/ActionError.pione +9 -0
- data/example/ActionError/pione-package.json +15 -0
- data/example/CountChar/CountChar.pione +1 -1
- data/example/ScoreAggregation/ScoreAggregation.pione +1 -1
- data/example/Touch/pione-package.json +15 -0
- data/lib/pione.rb +12 -0
- data/lib/pione/agent.rb +3 -3
- data/lib/pione/agent/basic-agent.rb +10 -4
- data/lib/pione/agent/input-generator.rb +3 -3
- data/lib/pione/agent/{process-manager.rb → job-manager.rb} +10 -7
- data/lib/pione/agent/job-terminator.rb +2 -2
- data/lib/pione/agent/logger.rb +3 -3
- data/lib/pione/agent/messenger.rb +20 -9
- data/lib/pione/agent/notification-listener.rb +88 -0
- data/lib/pione/agent/task-worker-broker.rb +84 -0
- data/lib/pione/agent/task-worker.rb +3 -2
- data/lib/pione/agent/tuple-space-client.rb +1 -0
- data/lib/pione/agent/tuple-space-provider.rb +17 -35
- data/lib/pione/command.rb +33 -15
- data/lib/pione/command/action.rb +105 -0
- data/lib/pione/command/basic-command.rb +34 -376
- data/lib/pione/command/command-exception.rb +12 -11
- data/lib/pione/command/common.rb +198 -0
- data/lib/pione/command/option.rb +159 -204
- data/lib/pione/command/pione-action-exec.rb +85 -0
- data/lib/pione/command/pione-action-list.rb +43 -19
- data/lib/pione/command/pione-action-print.rb +79 -0
- data/lib/pione/command/pione-action.rb +8 -67
- data/lib/pione/command/pione-clean.rb +88 -68
- data/lib/pione/command/pione-client.rb +475 -332
- data/lib/pione/command/pione-command.rb +14 -31
- data/lib/pione/command/pione-compile.rb +90 -0
- data/lib/pione/command/pione-config-get.rb +53 -0
- data/lib/pione/command/pione-config-list.rb +64 -0
- data/lib/pione/command/pione-config-set.rb +59 -0
- data/lib/pione/command/pione-config-unset.rb +50 -0
- data/lib/pione/command/pione-config.rb +61 -0
- data/lib/pione/command/pione-diagnosis-notification.rb +235 -0
- data/lib/pione/command/pione-diagnosis.rb +21 -0
- data/lib/pione/command/pione-interactive.rb +188 -0
- data/lib/pione/command/pione-lang-check-syntax.rb +163 -0
- data/lib/pione/command/pione-lang-interactive.rb +146 -0
- data/lib/pione/command/pione-lang.rb +22 -0
- data/lib/pione/command/pione-log-format.rb +163 -0
- data/lib/pione/command/pione-log-list-id.rb +48 -0
- data/lib/pione/command/pione-log.rb +19 -101
- data/lib/pione/command/pione-notification-listener.rb +95 -0
- data/lib/pione/command/pione-package-add.rb +137 -0
- data/lib/pione/command/pione-package-build.rb +122 -0
- data/lib/pione/command/pione-package-show.rb +96 -0
- data/lib/pione/command/pione-package-update.rb +59 -0
- data/lib/pione/command/pione-package.rb +11 -139
- data/lib/pione/command/pione-task-worker-broker.rb +88 -0
- data/lib/pione/command/pione-task-worker.rb +148 -98
- data/lib/pione/command/pione-tuple-space-provider.rb +62 -54
- data/lib/pione/command/pione-tuple-space-viewer.rb +105 -83
- data/lib/pione/command/pione-val.rb +39 -39
- data/lib/pione/command/spawner.rb +34 -27
- data/lib/pione/front.rb +4 -2
- data/lib/pione/front/basic-front.rb +86 -23
- data/lib/pione/front/client-front.rb +2 -2
- data/lib/pione/front/diagnosis-notification-front.rb +40 -0
- data/lib/pione/front/front-exception.rb +7 -1
- data/lib/pione/front/notification-listener-front.rb +36 -0
- data/lib/pione/front/notification-recipient-interface.rb +19 -0
- data/lib/pione/front/relay-front.rb +4 -4
- data/lib/pione/front/task-worker-broker-front.rb +19 -0
- data/lib/pione/front/task-worker-front.rb +2 -2
- data/lib/pione/front/tuple-space-provider-front.rb +3 -2
- data/lib/pione/global.rb +3 -1
- data/lib/pione/global/client-variable.rb +1 -1
- data/lib/pione/global/config.rb +63 -7
- data/lib/pione/global/diagnosis-variable.rb +26 -0
- data/lib/pione/global/item.rb +28 -5
- data/lib/pione/global/log-variable.rb +6 -5
- data/lib/pione/global/network-variable.rb +75 -4
- data/lib/pione/global/path-variable.rb +1 -1
- data/lib/pione/global/system-variable.rb +12 -12
- data/lib/pione/global/task-worker-broker-variable.rb +43 -0
- data/lib/pione/global/tuple-space-notifier-variable.rb +3 -55
- data/lib/pione/lang/boolean.rb +4 -0
- data/lib/pione/lang/data-expr.rb +1 -1
- data/lib/pione/lang/integer.rb +1 -1
- data/lib/pione/lang/string.rb +4 -0
- data/lib/pione/lang/type.rb +1 -1
- data/lib/pione/location.rb +1 -0
- data/lib/pione/location/data-location.rb +41 -13
- data/lib/pione/location/dropbox-location.rb +175 -56
- data/lib/pione/location/ftp-location.rb +4 -1
- data/lib/pione/location/http-location.rb +5 -3
- data/lib/pione/location/https-location.rb +4 -2
- data/lib/pione/location/local-location.rb +6 -3
- data/lib/pione/location/location-exception.rb +12 -0
- data/lib/pione/location/notification-scheme.rb +46 -0
- data/lib/pione/log.rb +8 -7
- data/lib/pione/log/debug.rb +9 -9
- data/lib/pione/log/domain-log.rb +6 -1
- data/lib/pione/log/message-log-receiver.rb +32 -0
- data/lib/pione/log/system-log.rb +62 -141
- data/lib/pione/model.rb +7 -0
- data/lib/pione/model/notification-listener-model.rb +29 -0
- data/lib/pione/model/task-worker-broker-model.rb +129 -0
- data/lib/pione/notification.rb +13 -0
- data/lib/pione/notification/address.rb +104 -0
- data/lib/pione/notification/exception.rb +10 -0
- data/lib/pione/notification/message.rb +109 -0
- data/lib/pione/notification/receiver.rb +90 -0
- data/lib/pione/notification/recipient.rb +68 -0
- data/lib/pione/notification/task-worker-broker-recipient.rb +85 -0
- data/lib/pione/notification/transmitter.rb +84 -0
- data/lib/pione/pnml.rb +35 -0
- data/lib/pione/pnml/annotation-extractor.rb +47 -0
- data/lib/pione/pnml/compiler.rb +176 -0
- data/lib/pione/pnml/input-merge-complement.rb +78 -0
- data/lib/pione/pnml/input-parallelization-complement.rb +75 -0
- data/lib/pione/pnml/input-reduction.rb +80 -0
- data/lib/pione/pnml/invalid-arc-elimination.rb +41 -0
- data/lib/pione/pnml/io-expansion.rb +88 -0
- data/lib/pione/pnml/isolated-element-elimination.rb +32 -0
- data/lib/pione/pnml/net-rewriter.rb +44 -0
- data/lib/pione/pnml/output-decomposition-complement.rb +77 -0
- data/lib/pione/pnml/output-reduction.rb +86 -0
- data/lib/pione/pnml/output-synchronization-complement.rb +77 -0
- data/lib/pione/pnml/pione-model.rb +417 -0
- data/lib/pione/pnml/pnml-exception.rb +23 -0
- data/lib/pione/pnml/pnml-model.rb +368 -0
- data/lib/pione/pnml/reader.rb +51 -0
- data/lib/pione/rule-engine/action-handler.rb +8 -6
- data/lib/pione/rule-engine/basic-handler.rb +5 -5
- data/lib/pione/rule-engine/engine-exception.rb +7 -6
- data/lib/pione/rule-engine/flow-handler.rb +27 -18
- data/lib/pione/system.rb +3 -1
- data/lib/pione/system/domain-dump.rb +34 -0
- data/lib/pione/system/file-cache.rb +92 -13
- data/lib/pione/system/init.rb +3 -0
- data/lib/pione/system/normalizer.rb +40 -0
- data/lib/pione/system/status.rb +5 -5
- data/lib/pione/system/system-exception.rb +14 -1
- data/lib/pione/task-worker-broker.rb +7 -0
- data/lib/pione/task-worker-broker/basic-provider.rb +20 -0
- data/lib/pione/task-worker-broker/easy-provider.rb +65 -0
- data/lib/pione/test-helper.rb +27 -0
- data/lib/pione/test-helper/command-helper.rb +9 -101
- data/lib/pione/tuple-space/basic-tuple.rb +1 -1
- data/lib/pione/tuple-space/tuple-definition.yml +4 -6
- data/lib/pione/tuple-space/tuple-space-interface.rb +3 -45
- data/lib/pione/tuple-space/tuple-space-server.rb +45 -0
- data/lib/pione/util.rb +1 -2
- data/lib/pione/util/boolean-value.rb +62 -0
- data/lib/pione/util/completion.rb +111 -0
- data/lib/pione/util/evaluatable.rb +13 -27
- data/lib/pione/util/package-parameters-list.rb +15 -27
- data/lib/pione/util/zip.rb +8 -3
- data/lib/pione/version.rb +1 -1
- data/lib/rootage.rb +20 -0
- data/lib/rootage/action.rb +114 -0
- data/lib/rootage/argument.rb +46 -0
- data/lib/rootage/command.rb +218 -0
- data/lib/rootage/core.rb +532 -0
- data/lib/rootage/exception.rb +107 -0
- data/lib/rootage/help.rb +148 -0
- data/lib/rootage/help.txt.erb +31 -0
- data/lib/rootage/log.rb +226 -0
- data/lib/rootage/normalizer.rb +184 -0
- data/lib/rootage/option.rb +152 -0
- data/lib/rootage/scenario-test-result.erb +39 -0
- data/lib/rootage/scenario.rb +362 -0
- data/lib/rootage/test-helper.rb +115 -0
- data/man/pione-list-param.1 +44 -0
- data/misc/clock.rb +9 -0
- data/misc/machine-info.sh +21 -0
- data/misc/pione-completion.bash +238 -0
- data/misc/pione-completion.erb +53 -0
- data/misc/pione-completion.zsh +238 -0
- data/misc/pione.god +22 -0
- data/misc/ui.xml +23 -0
- data/pione.gemspec +3 -1
- data/test/agent/spec_basic-agent.rb +1 -1
- data/test/agent/spec_input-generator.rb +2 -2
- data/test/agent/spec_messenger.rb +6 -9
- data/test/agent/spec_notification-listener.rb +80 -0
- data/test/agent/{spec_broker.rb → spec_task-worker-broker.rb} +13 -10
- data/test/agent/spec_tuple-space-provider.rb +10 -6
- data/test/command/command-behavior.rb +3 -11
- data/test/command/data/pione-list-param/AdvancedParameters.pione +12 -0
- data/test/command/data/pione-list-param/BasicParameters.pione +12 -0
- data/test/command/spec_pione-action-exec.rb +16 -0
- data/test/command/spec_pione-action-list.rb +15 -10
- data/test/command/spec_pione-action-print.rb +14 -0
- data/test/command/spec_pione-action.rb +6 -19
- data/test/command/spec_pione-clean.rb +29 -46
- data/test/command/spec_pione-client.rb +29 -36
- data/test/command/spec_pione-command.rb +6 -6
- data/test/command/{spec_pione-compiler.rb → spec_pione-compile.rb} +11 -13
- data/test/command/spec_pione-config-get.rb +47 -0
- data/test/command/spec_pione-config-list.rb +42 -0
- data/test/command/spec_pione-config-set.rb +38 -0
- data/test/command/spec_pione-config-unset.rb +44 -0
- data/test/command/spec_pione-config.rb +11 -0
- data/test/command/spec_pione-diagnosis-notification.rb +23 -0
- data/test/command/spec_pione-diagnosis.rb +11 -0
- data/test/command/spec_pione-lang-check-syntax.rb +12 -0
- data/test/command/spec_pione-lang.rb +11 -0
- data/test/command/spec_pione-log-format.rb +29 -0
- data/test/command/spec_pione-log-list-id.rb +17 -0
- data/test/command/spec_pione-log.rb +6 -20
- data/test/command/spec_pione-package-add.rb +55 -0
- data/test/command/spec_pione-package-build.rb +57 -0
- data/test/command/spec_pione-package-show.rb +72 -0
- data/test/command/{spec_pione-update-package-info.rb → spec_pione-package-update.rb} +12 -13
- data/test/command/spec_pione-package.rb +4 -104
- data/test/command/spec_pione-val.rb +10 -7
- data/test/global/spec_config.rb +50 -0
- data/test/global/spec_item.rb +1 -1
- data/test/literate-action/data/HelloWorld.md +1 -1
- data/test/location/location-behavior.rb +1 -1
- data/test/location/spec_dropbox-location.rb +39 -0
- data/test/location/spec_notification-scheme.rb +37 -0
- data/test/log/spec_debug.rb +5 -4
- data/test/log/spec_message-log-receiver.rb +13 -0
- data/test/log/spec_message-log.rb +6 -9
- data/test/log/spec_system-log.rb +5 -3
- data/test/notification/spec_address.rb +229 -0
- data/test/notification/spec_message.rb +30 -0
- data/test/notification/spec_receiver.rb +36 -0
- data/test/notification/spec_transmitter.rb +37 -0
- data/test/pnml/data/ConditionalBranchIf.pnml +270 -0
- data/test/pnml/data/ConditionalBranchIfElse.pnml +309 -0
- data/test/pnml/data/IOExpansionComplex.pnml +363 -0
- data/test/pnml/data/IOExpansionSimple.pnml +140 -0
- data/test/pnml/data/InputMergeComplementComplex.pnml +381 -0
- data/test/pnml/data/InputMergeComplementSimple.pnml +248 -0
- data/test/pnml/data/InputParallelizationComplementComplex.pnml +433 -0
- data/test/pnml/data/InputParallelizationComplementSimple.pnml +288 -0
- data/test/pnml/data/InputReductionComplex.pnml +192 -0
- data/test/pnml/data/InputReductionLong.pnml +344 -0
- data/test/pnml/data/InputReductionSimple.pnml +140 -0
- data/test/pnml/data/IsolatedElementElimination.pnml +171 -0
- data/test/pnml/data/OutputDecompositionComplementComplex.pnml +381 -0
- data/test/pnml/data/OutputDecompositionComplementSimple.pnml +242 -0
- data/test/pnml/data/OutputReductionComplex.pnml +186 -0
- data/test/pnml/data/OutputReductionLong.pnml +344 -0
- data/test/pnml/data/OutputReductionSimple.pnml +140 -0
- data/test/pnml/data/OutputSynchronizationComplementComplex.pnml +498 -0
- data/test/pnml/data/OutputSynchronizationComplementSimple.pnml +347 -0
- data/test/pnml/data/SampleNet.pnml +238 -0
- data/test/pnml/spec_input-merge-complement.rb +40 -0
- data/test/pnml/spec_input-parallelization-complement.rb +50 -0
- data/test/pnml/spec_input-reduction.rb +113 -0
- data/test/pnml/spec_invalid-arc-elimination.rb +33 -0
- data/test/pnml/spec_io-expansion.rb +126 -0
- data/test/pnml/spec_isolated-element-elimination.rb +25 -0
- data/test/pnml/spec_output-decomposition-complement.rb +40 -0
- data/test/pnml/spec_output-reduction.rb +114 -0
- data/test/pnml/spec_output-synchronization-complement.rb +62 -0
- data/test/pnml/spec_pione-element.rb +144 -0
- data/test/pnml/spec_pnml-element.rb +373 -0
- data/test/pnml/spec_reader.rb +16 -0
- data/test/rootage/spec_argument.rb +18 -0
- data/test/rootage/spec_command.rb +239 -0
- data/test/rootage/spec_core.rb +198 -0
- data/test/rootage/spec_scenario.rb +149 -0
- data/test/system/{spec_domain-info.rb → spec_domain-dump.rb} +6 -6
- data/test/system/spec_file-cache.rb +6 -9
- data/test/tuple-space/spec_finished-tuple.rb +1 -1
- data/test/util/{spec_package-parameters-list_1.pione → data/package-parameters-list/Param1.pione} +0 -0
- data/test/util/{spec_package-parameters-list_2.pione → data/package-parameters-list/Param2.pione} +0 -0
- data/test/util/{spec_package-parameters-list_3.pione → data/package-parameters-list/Param3.pione} +0 -0
- data/test/util/{spec_package-parameters-list_4.pione → data/package-parameters-list/Param4.pione} +0 -0
- data/test/util/spec_boolean-value.rb +32 -0
- data/test/util/spec_completion.rb +22 -0
- data/test/util/spec_package-parameters-list.rb +39 -52
- data/test/util/spec_zip.rb +28 -1
- metadata +288 -47
- data/bin/pione-tuple-space-receiver +0 -5
- data/lib/pione/agent/broker.rb +0 -304
- data/lib/pione/agent/tuple-space-receiver.rb +0 -137
- data/lib/pione/command/pione-broker.rb +0 -104
- data/lib/pione/command/pione-compiler.rb +0 -57
- data/lib/pione/command/pione-relay-account-db.rb +0 -141
- data/lib/pione/command/pione-relay-client-db.rb +0 -118
- data/lib/pione/command/pione-relay.rb +0 -59
- data/lib/pione/command/pione-syntax-checker.rb +0 -214
- data/lib/pione/command/pione-tuple-space-receiver.rb +0 -111
- data/lib/pione/command/pione-update-package-info.rb +0 -53
- data/lib/pione/front/broker-front.rb +0 -22
- data/lib/pione/front/tuple-space-receiver-front.rb +0 -11
- data/lib/pione/global/broker-variable.rb +0 -33
- data/lib/pione/system/domain-info.rb +0 -25
- data/lib/pione/util/pnml-compiler.rb +0 -168
- data/test/agent/spec_tuple-space-receiver.rb +0 -47
- data/test/util/spec_pnml-compiler.rb +0 -32
@@ -0,0 +1,21 @@
|
|
1
|
+
module Pione
|
2
|
+
module Command
|
3
|
+
# `PioneDiagnosis` is a utility set for diagnosis.
|
4
|
+
class PioneDiagnosis < BasicCommand
|
5
|
+
#
|
6
|
+
# informations
|
7
|
+
#
|
8
|
+
|
9
|
+
define(:name, "diagnosis")
|
10
|
+
define(:desc, "PIONE diagnosis tools")
|
11
|
+
|
12
|
+
#
|
13
|
+
# requirements
|
14
|
+
#
|
15
|
+
|
16
|
+
require 'pione/command/pione-diagnosis-notification'
|
17
|
+
end
|
18
|
+
|
19
|
+
PioneCommand.define_subcommand("diagnosis", PioneDiagnosis)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
module Pione
|
2
|
+
module Command
|
3
|
+
class PioneInteractive < BasicCommand
|
4
|
+
#
|
5
|
+
# libraries
|
6
|
+
#
|
7
|
+
|
8
|
+
require 'rexml/document'
|
9
|
+
|
10
|
+
# debug mode only
|
11
|
+
unless ENV["PIONE_JOB_ID"]
|
12
|
+
require 'webrick'
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# informations
|
17
|
+
#
|
18
|
+
|
19
|
+
define(:toplevel, true)
|
20
|
+
define(:name, "pione-interactive")
|
21
|
+
define(:desc, "interactive action handler")
|
22
|
+
|
23
|
+
#
|
24
|
+
# arguments
|
25
|
+
#
|
26
|
+
|
27
|
+
argument(:xml) do |item|
|
28
|
+
item.type = :location
|
29
|
+
item.desc = "UI definition file"
|
30
|
+
item.missing = "There are no definition file."
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# options
|
35
|
+
#
|
36
|
+
|
37
|
+
option(:ui) do |item|
|
38
|
+
item.type = :symbol_downcase
|
39
|
+
item.long = "--ui"
|
40
|
+
item.arg = "NAME"
|
41
|
+
item.desc = "User interface name"
|
42
|
+
end
|
43
|
+
|
44
|
+
option_post(:validate_ui) do |item|
|
45
|
+
item.desc = "Validate UI name"
|
46
|
+
|
47
|
+
item.process do
|
48
|
+
test(model[:ui].nil?)
|
49
|
+
raise Rootage::OptionError.new(cmd, "No UI name")
|
50
|
+
end
|
51
|
+
|
52
|
+
item.process do
|
53
|
+
test(model[:ui] != :browser)
|
54
|
+
raise Rootage::OptionError.new(cmd, "Unknown UI name: %s" % model[:ui])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
#
|
59
|
+
# command lifecycle: setup phase
|
60
|
+
#
|
61
|
+
|
62
|
+
phase(:setup) do |seq|
|
63
|
+
seq << :ui_definition
|
64
|
+
end
|
65
|
+
|
66
|
+
setup(:ui_definition) do |item|
|
67
|
+
item.desc = "Extract informations from UI definition"
|
68
|
+
item.process do
|
69
|
+
fm = REXML::Formatters::Default.new
|
70
|
+
|
71
|
+
# create a document
|
72
|
+
doc = REXML::Document.new(model[:xml].read)
|
73
|
+
|
74
|
+
# get the prefix of root element(e.g. "pione")
|
75
|
+
prefix = doc.root.prefix
|
76
|
+
prefix = prefix ? prefix + ":" : ""
|
77
|
+
|
78
|
+
# get embeded contents
|
79
|
+
content = REXML::XPath.first(doc, "/#{prefix}interactive/#{prefix}content")
|
80
|
+
model[:content] = ""
|
81
|
+
content.elements.each {|e| fm.write(e, model[:content])}
|
82
|
+
|
83
|
+
# get embeded script
|
84
|
+
script = REXML::XPath.first(doc, "/#{prefix}interactive/#{prefix}script")
|
85
|
+
model[:script] = script.text
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# command lifecycle: execution phase
|
91
|
+
#
|
92
|
+
|
93
|
+
phase(:execution) do |seq|
|
94
|
+
if ENV["PIONE_JOB_ID"]
|
95
|
+
seq << :connect_webclient
|
96
|
+
else
|
97
|
+
# debug mode
|
98
|
+
seq << :debug_mode
|
99
|
+
seq << :print_result
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
execution(:debug_mode) do |item|
|
104
|
+
item.desc = "Launch a debug server"
|
105
|
+
item.process do
|
106
|
+
begin
|
107
|
+
template = <<HTML
|
108
|
+
<!DOCTYPE html>
|
109
|
+
<html>
|
110
|
+
<head>
|
111
|
+
<meta charset="utf-8">
|
112
|
+
<title>pione-interactive</title>
|
113
|
+
<script>
|
114
|
+
document.addEventListener("pione-interactive-result", function(event) {
|
115
|
+
var msg = document.getElementById("message");
|
116
|
+
|
117
|
+
// clear children
|
118
|
+
while (msg.firstChild) {
|
119
|
+
msg.removeChild(msg.firstChild);
|
120
|
+
}
|
121
|
+
|
122
|
+
// show the result
|
123
|
+
var line1 = document.createElement("p");
|
124
|
+
line1.textContent = "Result: " + event.result;
|
125
|
+
msg.appendChild(line1);
|
126
|
+
|
127
|
+
// server shutdown
|
128
|
+
var req = new XMLHttpRequest();
|
129
|
+
req.open("POST", "/shutdown", false);
|
130
|
+
req.setRequestHeader("Content-Type", "text/plain");
|
131
|
+
req.send(event.result);
|
132
|
+
var line2 = document.createElement("p");
|
133
|
+
line2.textContent = "Server has shutdowned. See your console, bye.";
|
134
|
+
msg.appendChild(line2);
|
135
|
+
});
|
136
|
+
</script>
|
137
|
+
</head>
|
138
|
+
<body>
|
139
|
+
<div>%s</div>
|
140
|
+
<div id="message"></div>
|
141
|
+
<script>window.onload = function() {%s};</script>
|
142
|
+
</body>
|
143
|
+
</html>
|
144
|
+
HTML
|
145
|
+
html = template % [model[:content], model[:script]]
|
146
|
+
|
147
|
+
model[:debug_server] = WEBrick::HTTPServer.new(
|
148
|
+
:Port => 8080, :Logger => WEBrick::Log.new($stderr)
|
149
|
+
)
|
150
|
+
|
151
|
+
# page handler on '/'
|
152
|
+
model[:debug_server].mount_proc("/") do |req, res|
|
153
|
+
res.body = html
|
154
|
+
res['Content-Type'] = "text/html"
|
155
|
+
end
|
156
|
+
|
157
|
+
# shutdown handler on '/shutdown'
|
158
|
+
model[:debug_server].mount_proc("/shutdown") do |req, res|
|
159
|
+
model[:result] = req.body
|
160
|
+
model[:debug_server].shutdown
|
161
|
+
end
|
162
|
+
|
163
|
+
# `Kernel.trap` can take multiple INT handlers
|
164
|
+
trap("INT") { model[:debug_server].shutdown }
|
165
|
+
|
166
|
+
# show the location
|
167
|
+
$stderr.puts "See http://localhost:8080"
|
168
|
+
|
169
|
+
# start the debug server
|
170
|
+
model[:debug_server].start
|
171
|
+
ensure
|
172
|
+
if model[:debug_server]
|
173
|
+
model[:debug_server].shutdown
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
# Print a result string of interactive action to stdout.
|
180
|
+
execution(:print_result) do |item|
|
181
|
+
item.desc = "Print a result string."
|
182
|
+
item.process do
|
183
|
+
$stdout.print model[:result]
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
module Pione
|
2
|
+
module Command
|
3
|
+
# `PioneLangCheckSyntax` is a command that checks syntax.
|
4
|
+
class PioneLangCheckSyntax < BasicCommand
|
5
|
+
#
|
6
|
+
# informations
|
7
|
+
#
|
8
|
+
|
9
|
+
define(:name, "interactive")
|
10
|
+
define(:desc, "Interactive environment for PIONE language")
|
11
|
+
|
12
|
+
#
|
13
|
+
# requirements
|
14
|
+
#
|
15
|
+
|
16
|
+
require "pp"
|
17
|
+
|
18
|
+
#
|
19
|
+
# options
|
20
|
+
#
|
21
|
+
|
22
|
+
option CommonOption.color
|
23
|
+
|
24
|
+
option(:expr) do |item|
|
25
|
+
item.type = :string
|
26
|
+
item.short = '-e'
|
27
|
+
item.long = '--expr'
|
28
|
+
item.arg = 'EXPR'
|
29
|
+
item.desc = 'PIONE expression'
|
30
|
+
end
|
31
|
+
|
32
|
+
option(:syntax) do |item|
|
33
|
+
item.type = :boolean
|
34
|
+
item.short = '-s'
|
35
|
+
item.long = '--syntax'
|
36
|
+
item.desc = 'show syntax tree'
|
37
|
+
item.init = true
|
38
|
+
end
|
39
|
+
|
40
|
+
option(:model) do |item|
|
41
|
+
item.type = :boolean
|
42
|
+
item.short = '-m'
|
43
|
+
item.long = '--model'
|
44
|
+
item.desc = 'show internal model'
|
45
|
+
item.init = false
|
46
|
+
end
|
47
|
+
|
48
|
+
option(:file) do |item|
|
49
|
+
item.type = :path
|
50
|
+
item.short = '-f'
|
51
|
+
item.long = '--file'
|
52
|
+
item.arg = 'PATH'
|
53
|
+
item.desc = 'PIONE document that is checked'
|
54
|
+
end
|
55
|
+
|
56
|
+
option(:parser) do |item|
|
57
|
+
item.type = :symbol
|
58
|
+
item.long = '--parser'
|
59
|
+
item.arg = 'NAME'
|
60
|
+
item.desc = 'Parser name'
|
61
|
+
item.init = :expr
|
62
|
+
end
|
63
|
+
|
64
|
+
option_post(:source) do |item|
|
65
|
+
item.process do
|
66
|
+
test(not(model[:file]))
|
67
|
+
test(not(model[:expr]))
|
68
|
+
raise Rootage::OptionError.new(cmd, "Requires --file or --expr.")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
#
|
73
|
+
# command lifecycle: setup phase
|
74
|
+
#
|
75
|
+
|
76
|
+
phase(:setup) do |seq|
|
77
|
+
seq << :source
|
78
|
+
end
|
79
|
+
|
80
|
+
setup(:source) do |item|
|
81
|
+
item.desc = "Setup a source string"
|
82
|
+
|
83
|
+
item.assign(:source) do
|
84
|
+
test(model[:file])
|
85
|
+
Pathname.new(model[:file]).read
|
86
|
+
end
|
87
|
+
|
88
|
+
item.assign(:source) do
|
89
|
+
test(model[:expr])
|
90
|
+
model[:expr]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
#
|
95
|
+
# command lifecycle: execution phase
|
96
|
+
#
|
97
|
+
|
98
|
+
phase(:execution) do |seq|
|
99
|
+
seq << :make_syntax_tree
|
100
|
+
seq << :print_syntax_tree
|
101
|
+
seq << :make_internal_model
|
102
|
+
seq << :print_internal_model
|
103
|
+
end
|
104
|
+
|
105
|
+
execution(:make_syntax_tree) do |item|
|
106
|
+
item.desc = "Make a syntax tree"
|
107
|
+
|
108
|
+
# parse
|
109
|
+
item.assign(:stree) do
|
110
|
+
Lang::DocumentParser.new.send(model[:parser]).parse(model[:source])
|
111
|
+
end
|
112
|
+
|
113
|
+
item.exception(Lang::ParserError, Parslet::ParseFailed) do |e|
|
114
|
+
cmd.abort("Pione syntax error: %{reason}" % {reason: e.message})
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
execution(:print_syntax_tree) do |item|
|
119
|
+
item.desc = "Print the syntax tree"
|
120
|
+
|
121
|
+
item.condition {test(model[:syntax])}
|
122
|
+
|
123
|
+
item.process do
|
124
|
+
puts "syntax:".color(:green)
|
125
|
+
pp model[:stree]
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
execution(:make_internal_model) do |item|
|
130
|
+
item.desc = "Make an internal language model"
|
131
|
+
|
132
|
+
item.condition {test(model[:model])}
|
133
|
+
|
134
|
+
# make the internal model
|
135
|
+
item.assign(:internal_model) do
|
136
|
+
transformer_option = {}
|
137
|
+
transformer_option[:package_name] = model[:package_name] || "PioneSyntaxChecker"
|
138
|
+
transformer_option[:filename] = model[:filename] || "NoFile"
|
139
|
+
|
140
|
+
Lang::DocumentTransformer.new.apply(model[:stree], transformer_option)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
execution(:print_internal_model) do |item|
|
145
|
+
item.desc = "Print the internal language model"
|
146
|
+
|
147
|
+
item.condition {test(model[:model])}
|
148
|
+
|
149
|
+
# print model
|
150
|
+
item.process do
|
151
|
+
puts "model:".color(:green)
|
152
|
+
pp model[:internal_model]
|
153
|
+
end
|
154
|
+
|
155
|
+
item.exception(Lang::LangTypeError, Lang::BindingError) do |e|
|
156
|
+
cmd.abort("Pione model error: %{reason}" % {reason: e.message})
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
PioneLang.define_subcommand("check-syntax", PioneLangCheckSyntax)
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
module Pione
|
2
|
+
module Command
|
3
|
+
# `PioneLangInteractive` is a command that provides interactive environment
|
4
|
+
# for PIONE language.
|
5
|
+
class PioneLangInteractive < BasicCommand
|
6
|
+
#
|
7
|
+
# informations
|
8
|
+
#
|
9
|
+
|
10
|
+
define(:name, "interactive")
|
11
|
+
define(:desc, "Interactive environment for PIONE language")
|
12
|
+
|
13
|
+
#
|
14
|
+
# requirements
|
15
|
+
#
|
16
|
+
|
17
|
+
require "readline"
|
18
|
+
|
19
|
+
#
|
20
|
+
# arguments and options
|
21
|
+
#
|
22
|
+
|
23
|
+
option CommonOption.color
|
24
|
+
|
25
|
+
#
|
26
|
+
# command lifecycle: setup phase
|
27
|
+
#
|
28
|
+
|
29
|
+
phase(:setup) do |item|
|
30
|
+
item << :load_history
|
31
|
+
end
|
32
|
+
|
33
|
+
setup(:load_history) do |item|
|
34
|
+
item.desc = "Load history"
|
35
|
+
|
36
|
+
item.assign(:history) do
|
37
|
+
File.join(Global.dot_pione_dir, "pione-lang-interactive-history")
|
38
|
+
end
|
39
|
+
|
40
|
+
item.process do
|
41
|
+
if File.exist?(model[:history])
|
42
|
+
File.readlines(model[:history]).reverse.each do |line|
|
43
|
+
Readline::HISTORY.push line.chomp
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# command lifecycle: execution phase
|
51
|
+
#
|
52
|
+
|
53
|
+
phase(:execution) do |item|
|
54
|
+
item << :readline
|
55
|
+
end
|
56
|
+
|
57
|
+
execution(:readline) do |item|
|
58
|
+
item.desc = "Start interactive environment"
|
59
|
+
|
60
|
+
item.process do
|
61
|
+
start_readline
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# command lifecycle: termination phase
|
67
|
+
#
|
68
|
+
|
69
|
+
phase(:termination) do |item|
|
70
|
+
item << :save_history
|
71
|
+
end
|
72
|
+
|
73
|
+
termination(:save_history) do |item|
|
74
|
+
item.desc = "Save history file"
|
75
|
+
|
76
|
+
item.process do
|
77
|
+
File.open(model[:history], "w+") do |file|
|
78
|
+
Readline::HISTORY.to_a.reverse[0..100].each do |line|
|
79
|
+
file.puts(line) if /\S/.match(line)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
PioneLang.define_subcommand("interactive" , PioneLangInteractive)
|
87
|
+
|
88
|
+
class PioneLangInteractiveContext < Rootage::CommandContext
|
89
|
+
def start_readline
|
90
|
+
buf = ""
|
91
|
+
mark = ">"
|
92
|
+
|
93
|
+
# start loop
|
94
|
+
while line = Readline.readline("#{mark} ".color(:red), true)
|
95
|
+
buf += line
|
96
|
+
if /[^\s]/.match(buf)
|
97
|
+
# don't record if previous line is the same
|
98
|
+
if Readline::HISTORY.size > 1 && Readline::HISTORY[-2] == buf
|
99
|
+
Readline::HISTORY.pop
|
100
|
+
end
|
101
|
+
if buf[-1] == "\\"
|
102
|
+
buf[-1] = "\n"
|
103
|
+
mark = "+"
|
104
|
+
next
|
105
|
+
else
|
106
|
+
# print parsing result
|
107
|
+
print_result(Lang::DocumentParser.new.expr, buf)
|
108
|
+
buf = ""
|
109
|
+
mark = ">"
|
110
|
+
end
|
111
|
+
else
|
112
|
+
# don't record if it is an empty line
|
113
|
+
Readline::HISTORY.pop
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# Print parsing result of the string.
|
119
|
+
def print_result(parser, str)
|
120
|
+
begin
|
121
|
+
stree = parser.parse(str)
|
122
|
+
transformer_option = {}
|
123
|
+
transformer_option[:package_name] = model[:package_name] || "PioneSyntaxChecker"
|
124
|
+
transformer_option[:filename] = model[:filename] || "NoFile"
|
125
|
+
model = Lang::DocumentTransformer.new.apply(stree, transformer_option)
|
126
|
+
if model.kind_of?(Array)
|
127
|
+
model.each {|m| p m}
|
128
|
+
else
|
129
|
+
p model.eval(Lang::Environment.new)
|
130
|
+
end
|
131
|
+
rescue Lang::ParserError, Parslet::ParseFailed => e
|
132
|
+
msg = "Pione syntax error: %s (%s)" % [e.message, e.class.name]
|
133
|
+
puts(msg)
|
134
|
+
rescue Lang::LangTypeError, Lang::BindingError => e
|
135
|
+
msg = "Pione model error: %s (%s)" % [e.message, e.class.name]
|
136
|
+
puts(msg)
|
137
|
+
rescue Lang::MethodNotFound => e
|
138
|
+
msg = "%s (%s)" % [e.message, e.class.name]
|
139
|
+
puts(msg)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
PioneLangInteractive.define(:process_context_class, PioneLangInteractiveContext)
|
145
|
+
end
|
146
|
+
end
|