pione 0.1.0
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.
- data/.gitignore +14 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +94 -0
- data/Rakefile +118 -0
- data/bin/pione-broker +5 -0
- data/bin/pione-clean +5 -0
- data/bin/pione-client +5 -0
- data/bin/pione-eval +111 -0
- data/bin/pione-relay +5 -0
- data/bin/pione-relay-account-db +5 -0
- data/bin/pione-relay-client-db +5 -0
- data/bin/pione-search-log +30 -0
- data/bin/pione-syntax-checker +5 -0
- data/bin/pione-task-worker +5 -0
- data/bin/pione-tuple-space-provider +5 -0
- data/bin/pione-tuple-space-receiver +5 -0
- data/bin/pione-tuple-space-viewer +5 -0
- data/demo/demo.rb +311 -0
- data/demo/public/base.css +94 -0
- data/demo/public/demo.js +107 -0
- data/demo/public/index.html +91 -0
- data/demo/public/jquery-1.8.3.min.js +2 -0
- data/example/CountChar/CountChar.pione +64 -0
- data/example/CountChar/misc/CountChar.rb +22 -0
- data/example/CountChar/text/aidokushono_insho.txt +32 -0
- data/example/CountChar/text/aikokuka_shokan.txt +108 -0
- data/example/CountChar/text/carlyle_hakubutsukan.txt +58 -0
- data/example/CountChar/text/dark_minister.txt +2440 -0
- data/example/CountChar/text/kaikano_otto.txt +61 -0
- data/example/CountChar/text/kaikon.txt +30 -0
- data/example/CountChar/text/nagashimano_shi.txt +45 -0
- data/example/CountChar/text/saikachibuchi.txt +80 -0
- data/example/CountChar/text/saikonihonno_josei.txt +91 -0
- data/example/CountChar/text/taishojugonenno_bundan.txt +21 -0
- data/example/FeatureExample/FeatureExample.pione +7 -0
- data/example/Fib/Fib.pione +56 -0
- data/example/Fib/FibBC.pione +56 -0
- data/example/HelloWorld/HelloWorld.pione +5 -0
- data/example/LucasNumber/LucasNumber.pione +64 -0
- data/example/MakePair/MakePair.pione +14 -0
- data/example/MakePair/data/1.i +0 -0
- data/example/MakePair/data/2.i +0 -0
- data/example/MakePair/data/3.i +0 -0
- data/example/MakePair/data/4.i +0 -0
- data/example/MakePair/data/5.i +0 -0
- data/example/SieveOfEratosthenes/SieveOfEratosthenes.pione +61 -0
- data/example/SingleParticlesWithRef/Makefile +289 -0
- data/example/SingleParticlesWithRef/SingleParticlesWithRef.Makefile +153 -0
- data/example/SingleParticlesWithRef/SingleParticlesWithRef.pione +116 -0
- data/example/SingleParticlesWithRef/SingleParticlesWithRefFull.pione +400 -0
- data/example/SingleParticlesWithRef/data/121p-shift-0-0-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-0-120-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-0-180-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-0-240-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-0-300-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-0-60-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-120-0-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-120-120-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-120-180-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-120-240-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-120-300-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-120-60-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-180-0-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-180-120-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-180-180-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-180-240-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-180-300-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-180-60-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-240-0-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-240-120-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-240-180-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-240-240-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-240-300-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-240-60-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-300-0-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-300-120-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-300-180-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-300-240-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-300-300-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-300-60-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-60-0-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-60-120-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-60-180-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-60-240-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-60-300-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-60-60-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-0-0-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-0-120-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-0-180-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-0-240-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-0-300-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-0-60-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-120-0-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-120-120-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-120-180-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-120-240-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-120-300-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-120-60-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-180-0-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-180-120-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-180-180-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-180-240-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-180-300-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-180-60-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-240-0-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-240-120-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-240-180-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-240-240-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-240-300-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-240-60-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-300-0-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-300-120-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-300-180-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-300-240-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-300-300-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-300-60-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-60-0-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-60-120-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-60-180-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-60-240-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-60-300-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift-noise-60-60-0.roi +0 -0
- data/example/SingleParticlesWithRef/data/121p-shift.pdb +3381 -0
- data/example/SingleParticlesWithRef/data/all.ref2d +0 -0
- data/example/SingleParticlesWithRef/data/all.ref3d +0 -0
- data/example/Sum/Sum.pione +52 -0
- data/example/SyntaxError/call_rule_error.pione +6 -0
- data/example/SyntaxError/feature_line_error.pione +7 -0
- data/example/SyntaxError/flow_block_error.pione +5 -0
- data/example/SyntaxError/input_line_error.pione +6 -0
- data/example/SyntaxError/invalid_rule_name.pione +6 -0
- data/example/SyntaxError/param_line_error.pione +7 -0
- data/example/SyntaxError/variable-binding-error.pione +11 -0
- data/lib/pione.rb +241 -0
- data/lib/pione/agent/basic-agent.rb +333 -0
- data/lib/pione/agent/broker.rb +274 -0
- data/lib/pione/agent/command-listener.rb +47 -0
- data/lib/pione/agent/input-generator.rb +194 -0
- data/lib/pione/agent/logger.rb +65 -0
- data/lib/pione/agent/process-manager.rb +38 -0
- data/lib/pione/agent/rule-provider.rb +64 -0
- data/lib/pione/agent/task-worker.rb +274 -0
- data/lib/pione/agent/trivial-routine-worker.rb +28 -0
- data/lib/pione/agent/tuple-space-client.rb +146 -0
- data/lib/pione/agent/tuple-space-server-client-life-checker.rb +29 -0
- data/lib/pione/command-option/basic-option.rb +42 -0
- data/lib/pione/command-option/child-process-option.rb +17 -0
- data/lib/pione/command-option/common-option.rb +29 -0
- data/lib/pione/command-option/daemon-option.rb +12 -0
- data/lib/pione/command-option/presence-notifier-option.rb +15 -0
- data/lib/pione/command-option/task-worker-owner-option.rb +17 -0
- data/lib/pione/command-option/tuple-space-provider-option.rb +26 -0
- data/lib/pione/command-option/tuple-space-provider-owner-option.rb +16 -0
- data/lib/pione/command-option/tuple-space-receiver-option.rb +12 -0
- data/lib/pione/command/basic-command.rb +126 -0
- data/lib/pione/command/child-process.rb +43 -0
- data/lib/pione/command/daemon-process.rb +18 -0
- data/lib/pione/command/front-owner-command.rb +37 -0
- data/lib/pione/command/pione-broker.rb +53 -0
- data/lib/pione/command/pione-clean.rb +16 -0
- data/lib/pione/command/pione-client.rb +273 -0
- data/lib/pione/command/pione-relay-account-db.rb +85 -0
- data/lib/pione/command/pione-relay-client-db.rb +80 -0
- data/lib/pione/command/pione-relay.rb +47 -0
- data/lib/pione/command/pione-syntax-checker.rb +103 -0
- data/lib/pione/command/pione-task-worker.rb +123 -0
- data/lib/pione/command/pione-tuple-space-provider.rb +87 -0
- data/lib/pione/command/pione-tuple-space-receiver.rb +55 -0
- data/lib/pione/command/pione-tuple-space-viewer.rb +151 -0
- data/lib/pione/command/tuple-space-provider-owner.rb +6 -0
- data/lib/pione/front/basic-front.rb +64 -0
- data/lib/pione/front/broker-front.rb +30 -0
- data/lib/pione/front/client-front.rb +28 -0
- data/lib/pione/front/relay-front.rb +19 -0
- data/lib/pione/front/task-worker-front.rb +16 -0
- data/lib/pione/front/task-worker-owner.rb +42 -0
- data/lib/pione/front/tuple-space-provider-front.rb +22 -0
- data/lib/pione/front/tuple-space-provider-owner.rb +11 -0
- data/lib/pione/front/tuple-space-receiver-front.rb +18 -0
- data/lib/pione/model/assignment.rb +89 -0
- data/lib/pione/model/basic-model.rb +395 -0
- data/lib/pione/model/binary-operator.rb +80 -0
- data/lib/pione/model/block.rb +233 -0
- data/lib/pione/model/boolean.rb +138 -0
- data/lib/pione/model/call-rule.rb +69 -0
- data/lib/pione/model/data-expr.rb +360 -0
- data/lib/pione/model/feature-expr.rb +794 -0
- data/lib/pione/model/float.rb +107 -0
- data/lib/pione/model/integer.rb +140 -0
- data/lib/pione/model/list.rb +104 -0
- data/lib/pione/model/message.rb +80 -0
- data/lib/pione/model/package.rb +48 -0
- data/lib/pione/model/parameters.rb +282 -0
- data/lib/pione/model/rule-expr.rb +120 -0
- data/lib/pione/model/rule-io.rb +166 -0
- data/lib/pione/model/rule.rb +294 -0
- data/lib/pione/model/string.rb +111 -0
- data/lib/pione/model/undefined-value.rb +24 -0
- data/lib/pione/model/variable-table.rb +315 -0
- data/lib/pione/model/variable.rb +87 -0
- data/lib/pione/parser/block-parser.rb +83 -0
- data/lib/pione/parser/common-parser.rb +145 -0
- data/lib/pione/parser/document-parser.rb +58 -0
- data/lib/pione/parser/error-message.yml +4 -0
- data/lib/pione/parser/expr-parser.rb +266 -0
- data/lib/pione/parser/feature-expr-parser.rb +105 -0
- data/lib/pione/parser/flow-element-parser.rb +181 -0
- data/lib/pione/parser/literal-parser.rb +182 -0
- data/lib/pione/parser/rule-definition-parser.rb +163 -0
- data/lib/pione/parser/syntax-error.rb +61 -0
- data/lib/pione/patch/array-patch.rb +3 -0
- data/lib/pione/patch/drb-patch.rb +467 -0
- data/lib/pione/patch/monitor-patch.rb +16 -0
- data/lib/pione/patch/rinda-patch.rb +759 -0
- data/lib/pione/patch/uri-patch.rb +66 -0
- data/lib/pione/relay/receiver-socket.rb +69 -0
- data/lib/pione/relay/relay-account-db.rb +55 -0
- data/lib/pione/relay/relay-client-db.rb +53 -0
- data/lib/pione/relay/relay-socket.rb +215 -0
- data/lib/pione/relay/trampoline.rb +22 -0
- data/lib/pione/relay/transmitter-socket.rb +167 -0
- data/lib/pione/resource/basic-resource.rb +92 -0
- data/lib/pione/resource/dropbox-resource.rb +106 -0
- data/lib/pione/resource/ftp.rb +84 -0
- data/lib/pione/resource/local.rb +113 -0
- data/lib/pione/rule-handler/action-handler.rb +184 -0
- data/lib/pione/rule-handler/basic-handler.rb +217 -0
- data/lib/pione/rule-handler/flow-handler.rb +339 -0
- data/lib/pione/rule-handler/root-handler.rb +23 -0
- data/lib/pione/rule-handler/system-handler.rb +13 -0
- data/lib/pione/system/common.rb +22 -0
- data/lib/pione/system/config.rb +20 -0
- data/lib/pione/system/document.rb +81 -0
- data/lib/pione/system/file-cache.rb +150 -0
- data/lib/pione/system/global.rb +346 -0
- data/lib/pione/system/identifier.rb +61 -0
- data/lib/pione/system/init.rb +16 -0
- data/lib/pione/system/object.rb +35 -0
- data/lib/pione/transformer/block-transformer.rb +23 -0
- data/lib/pione/transformer/document-transformer.rb +36 -0
- data/lib/pione/transformer/expr-transformer.rb +89 -0
- data/lib/pione/transformer/feature-expr-transformer.rb +56 -0
- data/lib/pione/transformer/flow-element-transformer.rb +66 -0
- data/lib/pione/transformer/literal-transformer.rb +76 -0
- data/lib/pione/transformer/rule-definition-transformer.rb +62 -0
- data/lib/pione/transformer/transformer-module.rb +37 -0
- data/lib/pione/tuple-space/data-finder.rb +165 -0
- data/lib/pione/tuple-space/presence-notifier.rb +83 -0
- data/lib/pione/tuple-space/relay.rb +9 -0
- data/lib/pione/tuple-space/tuple-space-provider.rb +85 -0
- data/lib/pione/tuple-space/tuple-space-receiver.rb +140 -0
- data/lib/pione/tuple-space/tuple-space-server-interface.rb +60 -0
- data/lib/pione/tuple-space/tuple-space-server.rb +156 -0
- data/lib/pione/tuple-space/update-criteria.rb +96 -0
- data/lib/pione/tuple/agent-tuple.rb +10 -0
- data/lib/pione/tuple/attribute-tuple.rb +7 -0
- data/lib/pione/tuple/base-uri-tuple.rb +9 -0
- data/lib/pione/tuple/basic-tuple.rb +317 -0
- data/lib/pione/tuple/bye-tuple.rb +9 -0
- data/lib/pione/tuple/command-tuple.rb +9 -0
- data/lib/pione/tuple/data-tuple.rb +18 -0
- data/lib/pione/tuple/dry-run-tuple.rb +8 -0
- data/lib/pione/tuple/exception-tuple.rb +11 -0
- data/lib/pione/tuple/finished-tuple.rb +17 -0
- data/lib/pione/tuple/foreground-tuple.rb +7 -0
- data/lib/pione/tuple/log-tuple.rb +14 -0
- data/lib/pione/tuple/process-info-tuple.rb +9 -0
- data/lib/pione/tuple/request-rule-tuple.rb +9 -0
- data/lib/pione/tuple/rule-tuple.rb +10 -0
- data/lib/pione/tuple/shift-tuple.rb +13 -0
- data/lib/pione/tuple/task-tuple.rb +36 -0
- data/lib/pione/tuple/task-worker-resource-tuple.rb +9 -0
- data/lib/pione/tuple/working-tuple.rb +13 -0
- data/lib/pione/uri-scheme/basic-scheme.rb +40 -0
- data/lib/pione/uri-scheme/broadcast-scheme.rb +11 -0
- data/lib/pione/uri-scheme/dropbox-scheme.rb +9 -0
- data/lib/pione/uri-scheme/local-scheme.rb +28 -0
- data/lib/pione/util/error-report.rb +12 -0
- data/lib/pione/util/log.rb +79 -0
- data/lib/pione/util/message.rb +155 -0
- data/lib/pione/util/misc.rb +73 -0
- data/lib/pione/util/terminal.rb +78 -0
- data/lib/pione/util/waiter-table.rb +53 -0
- data/lib/pione/version.rb +3 -0
- data/misc/env.sh +2 -0
- data/misc/test-drb-stop-service.rb +34 -0
- data/misc/test-ensure-and-thread-kill.rb +40 -0
- data/misc/test-many-waiters-client.rb +56 -0
- data/misc/test-many-waiters-server.rb +14 -0
- data/misc/write_and_take_test.png +0 -0
- data/misc/write_and_take_test.rb +36 -0
- data/pione.gemspec +49 -0
- data/test/agent/spec_basic-agent.rb +170 -0
- data/test/agent/spec_broker.rb +36 -0
- data/test/agent/spec_command-listener.rb +30 -0
- data/test/agent/spec_input-generator.rb +123 -0
- data/test/agent/spec_logger.rb +71 -0
- data/test/agent/spec_rule-provider.rb +65 -0
- data/test/agent/spec_task-worker.rb +307 -0
- data/test/agent/spec_tuple-space-client.rb +30 -0
- data/test/model/spec_assignment.rb +51 -0
- data/test/model/spec_binary-operator.rb +39 -0
- data/test/model/spec_block.rb +154 -0
- data/test/model/spec_boolean.rb +115 -0
- data/test/model/spec_call-rule.rb +23 -0
- data/test/model/spec_data-expr.rb +312 -0
- data/test/model/spec_feature-expr.rb +359 -0
- data/test/model/spec_feature-expr.yml +16 -0
- data/test/model/spec_float.rb +141 -0
- data/test/model/spec_integer.rb +141 -0
- data/test/model/spec_list.rb +26 -0
- data/test/model/spec_message.rb +42 -0
- data/test/model/spec_package.rb +15 -0
- data/test/model/spec_parameters.rb +148 -0
- data/test/model/spec_rule-expr.rb +66 -0
- data/test/model/spec_rule-io.rb +32 -0
- data/test/model/spec_rule.rb +158 -0
- data/test/model/spec_string.rb +106 -0
- data/test/model/spec_variable-table.rb +117 -0
- data/test/model/spec_variable.rb +84 -0
- data/test/parser/spec_block-parser.rb +5 -0
- data/test/parser/spec_block-parser.yml +85 -0
- data/test/parser/spec_common-parser.rb +281 -0
- data/test/parser/spec_expr-parser.rb +6 -0
- data/test/parser/spec_expr-parser.yml +82 -0
- data/test/parser/spec_feature-expr-parser.rb +32 -0
- data/test/parser/spec_feature-expr-parser.yml +25 -0
- data/test/parser/spec_flow-element-parser.rb +5 -0
- data/test/parser/spec_flow-element-parser.yml +180 -0
- data/test/parser/spec_literal-parser.rb +5 -0
- data/test/parser/spec_literal-parser.yml +123 -0
- data/test/parser/spec_rule-definition-parser.rb +5 -0
- data/test/parser/spec_rule-definition-parser.yml +93 -0
- data/test/patch/spec_rinda-patch.rb +32 -0
- data/test/patch/spec_uri-patch.rb +23 -0
- data/test/rule-handler/spec_action-handler.rb +135 -0
- data/test/rule-handler/spec_flow-handler.rb +127 -0
- data/test/spec_common.rb +14 -0
- data/test/spec_data-finder.rb +88 -0
- data/test/spec_data-finder.yml +115 -0
- data/test/spec_document.rb +76 -0
- data/test/spec_identifier.rb +29 -0
- data/test/spec_log.rb +52 -0
- data/test/spec_object.rb +20 -0
- data/test/spec_resource.rb +73 -0
- data/test/spec_update-criteria.rb +83 -0
- data/test/test-util.rb +223 -0
- data/test/transformer/spec_block-transformer.rb +26 -0
- data/test/transformer/spec_expr-transformer.rb +106 -0
- data/test/transformer/spec_feature-expr-transformer.rb +21 -0
- data/test/transformer/spec_flow-element-transformer.rb +154 -0
- data/test/transformer/spec_literal-transformer.rb +58 -0
- data/test/transformer/spec_rule-definition-transformer.rb +168 -0
- data/test/tuple-space/spec_tuple-space-provider.rb +36 -0
- data/test/tuple-space/spec_tuple-space-receiver.rb +32 -0
- data/test/tuple-space/spec_tuple-space-server.rb +49 -0
- data/test/tuple/spec_basic-tuple.rb +87 -0
- data/test/tuple/spec_data-tuple.rb +85 -0
- data/test/tuple/spec_finished-tuple.rb +61 -0
- data/test/tuple/spec_task-tuple.rb +127 -0
- data/test/tuple/spec_working-tuple.rb +58 -0
- data/test/uri-scheme/spec_broadcast-scheme.rb +40 -0
- data/test/uri-scheme/spec_dropbox-scheme.rb +31 -0
- data/test/uri-scheme/spec_local-scheme.rb +69 -0
- metadata +660 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
module Pione::Model
|
|
2
|
+
# RuleCondition represents rule condition.
|
|
3
|
+
class RuleCondition < BasicModel
|
|
4
|
+
# Returns the value of attribute inputs.
|
|
5
|
+
# @return [Array<DataExpr, Array<DataExpr>>]
|
|
6
|
+
# rule inputs condition
|
|
7
|
+
attr_reader :inputs
|
|
8
|
+
|
|
9
|
+
# Returns the value of attribute outputs.
|
|
10
|
+
# @return [Array<DataExpr, Array<DataExpr>>]
|
|
11
|
+
# rule outputs condition
|
|
12
|
+
attr_reader :outputs
|
|
13
|
+
|
|
14
|
+
# Returns the value of attribute params.
|
|
15
|
+
# @return [Parameters]
|
|
16
|
+
# rule parameters table
|
|
17
|
+
attr_reader :params
|
|
18
|
+
|
|
19
|
+
# Returns the value of attribute features.
|
|
20
|
+
# @return [Feature]
|
|
21
|
+
# rule feature condition
|
|
22
|
+
attr_reader :features
|
|
23
|
+
|
|
24
|
+
# Creates a rule condition.
|
|
25
|
+
# @param [Array<DataExpr, Array<DataExpr>>] inputs
|
|
26
|
+
# rule inputs
|
|
27
|
+
# @param [Array<DataExpr, Array<DataExpr>>] outputs
|
|
28
|
+
# rule outputs
|
|
29
|
+
# @param [Parameters] params
|
|
30
|
+
# rule parameters
|
|
31
|
+
# @param [Feature] features
|
|
32
|
+
# rule features
|
|
33
|
+
def initialize(inputs, outputs, params, features)
|
|
34
|
+
check_argument_type(params, Parameters)
|
|
35
|
+
check_argument_type(features, Feature::Expr)
|
|
36
|
+
@inputs = inputs
|
|
37
|
+
@outputs = outputs
|
|
38
|
+
@params = params
|
|
39
|
+
@features = features
|
|
40
|
+
super()
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Returns true if the condition includes variable.
|
|
44
|
+
# @return [Boolean]
|
|
45
|
+
# true if the condition includes variable, or false
|
|
46
|
+
def include_variable?
|
|
47
|
+
[ @inputs.any? {|input| input.include_variable?},
|
|
48
|
+
@outputs.any? {|output| output.include_variable?},
|
|
49
|
+
@params.include_variable?,
|
|
50
|
+
@features.include_variable?
|
|
51
|
+
].any?
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# @api private
|
|
55
|
+
def ==(other)
|
|
56
|
+
return false unless @inputs == other.inputs
|
|
57
|
+
return false unless @outputs == other.outputs
|
|
58
|
+
return false unless @params == other.params
|
|
59
|
+
return false unless @features == other.features
|
|
60
|
+
return true
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
alias :eql? :"=="
|
|
64
|
+
|
|
65
|
+
# @api private
|
|
66
|
+
def hash
|
|
67
|
+
@inputs.hash + @outputs.hash + @params.hash + @features.hash
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Rule is a class for PIONE rule model.
|
|
72
|
+
class Rule < BasicModel
|
|
73
|
+
extend Forwardable
|
|
74
|
+
|
|
75
|
+
# Returns rule type.
|
|
76
|
+
def self.rule_type
|
|
77
|
+
@rule_type
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Returns the value of attribute expr.
|
|
81
|
+
# @return [Array<DataExpr, Array<DataExpr>>]
|
|
82
|
+
# rule inputs condition
|
|
83
|
+
attr_reader :expr
|
|
84
|
+
|
|
85
|
+
attr_reader :condition
|
|
86
|
+
attr_reader :body
|
|
87
|
+
|
|
88
|
+
def_delegators :@condition, :inputs, :outputs, :params, :features
|
|
89
|
+
|
|
90
|
+
# Creates a rule.
|
|
91
|
+
# @param [RuleExpr] expr
|
|
92
|
+
# rule expression
|
|
93
|
+
# @param [RuleCondition] condition
|
|
94
|
+
# rule condition
|
|
95
|
+
# @param [Block] body
|
|
96
|
+
# rule body block
|
|
97
|
+
def initialize(expr, condition, body)
|
|
98
|
+
@expr = expr
|
|
99
|
+
@condition = condition
|
|
100
|
+
@body = body
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Returns the rule path.
|
|
104
|
+
# @return [String]
|
|
105
|
+
# rule path
|
|
106
|
+
def rule_path
|
|
107
|
+
@expr.rule_path
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Returns true if expression, condition, or body include variables.
|
|
111
|
+
# @return [Boolean]
|
|
112
|
+
# true if expression, condition, or body include variables
|
|
113
|
+
def include_variable?
|
|
114
|
+
return true if @expr.include_variable?
|
|
115
|
+
return true if @condition.include_variable?
|
|
116
|
+
return true if @body.include_variable?
|
|
117
|
+
return false
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# Returns true if this is a kind of action rule.
|
|
121
|
+
# @return [Boolean]
|
|
122
|
+
# true if this is a kind of action rule, or false
|
|
123
|
+
def action?
|
|
124
|
+
self.class.rule_type == :action
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# Returns true if this is a kind of flow rule.
|
|
128
|
+
# @return [Boolean]
|
|
129
|
+
# true if this is a kind of flow rule, or false
|
|
130
|
+
def flow?
|
|
131
|
+
self.class.rule_type == :flow
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Makes a task handler object for the rule.
|
|
135
|
+
# @param [TupleSpaceServer] ts_server
|
|
136
|
+
# tuple space server
|
|
137
|
+
# @param [Array<Data, Array<Data>>] inputs
|
|
138
|
+
# input tuples
|
|
139
|
+
# @param [Parameters] params
|
|
140
|
+
# rule parameters
|
|
141
|
+
# @param [Array<String>] call_stack
|
|
142
|
+
# call stack
|
|
143
|
+
# @return [RuleHandler]
|
|
144
|
+
# rule handler object
|
|
145
|
+
def make_handler(ts_server, inputs, params, call_stack, opts={})
|
|
146
|
+
handler_class.new(ts_server, self, inputs, params, call_stack, opts)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# Returns a rule handler class.
|
|
150
|
+
# @api private
|
|
151
|
+
def handler_class
|
|
152
|
+
raise NotImplementedError
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# @api private
|
|
156
|
+
def ==(other)
|
|
157
|
+
return false unless other.kind_of?(self.class)
|
|
158
|
+
return false unless @expr == other.expr
|
|
159
|
+
return false unless @condition == other.condition
|
|
160
|
+
return false unless @body == other.body
|
|
161
|
+
return true
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
alias :eql? :"=="
|
|
165
|
+
|
|
166
|
+
# @api private
|
|
167
|
+
def hash
|
|
168
|
+
@expr.hash + @condition.hash + @body.hash
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# ActionRule is a rule writing action.
|
|
173
|
+
class ActionRule < Rule
|
|
174
|
+
@rule_type = :action
|
|
175
|
+
|
|
176
|
+
# @api private
|
|
177
|
+
def handler_class
|
|
178
|
+
RuleHandler::ActionHandler
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
# FlowRule represents a flow structured rule. This rule is consisted by flow
|
|
183
|
+
# elements and executes elements actions.
|
|
184
|
+
class FlowRule < Rule
|
|
185
|
+
@rule_type = :flow
|
|
186
|
+
|
|
187
|
+
# @api private
|
|
188
|
+
def handler_class
|
|
189
|
+
RuleHandler::FlowHandler
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
# RootRule is a hidden toplevel flow rule like the following:
|
|
194
|
+
# Rule Root
|
|
195
|
+
# input '*'.all
|
|
196
|
+
# output '*'.all.except('{$INPUT[1]}')
|
|
197
|
+
# Flow
|
|
198
|
+
# rule &main:Main
|
|
199
|
+
# End
|
|
200
|
+
class RootRule < FlowRule
|
|
201
|
+
INPUT_DOMAIN = 'input'
|
|
202
|
+
|
|
203
|
+
# root domain has no digest and no package
|
|
204
|
+
ROOT_DOMAIN = 'root'
|
|
205
|
+
|
|
206
|
+
attr_reader :main
|
|
207
|
+
|
|
208
|
+
# Makes a rule.
|
|
209
|
+
def initialize(main, params=Parameters.empty)
|
|
210
|
+
@main = main
|
|
211
|
+
@params = params
|
|
212
|
+
condition = make_condition
|
|
213
|
+
super(
|
|
214
|
+
RuleExpr.new(Package.new("root"), "Root"),
|
|
215
|
+
condition,
|
|
216
|
+
FlowBlock.new(CallRule.new(@main.expr.set_params(@params)))
|
|
217
|
+
)
|
|
218
|
+
@domain = ROOT_DOMAIN
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
# @api private
|
|
222
|
+
def make_handler(ts_server)
|
|
223
|
+
finder = DataFinder.new(ts_server, INPUT_DOMAIN)
|
|
224
|
+
results = finder.find(:input, inputs, @params.as_variable_table)
|
|
225
|
+
if results.empty? and not(@main.inputs.empty?)
|
|
226
|
+
return nil
|
|
227
|
+
end
|
|
228
|
+
inputs = @main.inputs.empty? ? [] : results.first.combination
|
|
229
|
+
handler_class.new(
|
|
230
|
+
ts_server,
|
|
231
|
+
self,
|
|
232
|
+
inputs,
|
|
233
|
+
@params,
|
|
234
|
+
[],
|
|
235
|
+
{:domain => @domain}
|
|
236
|
+
)
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
private
|
|
240
|
+
|
|
241
|
+
# @api private
|
|
242
|
+
def make_condition
|
|
243
|
+
RuleCondition.new(
|
|
244
|
+
@main.inputs,
|
|
245
|
+
@main.outputs,
|
|
246
|
+
Parameters.empty,
|
|
247
|
+
Feature.empty
|
|
248
|
+
)
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
# @api private
|
|
252
|
+
def handler_class
|
|
253
|
+
RuleHandler::RootHandler
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
# SystemRule represents built-in rule definition. System rules belong to
|
|
258
|
+
# 'system' package.
|
|
259
|
+
class SystemRule < ActionRule
|
|
260
|
+
# Creates a system rule model.
|
|
261
|
+
# @param [String] name
|
|
262
|
+
# rule name
|
|
263
|
+
# @param [Proc] b
|
|
264
|
+
# rule process
|
|
265
|
+
def initialize(name, &b)
|
|
266
|
+
expr = RuleExpr.new(Package.new('system'), name)
|
|
267
|
+
condition = make_condition
|
|
268
|
+
super(expr, condition, b)
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
private
|
|
272
|
+
|
|
273
|
+
# @api private
|
|
274
|
+
def make_condition
|
|
275
|
+
inputs = [DataExpr.new('*')]
|
|
276
|
+
RuleCondition.new(inputs, [], Parameters.empty, Feature::EmptyFeature.new)
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
# @api private
|
|
280
|
+
def handler_class
|
|
281
|
+
RuleHandler::SystemHandler
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
# &System:Terminate rule
|
|
286
|
+
SYSTEM_TERMINATE = SystemRule.new('Terminate') do |tuple_space_server|
|
|
287
|
+
user_message "!!!!!!!!!!!!!!!!!"
|
|
288
|
+
user_message "!!! Terminate !!!"
|
|
289
|
+
user_message "!!!!!!!!!!!!!!!!!"
|
|
290
|
+
tuple_space_server.write(Tuple[:command].new("terminate"))
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
SYSTEM_RULES = [ SYSTEM_TERMINATE ]
|
|
294
|
+
end
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
module Pione::Model
|
|
2
|
+
# PioneString is a string value in PIONE system.
|
|
3
|
+
class PioneString < BasicModel
|
|
4
|
+
set_pione_model_type TypeString
|
|
5
|
+
attr_reader :value
|
|
6
|
+
|
|
7
|
+
# Creates a string with the value.
|
|
8
|
+
# @param [String] value
|
|
9
|
+
# string value
|
|
10
|
+
def initialize(value)
|
|
11
|
+
@value = value
|
|
12
|
+
super()
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Evaluates the object with the variable table.
|
|
16
|
+
# @param [VariableTable] vtable
|
|
17
|
+
# variable table for evaluation
|
|
18
|
+
# @return [BasicModel]
|
|
19
|
+
# evaluation result
|
|
20
|
+
def eval(vtable)
|
|
21
|
+
self.class.new(vtable.expand(@value))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Returns true if the value includes variables.
|
|
25
|
+
# @return [Boolean]
|
|
26
|
+
# true if the value includes variables
|
|
27
|
+
def include_variable?
|
|
28
|
+
VariableTable.check_include_variable(@value)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# @api private
|
|
32
|
+
def task_id_string
|
|
33
|
+
"String<#{@value}>"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# @api private
|
|
37
|
+
def textize
|
|
38
|
+
"\"%s\"" % [@value]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Returns ruby's value.
|
|
42
|
+
# @return [String]
|
|
43
|
+
# the value in ruby
|
|
44
|
+
def to_ruby
|
|
45
|
+
return @value
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# @api private
|
|
49
|
+
def ==(other)
|
|
50
|
+
return false unless other.kind_of?(self.class)
|
|
51
|
+
@value == other.value
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
alias :eql? :"=="
|
|
55
|
+
|
|
56
|
+
# @api private
|
|
57
|
+
def hash
|
|
58
|
+
@value.hash
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
TypeString.instance_eval do
|
|
63
|
+
define_pione_method("==", [TypeString], TypeBoolean) do |rec, other|
|
|
64
|
+
PioneBoolean.new(rec.value == other.value)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
define_pione_method("!=", [TypeString], TypeBoolean) do |rec, other|
|
|
68
|
+
PioneBoolean.not(rec.call_pione_method("==", other))
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
define_pione_method("+", [TypeString], TypeString) do |rec, other|
|
|
72
|
+
PioneString.new(rec.value + other.value)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
define_pione_method("as_string", [], TypeString) do |rec|
|
|
76
|
+
rec
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
define_pione_method("as_int", [], TypeInteger) do |rec|
|
|
80
|
+
PioneInteger.new(rec.value.to_i)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
define_pione_method("as_float", [], TypeFloat) do |rec|
|
|
84
|
+
PioneFloat.new(rec.value.to_f)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
define_pione_method("length", [], TypeInteger) do |rec|
|
|
88
|
+
PioneInteger.new(rec.value.size)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
define_pione_method("include?", [TypeString], TypeBoolean) do |rec, str|
|
|
92
|
+
PioneBoolean.new(rec.value.include?(str.value))
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
define_pione_method("substring",
|
|
96
|
+
[TypeInteger, TypeInteger],
|
|
97
|
+
TypeString) do |rec, nth, len|
|
|
98
|
+
PioneString.new(rec.value[nth.value, len.value])
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# String extention for PIONE system.
|
|
104
|
+
class String
|
|
105
|
+
# Returns PIONE's value.
|
|
106
|
+
# @return [PioneString]
|
|
107
|
+
# PIONE's value
|
|
108
|
+
def to_pione
|
|
109
|
+
PioneString.new(self)
|
|
110
|
+
end
|
|
111
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Pione
|
|
2
|
+
module Model
|
|
3
|
+
class UndefinedValue < BasicModel
|
|
4
|
+
set_pione_model_type TypeUndefinedValue
|
|
5
|
+
|
|
6
|
+
def ==(other)
|
|
7
|
+
return other.kind_of?(UndefinedValue)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
alias :eql? :"=="
|
|
11
|
+
|
|
12
|
+
def hash
|
|
13
|
+
0
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
#
|
|
17
|
+
# pione model method
|
|
18
|
+
#
|
|
19
|
+
define_pione_method("as_string", [], TypeString) do |rec|
|
|
20
|
+
PioneString.new("undefined")
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
module Pione::Model
|
|
2
|
+
# UnboundVariableError represents an unknown variable reference.
|
|
3
|
+
class UnboundVariableError < StandardError
|
|
4
|
+
attr_reader :variable
|
|
5
|
+
|
|
6
|
+
# Creates an error.
|
|
7
|
+
# @param [Variable] variable
|
|
8
|
+
# unbound variable
|
|
9
|
+
def initialize(variable)
|
|
10
|
+
@variable = variable
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# @api private
|
|
14
|
+
def message
|
|
15
|
+
"Refferred unbound variable '%s' in the context." % @variable.name
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# VariableBindingError represents an error that you try to bind different value
|
|
20
|
+
# to a variable.
|
|
21
|
+
class VariableBindingError < StandardError
|
|
22
|
+
attr_reader :variable
|
|
23
|
+
attr_reader :new_value
|
|
24
|
+
attr_reader :old_value
|
|
25
|
+
|
|
26
|
+
# Creates an error.
|
|
27
|
+
# @param [Variable] variable
|
|
28
|
+
# double bound variable
|
|
29
|
+
# @param [BasicModel] new_value
|
|
30
|
+
# new value
|
|
31
|
+
# @param [BasicModel] old_value
|
|
32
|
+
# old value
|
|
33
|
+
def initialize(variable, new_value, old_value)
|
|
34
|
+
@variable = variable
|
|
35
|
+
@new_value = new_value
|
|
36
|
+
@old_value = old_value
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# @api private
|
|
40
|
+
def message
|
|
41
|
+
args = [
|
|
42
|
+
@new_value.textize,
|
|
43
|
+
@variable.name,
|
|
44
|
+
@old_value.textize,
|
|
45
|
+
@variable.line,
|
|
46
|
+
@variable.column
|
|
47
|
+
]
|
|
48
|
+
message = [
|
|
49
|
+
"Try to bind the value '%s' as variable %s, ",
|
|
50
|
+
"but already bound the value '%s'",
|
|
51
|
+
"(line: %s, column: %s)"
|
|
52
|
+
] % args
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# VariableTable represents variable tables for rule context.
|
|
57
|
+
class VariableTable < BasicModel
|
|
58
|
+
set_pione_model_type TypeVariableTable
|
|
59
|
+
|
|
60
|
+
# Returns empty variable table.
|
|
61
|
+
# @return [VariableTable]
|
|
62
|
+
# empty variable table
|
|
63
|
+
def self.empty
|
|
64
|
+
new
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Creates a vairable table.
|
|
68
|
+
# @param [Hash{Variable => BasicModel}] table
|
|
69
|
+
# initial values for the variable table
|
|
70
|
+
def initialize(table={})
|
|
71
|
+
@table = table.to_hash.dup
|
|
72
|
+
super()
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Returns the variable table as hash.
|
|
76
|
+
# @return [Hash{Variable => BasicModel}]
|
|
77
|
+
# hash form of the variable table
|
|
78
|
+
def to_hash
|
|
79
|
+
@table
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Returns the parameters form.
|
|
83
|
+
# @return [Parameters]
|
|
84
|
+
# parameters form of the variable table
|
|
85
|
+
def to_params
|
|
86
|
+
Parameters.new(to_hash)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Returns true if the table is empty.
|
|
90
|
+
# @return [Boolean]
|
|
91
|
+
# true if the table is empty
|
|
92
|
+
def empty?
|
|
93
|
+
@table.empty?
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Gets the variable value and evaluates the value if the value is not
|
|
97
|
+
# atomic.
|
|
98
|
+
# @param [Variable] var
|
|
99
|
+
# table key to get the value
|
|
100
|
+
# @return [BasicModel]
|
|
101
|
+
# the value
|
|
102
|
+
def get(var)
|
|
103
|
+
check_argument_type(var, Variable)
|
|
104
|
+
val = @table[var]
|
|
105
|
+
case val
|
|
106
|
+
when Variable
|
|
107
|
+
next_val = get(val)
|
|
108
|
+
return next_val.nil? ? val : next_val
|
|
109
|
+
when BasicModel
|
|
110
|
+
return not(val.atomic?) ? val.eval(self) : val
|
|
111
|
+
end
|
|
112
|
+
return val
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Sets a new variable. This method raises an exception when the variable has
|
|
116
|
+
# its value already.
|
|
117
|
+
# @param [Variable] variable
|
|
118
|
+
# table key
|
|
119
|
+
# @param [BasicModel] new_value
|
|
120
|
+
# new value
|
|
121
|
+
# @return [VariableTable]
|
|
122
|
+
# new variable table
|
|
123
|
+
def set(variable, new_value)
|
|
124
|
+
check_argument_type(variable, Variable)
|
|
125
|
+
check_argument_type(new_value, BasicModel)
|
|
126
|
+
if old_value = @table[variable]
|
|
127
|
+
unless old_value.kind_of?(UndefinedValue) or new_value == old_value
|
|
128
|
+
raise VariableBindingError.new(variable, new_value, old_value)
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
@table[variable] = new_value
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Sets a variable. This method overrides old variable value.
|
|
135
|
+
# @param [Variable] variable
|
|
136
|
+
# table key
|
|
137
|
+
# @param [BasicModel] new_value
|
|
138
|
+
# new value
|
|
139
|
+
# @return [void]
|
|
140
|
+
def set!(variable, new_value)
|
|
141
|
+
check_argument_type(variable, Variable)
|
|
142
|
+
check_argument_type(new_value, BasicModel)
|
|
143
|
+
@table[variable] = new_value
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Expands variables in the string.
|
|
147
|
+
# @param [String] str
|
|
148
|
+
# string
|
|
149
|
+
# @return [String]
|
|
150
|
+
# expanded string
|
|
151
|
+
def expand(str)
|
|
152
|
+
variables = to_hash
|
|
153
|
+
new_str = str.to_s.gsub(/\{(\$.+?)\}/) do
|
|
154
|
+
expr = DocumentTransformer.new.apply(DocumentParser.new.expr.parse($1))
|
|
155
|
+
expr.eval(self).call_pione_method("as_string").to_ruby
|
|
156
|
+
end
|
|
157
|
+
new_str.gsub(/\<\?\s*(.+?)\s*\?\>/) do
|
|
158
|
+
expr = DocumentTransformer.new.apply(DocumentParser.new.expr.parse($1))
|
|
159
|
+
expr.eval(self).call_pione_method("as_string").to_ruby
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# Returns key variables of the table.
|
|
164
|
+
# @return [Array<Variable>]
|
|
165
|
+
# variable as table keys
|
|
166
|
+
def variables
|
|
167
|
+
@table.keys
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# FIXME
|
|
171
|
+
# Returns true if the string includes variables.
|
|
172
|
+
# @param [String] str
|
|
173
|
+
# target string
|
|
174
|
+
# @return [Boolean]
|
|
175
|
+
# true if the string includes variables
|
|
176
|
+
def self.check_include_variable(str)
|
|
177
|
+
str = str.to_s
|
|
178
|
+
return true if /\{\$(.+?)\}/.match(str)
|
|
179
|
+
str.gsub(/\<\?\s*(.+?)\s*\?\>/) do
|
|
180
|
+
expr = Transformer.new.apply(Parser.new.expr.parse($1))
|
|
181
|
+
return true if expr.include_variable?
|
|
182
|
+
end
|
|
183
|
+
return false
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# Returns true if table's values include variables.
|
|
187
|
+
# @return [Boolean]
|
|
188
|
+
# true if table's values include variables
|
|
189
|
+
def include_variable?
|
|
190
|
+
# FIXME
|
|
191
|
+
@table.values.any?{|val| val.include_variable?}
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
# Makes input auto-variables.
|
|
195
|
+
# @param [Array<DataExpr>] input_exprs
|
|
196
|
+
# input expressions
|
|
197
|
+
# @param [Array<Expr>] input_tuples
|
|
198
|
+
# input tuples
|
|
199
|
+
# @return [void]
|
|
200
|
+
def make_input_auto_variables(input_exprs, input_tuples)
|
|
201
|
+
set(Variable.new("INPUT"), Variable.new("I"))
|
|
202
|
+
input_exprs.each_with_index do |expr, index|
|
|
203
|
+
make_io_auto_variables(:input, expr, input_tuples[index], index+1)
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
# Makes output auto-variables.
|
|
208
|
+
# @param [Array<DataExpr>] output_exprs
|
|
209
|
+
# output expressions
|
|
210
|
+
# @param [Array<DataExpr>] output_tuples
|
|
211
|
+
# output tuples
|
|
212
|
+
# @return [void]
|
|
213
|
+
def make_output_auto_variables(output_exprs, output_tuples)
|
|
214
|
+
set(Variable.new("OUTPUT"), Variable.new("O"))
|
|
215
|
+
output_exprs.each_with_index do |expr, index|
|
|
216
|
+
make_io_auto_variables(:output, expr, output_tuples[index], index+1)
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
# @api private
|
|
221
|
+
def ==(other)
|
|
222
|
+
return false unless other.kind_of?(self.class)
|
|
223
|
+
@table == other.to_hash
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
alias :eql? :"=="
|
|
227
|
+
|
|
228
|
+
# @api private
|
|
229
|
+
def hash
|
|
230
|
+
@table.hash
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
private
|
|
234
|
+
|
|
235
|
+
# Make input or output auto variables.
|
|
236
|
+
# @api private
|
|
237
|
+
def make_io_auto_variables(type, expr, data, index)
|
|
238
|
+
expr = expr.eval(self)
|
|
239
|
+
prefix = (type == :input ? "I" : "O")
|
|
240
|
+
case expr.modifier
|
|
241
|
+
when :all
|
|
242
|
+
make_io_auto_variables_by_all(type, prefix, expr, data)
|
|
243
|
+
when :each
|
|
244
|
+
make_io_auto_variables_by_each(prefix, expr, data, index)
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
# Make input or output auto variables for 'exist' modified data name
|
|
249
|
+
# expression.
|
|
250
|
+
# @api private
|
|
251
|
+
def make_io_auto_variables_by_each(prefix, expr, tuple, index)
|
|
252
|
+
return if tuple.nil?
|
|
253
|
+
# variable
|
|
254
|
+
var = Variable.new(prefix)
|
|
255
|
+
# matched data
|
|
256
|
+
md = expr.match(tuple.name).to_a
|
|
257
|
+
|
|
258
|
+
# setup rule-io list
|
|
259
|
+
list = get(var)
|
|
260
|
+
list = RuleIOList.new unless list
|
|
261
|
+
elt = RuleIOElement.new(PioneString.new(tuple.name))
|
|
262
|
+
elt.uri = PioneString.new(tuple.uri)
|
|
263
|
+
elt.match = PioneList.new(*md.map{|d| PioneString.new(d)})
|
|
264
|
+
|
|
265
|
+
# update the list
|
|
266
|
+
set!(var, list.add(elt))
|
|
267
|
+
|
|
268
|
+
# set special variable if index equals 1
|
|
269
|
+
if prefix == 'I' && index == 1
|
|
270
|
+
set(Variable.new("*"), PioneString.new(md[1]))
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
# Make input or output auto variables for 'all' modified data name
|
|
275
|
+
# expression.
|
|
276
|
+
# @api private
|
|
277
|
+
def make_io_auto_variables_by_all(type, prefix, expr, tuples)
|
|
278
|
+
# FIXME: output
|
|
279
|
+
return if type == :output
|
|
280
|
+
|
|
281
|
+
# variable
|
|
282
|
+
var = Variable.new(prefix)
|
|
283
|
+
|
|
284
|
+
# setup rule-io list
|
|
285
|
+
list = get(var)
|
|
286
|
+
list = RuleIOList.new unless list
|
|
287
|
+
io_list = RuleIOList.new()
|
|
288
|
+
|
|
289
|
+
# convert each tuples
|
|
290
|
+
tuples.each do |tuple, i|
|
|
291
|
+
elt = RuleIOElement.new(PioneString.new(tuple.name))
|
|
292
|
+
elt.uri = PioneString.new(tuple.uri)
|
|
293
|
+
elt.match = PioneList.new(
|
|
294
|
+
*expr.match(tuple.name).to_a.map{|m| PioneString.new(m)}
|
|
295
|
+
)
|
|
296
|
+
io_list.add!(elt)
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
# update
|
|
300
|
+
set!(var, list.add(io_list))
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
#
|
|
304
|
+
# pione methods
|
|
305
|
+
#
|
|
306
|
+
|
|
307
|
+
define_pione_method("get", [TypeString], TypeAny) do |name|
|
|
308
|
+
get(Variable.new(name.value))
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
define_pione_method("keys", [], TypeList.new(TypeString)) do
|
|
312
|
+
PioneList.new(@table.keys.map{|var| PioneString.new(var.name)})
|
|
313
|
+
end
|
|
314
|
+
end
|
|
315
|
+
end
|