story-gen 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS +4 -0
- data/lib/story/compile.rb +32 -10
- metadata +2 -2
data/NEWS
CHANGED
data/lib/story/compile.rb
CHANGED
@@ -498,22 +498,16 @@ class Story
|
|
498
498
|
end
|
499
499
|
to_code = lambda do |operand|
|
500
500
|
case operand
|
501
|
-
when Var then "#{var_arg_valuess}[#{e1.var_args_indexes[operand]}]"
|
501
|
+
when Var then code << "#{var_arg_valuess}[#{e1.var_args_indexes[operand]}]"
|
502
502
|
when Above[Var] then at(operand.pos) { operand.var.name }
|
503
|
-
else operand.to_rb
|
503
|
+
else code << operand.to_rb
|
504
504
|
end
|
505
505
|
end
|
506
|
-
rb_op =
|
507
|
-
case e2.op
|
508
|
-
when "==", "!=", "<=", ">=", "<", ">" then e2.op
|
509
|
-
when "<>", "=/=" then "!="
|
510
|
-
when "=" then "=="
|
511
|
-
end
|
512
506
|
with_var_args(
|
513
507
|
e1.var_args,
|
514
508
|
code << "(" <<
|
515
509
|
e1.to_code << ".select do |#{var_arg_valuess}| "<<
|
516
|
-
at(e2.pos) { to_code.(e2.e1) << rb_op << to_code.(e2.e2) } << " "<<
|
510
|
+
at(e2.pos) { to_code.(e2.e1) << e2.rb_op << to_code.(e2.e2) } << " "<<
|
517
511
|
"end " <<
|
518
512
|
")"
|
519
513
|
)
|
@@ -557,7 +551,35 @@ class Story
|
|
557
551
|
|
558
552
|
end
|
559
553
|
|
560
|
-
FactExpr::Select = ASTNode.new :e1, :op, :e2
|
554
|
+
FactExpr::Select = ASTNode.new :e1, :op, :e2 do
|
555
|
+
|
556
|
+
include FactExpr
|
557
|
+
|
558
|
+
def to_code
|
559
|
+
to_code = lambda do |operand|
|
560
|
+
case operand
|
561
|
+
when Var then raise Parse::Error.new(operand.pos, "not supported")
|
562
|
+
when Above[Var] then at(operand.pos) { operand.var.name }
|
563
|
+
else code << operand.to_rb
|
564
|
+
end
|
565
|
+
end
|
566
|
+
#
|
567
|
+
with_var_args(
|
568
|
+
[],
|
569
|
+
code << "(if " << to_code.(e1) << rb_op << to_code.(e2) << " then [[]] else [] end)"
|
570
|
+
)
|
571
|
+
end
|
572
|
+
|
573
|
+
# @return [String] Ruby analogue of {#op}.
|
574
|
+
def rb_op
|
575
|
+
case op
|
576
|
+
when "==", "!=", "<=", ">=", "<", ">" then op
|
577
|
+
when "<>", "=/=" then "!="
|
578
|
+
when "=" then "=="
|
579
|
+
end
|
580
|
+
end
|
581
|
+
|
582
|
+
end
|
561
583
|
|
562
584
|
FactExpr::Or = ASTNode.new :e1, :e2 do
|
563
585
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: story-gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-02-
|
12
|
+
date: 2016-02-18 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Generate stories from descriptions based on Facts!
|
15
15
|
email: various.furriness@gmail.com
|