story-gen 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.yardopts CHANGED
@@ -1,2 +1,4 @@
1
1
  --protected
2
2
  --hide-api private
3
+ --files sample/*
4
+ --load yardopts_extra.rb
data/README.md CHANGED
@@ -258,11 +258,6 @@ Top-level statements may also be delimited with dot ("."):
258
258
  "Sabrina" is a girl.
259
259
  "John" loves "Liza".
260
260
 
261
- "If" statement may include a comma before `then` and `or`:
262
-
263
- If X is a boy, then "we know "X,
264
- or if Y is a girl, then "we know "Y
265
-
266
261
  There is another form of the statements combination:
267
262
 
268
263
  if X is a boy then:
@@ -274,11 +269,25 @@ Keywords `if`, `either`, `or`, `for` (in `for all`) and `while` may start with a
274
269
 
275
270
  You may also use russian keywords! ;)
276
271
 
277
- Examples
278
- --------
272
+ ### Mods ###
273
+
274
+ When `-m` or `--allow-comma-in-facts` is passed to `story`, the optional comma in "while" and "for all" becomes disallowed:
275
+
276
+ For all A, B, C loves D, "Love quadrangle!"; /* ERROR, ambiguity! */
277
+ For all A, B, C loves D: "Love quadrangle!". /* OK */
278
+ For all A, B, C loves D ("Love quadrangle!"); /* OK too */
279
+
280
+ Trailing comma in Fact expression is ignored:
281
+
282
+ For all X loves Y, ("Someone loves other one!")
283
+ /* is the same as */
284
+ For all X loves Y ("Someone loves other one!")
279
285
 
280
- See them in "sample" directory!
286
+ If (A loves B,) and (B loves C,) then ...
287
+ /* is the same as */
288
+ If (A loves B) and (B loves C) then ...
281
289
 
282
- You may find the "sample" directory with
290
+ Examples
291
+ --------
283
292
 
284
- story --samples
293
+ See them in "sample" directory (you may get it with `story --samples`)! Or in YARD doc's "File list"!
data/bin/story CHANGED
@@ -6,6 +6,7 @@ require 'story/samples_dir'
6
6
  $output_file = nil
7
7
  $input_file = nil
8
8
  $story_class_name = nil
9
+ $allow_comma_in_facts = false
9
10
  $process = lambda do |story_class_code, output|
10
11
  # execute the story
11
12
  story_class = eval story_class_code
@@ -34,14 +35,19 @@ OptionParser.new do |opts|
34
35
  "instead of an anonymous class" do |name|
35
36
  $story_class_name = name
36
37
  end
37
- opts.on "-r", "--show-relations", "Show relations mentioned in the story" do
38
+ opts.on "-m", "--allow-comma-in-facts", "Allow `,' in Fact expressions",
39
+ "(see `Mods' in README)" do
40
+ $allow_comma_in_facts = true
41
+ end
42
+ opts.on "-r", "--show-relations", "Show relations mentioned in the story",
43
+ "(useful for debug)" do
38
44
  $process = lambda do |story_class_code, output|
39
45
  story_class = eval story_class_code
40
46
  story = story_class.new
41
47
  story.relations.each { |relation| output.puts relation }
42
48
  end
43
49
  end
44
- opts.on "--samples", "Show directory with samples and exit" do
50
+ opts.on "-S", "--samples", "Show directory with samples and exit" do
45
51
  puts Story::SAMPLES_DIR
46
52
  exit
47
53
  end
@@ -61,7 +67,7 @@ begin
61
67
  end
62
68
  story_class_code =
63
69
  begin
64
- Story.compile(input_text, $input_file || "-")
70
+ Story.compile(input_text, $input_file || "-", $allow_comma_in_facts)
65
71
  rescue Parse::Error => e
66
72
  abort "error: #{e.pos.file}:#{e.pos.line+1}:#{e.pos.column+1}: #{e.message}"
67
73
  end
@@ -84,4 +90,6 @@ begin
84
90
  end
85
91
  rescue IOError => e
86
92
  abort "error: #{e.message}"
93
+ rescue SystemCallError => e
94
+ abort "error: #{e.message}"
87
95
  end
data/lib/story/compile.rb CHANGED
@@ -21,12 +21,16 @@ class Story
21
21
 
22
22
  # @param [String] text
23
23
  # @param [String] file a file the +text+ is taken from.
24
+ # @param [Boolean] allow_comma_in_fact_expr_primary
24
25
  # @return [String] a {String} which {Kernel#eval}s to a {Class} which
25
26
  # inherits {Story}.
26
27
  # @raise [Parse::Error]
27
- def self.compile(text, file = "-")
28
+ def self.compile(text, file = "-", allow_comma_in_fact_expr_primary = false)
28
29
  #
29
- c = Parse.new.(text, file).to_code
30
+ c = Parse.new.
31
+ tap { |p| p.allow_comma_in_fact_expr_primary = allow_comma_in_fact_expr_primary }.
32
+ (text, file).
33
+ to_code
30
34
  #
31
35
  relation_id_to_var_arg_valuesss_var = Hash.new do |h, relation_id|
32
36
  h[relation_id] = "@#{INTERNAL_VAR_PREFIX}var_arg_valuesss#{h.size}"
@@ -594,6 +598,14 @@ class Story
594
598
  # @!visibility private
595
599
  class Parse < ::Parse
596
600
 
601
+ # ---------------
602
+ # @!group Options
603
+ # ---------------
604
+
605
+ # @return [Boolean] is "," in {#fact_expr_primary} allowed? Default is
606
+ # false.
607
+ attr_accessor :allow_comma_in_fact_expr_primary
608
+
597
609
  # --------------
598
610
  # @!group Syntax
599
611
  # --------------
@@ -732,12 +744,14 @@ class Story
732
744
  end
733
745
 
734
746
  rule :fact_expr_primary do
747
+ allow_comma = allow_comma_in_fact_expr_primary
735
748
  relation_id = []
736
749
  args = []
737
750
  negated = false
738
751
  #
739
752
  one_or_more {
740
753
  _{ s = (_{dash} or _{other_char}) and act { relation_id << s } } or
754
+ _{ allow_comma and s = comma and act { relation_id << s } } or
741
755
  _{ a = asterisk and act { args << a; relation_id << :* } } or
742
756
  _{ _not_ and act { negated = !negated } } or
743
757
  _{ v = value and act { args << v; relation_id << :* } } or
@@ -745,7 +759,7 @@ class Story
745
759
  _{ v = above_var and act { args << v; relation_id << :* } } or
746
760
  _{ w = word and act { relation_id << w.ru_downcase } }
747
761
  } and
748
- # act { relation_id.chomp!(",") } and
762
+ act { relation_id.chomp!(",") } and
749
763
  # this is not a "statement_tell" and
750
764
  not relation_id.all? { |p| p == :* } and
751
765
  e = _(FactExpr::Primary[relation_id, args]) and
@@ -1,6 +1,6 @@
1
1
 
2
2
  class Story
3
3
 
4
- SAMPLES_DIR = "#{File.dirname __FILE__}/../../sample"
4
+ SAMPLES_DIR = File.expand_path "#{File.dirname __FILE__}/../../sample"
5
5
 
6
6
  end
@@ -1,3 +1,5 @@
1
+ (note: this is a sample story written in SDL - Story Description Language)
2
+
1
3
  "
2
4
  Fight club
3
5
  ==========
@@ -1,3 +1,5 @@
1
+ (note: this is a sample story written in SDL - Story Description Language)
2
+
1
3
  "Oliver" is a boy.
2
4
  "Sam" is a boy.
3
5
  "Nathan" is a boy.
@@ -1,3 +1,5 @@
1
+ (прим.: это пример стории, написанной на SDL - Языке Описания Историй)
2
+
1
3
  "
2
4
  Бойцовский клуб
3
5
  ===============
@@ -1,3 +1,5 @@
1
+ (прим.: это пример стории, написанной на SDL - Языке Описания Историй)
2
+
1
3
  "Слава" - самец.
2
4
  "Вова" - самец.
3
5
  "Юрий" - самец.
@@ -0,0 +1,71 @@
1
+ (прим.: это пример стории, написанной на SDL - Языке Описания Историй)
2
+
3
+ "Слава" - самец.
4
+ "Вова" - самец.
5
+ "Юрий" - самец.
6
+ "Борис" - самец.
7
+ "Гриша" - самец.
8
+ "Зоя" - самка.
9
+ "Вика" - самка.
10
+ "Света" - самка.
11
+ "Лиля" - самка.
12
+ "Юля" - самка.
13
+
14
+ "
15
+ Университет
16
+ ===========
17
+ "
18
+ nl
19
+
20
+ "Как-то раз в университет поступили "; для всех X - самец или X - самка, X", ";
21
+ "вот. Они быстро стали друзьями и часто гуляли все вместе. "
22
+
23
+ Для всех X - самец или X - самка: X свободен.
24
+
25
+ Пока * свободен:
26
+ если X свободен и Y свободен и X <> Y, то:
27
+ либо:
28
+ "Как-то раз они все вместе пошли в бар. Было много танцев. ";
29
+ либо
30
+ "" (прим.: это значит "ничего не делать")
31
+ либо:
32
+ ""X" и "Y" танцевали в основном вместе. Они понравились друг другу и вскоре влюбились! ";
33
+ X любит Y;
34
+ X не свободен;
35
+ Y не свободен;
36
+ .
37
+ .
38
+ Либо:
39
+ "Как-то раз "X" и "Y" встретились в общежитии на кухне. ";
40
+ либо
41
+ "Они приятно побеседовали и приготовили вкусный ужин. "
42
+ либо:
43
+ "Они очень много беседовали и вместе приготовили отменный ужин. ";
44
+ "Вскоре они поняли, что любят друг друга! ";
45
+ X любит Y;
46
+ X не свободен;
47
+ Y не свободен;
48
+ .
49
+ .
50
+ Либо:
51
+ "Как-то раз "X" и "Y" сидели на лекции и постоянно оглядывались друг на друга. ";
52
+ либо
53
+ "После лекций они пошли домой и делали уроки. "
54
+ либо:
55
+ если ^X - самец, то "После лекций "X" поймал "Y" и сказал ";
56
+ или если ^X - самка, то "После лекций "X" поймала "Y" и сказала ";
57
+ если ^Y - самка, то "ей, что любит её! ";
58
+ или если ^Y - самец, то "ему, что любит его! ";
59
+ X любит Y;
60
+ X не свободен;
61
+ Y не свободен;
62
+ .
63
+ .
64
+ .
65
+ .
66
+
67
+ nl
68
+ nl
69
+ "И жили они долго и счастливо!". Если X любит Y и ((X - самец и Y - самец) или (X - самка и Y - самка)), то " Правда, роскомнадзорненько как-то получилось.";
70
+ nl
71
+ nl
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.0.2
4
+ version: 0.0.3
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-01-30 00:00:00.000000000 Z
12
+ date: 2016-01-31 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
@@ -46,6 +46,7 @@ files:
46
46
  - sample/университет.sdl
47
47
  - sample/бойцовский_клуб.sdl
48
48
  - sample/university.sdl
49
+ - sample/университет_2.sdl
49
50
  - bin/story
50
51
  homepage:
51
52
  licenses: