ceml 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,13 +22,52 @@ grammar Lexer
22
22
  end
23
23
 
24
24
  rule number
25
- [1-9]+ [0-9]* / '0'
25
+ ([1-9]+ [0-9]* / '0' / 'an' / 'a' / 'the') {
26
+ def value
27
+ case text_value
28
+ when 'a', 'an', 'the' then 1
29
+ else text_value.to_i
30
+ end
31
+ end
32
+ }
33
+ end
34
+
35
+ rule and
36
+ (ws? ',')? ws 'and' ws / ws? ',' ws?
37
+ end
38
+
39
+ rule reserved_word
40
+ 'and' / 'within'
26
41
  end
27
42
 
28
43
  rule id
29
- [a-zA-Z_-]+
44
+ !(reserved_word ws) [a-zA-Z_]+
45
+ end
46
+
47
+ rule distance
48
+ number ws? distance_unit:('miles' / 'mile' / 'mi' / 'km' / 'kilometers' / 'k' / 'meters' / 'm' / 'ft' / 'feet' / 'f' / 'blocks' / 'block')
49
+ {
50
+ def meters
51
+ number.text_value.to_f * case distance_unit.text_value
52
+ when /^mi/; 1600; when /^k/; 1000; when /^m/; 1;
53
+ when /^f/; 0.35; when /^b/; 200; else 1; end
54
+ end
55
+ }
56
+ end
57
+
58
+ rule range
59
+ min:number max:('+' / '-' number)?
60
+ {
61
+ def min
62
+ super.value
63
+ end
64
+ def max
65
+ return min if super.empty?
66
+ return 10000 if super.text_value == '+'
67
+ return super.number.text_value.to_i
68
+ end
69
+ }
30
70
  end
31
71
 
32
72
  end
33
73
  end
34
-
@@ -5,28 +5,43 @@ grammar Scripts
5
5
  include Instructions
6
6
 
7
7
  rule scripts
8
- script+
8
+ script more:(nl script)* {
9
+ def list
10
+ [script] + more.elements.map(&:script)
11
+ end
12
+ }
9
13
  end
10
14
 
11
- rule script
12
- (script_with_title / script_with_instructions) <Script>
15
+ rule free_scripts
16
+ nl? scripts nl?
13
17
  end
14
18
 
15
- rule script_with_title
16
- nl? title casting_statement:casting_statement? instructions:instructions?
19
+ rule free_script
20
+ nl? script nl?
17
21
  end
18
22
 
19
- rule script_with_instructions
20
- nl? title:title? casting_statement:casting_statement? instructions
23
+ rule script
24
+ (
25
+ title nl casting_statement nl instructions /
26
+ title nl instructions /
27
+ casting_statement nl instructions /
28
+ title nl casting_statement /
29
+ instructions /
30
+ title
31
+ ) <Script>
21
32
  end
22
33
 
23
34
  rule title
24
- '"' value:('\\"' / !'"' .)+ '"' nl {
25
- def value
26
- super.text_value.gsub(/\\"/, '"')
35
+ '"' value:('\\"' / !'"' .)+ '"' {
36
+ def title_value
37
+ value.text_value.gsub(/\\"/, '"')
27
38
  end
28
39
  }
29
40
  end
30
41
 
42
+ rule instructions
43
+ instruction_stmt more:(nl instruction_stmt)* <Instructions>
44
+ end
45
+
31
46
  end
32
47
  end
data/lib/ceml.rb CHANGED
@@ -9,6 +9,7 @@ require 'ceml/tt/casting'
9
9
  require 'ceml/tt/instructions'
10
10
  require 'ceml/tt/scripts'
11
11
 
12
+ require 'ceml/casting_criterion'
12
13
  require 'ceml/incident'
13
14
 
14
15
  module CEML
@@ -18,27 +19,25 @@ module CEML
18
19
  # puts "#{meth}: #{args.to_s.inspect}"
19
20
  end
20
21
 
21
- class CEML::ScriptsParser
22
- def parse_with_root(string, root)
23
- self.root = root
24
- parse(string)
25
- end
26
- end
27
-
28
22
  module CEML
29
23
  def parse(what, string)
30
- result = nil
31
24
  string.gsub!(/\n +/, ' ')
32
- string << "\n"
25
+ what = case what
26
+ when :script then :free_script
27
+ when :scripts then :free_scripts
28
+ else what
29
+ end
30
+ result = nil
33
31
  ScriptsParser.new.tap do |parser|
34
- result = parser.parse_with_root(string, what)
32
+ result = parser.parse(string, :root => what)
35
33
  raise "parse failed: \n#{parser.failure_reason}" unless result
36
34
  case what
37
- when :scripts
38
- raise "no scripts found" unless result.elements and !result.elements.empty?
39
- result = result.elements
35
+ when :free_scripts
36
+ raise "no scripts found" unless result.scripts.list
37
+ result = result.scripts.list
40
38
  result.each{ |s| s.validate! }
41
- when :script
39
+ when :free_script
40
+ result = result.script
42
41
  result.validate!
43
42
  end
44
43
  end
data/test/helper.rb CHANGED
@@ -5,25 +5,6 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
6
6
  require 'ceml'
7
7
 
8
- COMPLIMENT_SCRIPT = <<END_OF_SCRIPT
9
- "Overwhelm a specific person with compliments"
10
- gather 5-20 players within 4 blocks
11
- ask organizer re target: Describe their appearance and location
12
- tell agents: Look for |otherguy.target| and compliment them briefly, then move on.
13
- END_OF_SCRIPT
14
-
15
- ASKCHAIN_SCRIPT = <<ENDOFSCRIPT
16
- "Meet your neighbor"
17
- gather 2 players within 1 block
18
- ask players re color: what's your favorite color?
19
- ask players re observation: find someone near you with the color |otherguy.color|. what are they wearing?
20
- ask players re rightmatch: are you wearing |otherguy.observation|?
21
- ask players re task: take your new partner and see if you can find something beautiful in the park.
22
-
23
- ENDOFSCRIPT
24
-
25
-
26
-
27
8
  class Test::Unit::TestCase
28
9
  def play script
29
10
  @e = CEML::Incident.new(script)
data/test/test_casting.rb CHANGED
@@ -24,14 +24,14 @@ class TestCasting < Test::Unit::TestCase
24
24
  def test_range
25
25
  cs = pcs "gather 3-4 runners"
26
26
  assert cs.type == :gather
27
- assert cs.roles.include? :runners
27
+ assert cs.roles.names.include? :runners
28
28
  assert cs[:runners].min == 3
29
29
  assert cs[:runners].max == 4
30
30
  assert cs.max == 4
31
31
 
32
32
  cs = pcs "gather 3+ runners"
33
33
  assert cs.type == :gather
34
- assert cs.roles.include? :runners
34
+ assert cs.roles.names.include? :runners
35
35
  assert cs[:runners].min == 3
36
36
  assert cs[:runners].max > 4
37
37
  assert cs.min == 3
@@ -39,7 +39,7 @@ class TestCasting < Test::Unit::TestCase
39
39
 
40
40
  cs = pcs "gather 3 runners"
41
41
  assert cs.type == :gather
42
- assert cs.roles.include? :runners
42
+ assert cs.roles.names.include? :runners
43
43
  assert cs[:runners].min == 3
44
44
  assert cs[:runners].max == 3
45
45
  assert cs.min == 3
@@ -47,25 +47,24 @@ class TestCasting < Test::Unit::TestCase
47
47
 
48
48
  cs = pcs "gather runners"
49
49
  assert cs.type == :gather
50
- assert cs.roles.include? :runners
50
+ assert cs.roles.names.include? :runners
51
51
  assert cs[:runners].min == 2
52
52
  assert cs[:runners].max > 10
53
53
  assert cs.min == 2
54
54
  assert cs.max > 10
55
55
 
56
- cs = pcs "teams of 1-2 runners and 1 announcer"
57
- assert cs.type == :teams
58
- assert cs.roles.include? :runners
59
- assert cs.roles.include? :announcer
56
+ cs = pcs "gather 1-2 runners and 1 announcer"
57
+ assert cs.type == :gather
58
+ assert cs.roles.names.include? :runners
59
+ assert cs.roles.names.include? :announcer
60
60
  assert cs[:runners].min == 1
61
61
  assert cs[:runners].max == 2
62
62
  assert cs.min == 2
63
- assert cs.max > 20
63
+ assert cs.max == 3
64
64
 
65
65
  cs = pcs "nab 1-2 runners within 4 mi"
66
66
  assert cs.type == :nab
67
67
  assert cs.nab?
68
- assert !cs.in_teams?
69
68
  assert cs[:runners].min == 1
70
69
  assert cs[:runners].max == 2
71
70
  end
@@ -1,8 +1,33 @@
1
1
  require 'ceml'
2
2
  require 'test/helper'
3
3
 
4
+ COMPLIMENT_SCRIPT = <<XXX
5
+ "Overwhelm a specific person with compliments"
6
+ gather 5-20 players within 4 blocks
7
+ ask organizer re target: Describe their appearance and location
8
+ tell agents: Look for |otherguy.target| and compliment them briefly, then move on.
9
+ XXX
10
+
11
+ ASKCHAIN_SCRIPT = <<XXX
12
+ "Meet your neighbor"
13
+ gather 2 players within 1 block
14
+ ask players re color: what's your favorite color?
15
+ ask players re observation: find someone near you with the color |otherguy.color|. what are they wearing?
16
+ ask players re rightmatch: are you wearing |otherguy.observation|?
17
+ ask players re task: take your new partner and see if you can find something beautiful in the park.
18
+ XXX
19
+
20
+
4
21
  class TestIncident < Test::Unit::TestCase
5
22
 
23
+ SIGNUP_SCRIPT = "await 1 new signup\ntell signup: thanks"
24
+ def test_signup_script
25
+ s = CEML.parse(:script, SIGNUP_SCRIPT)
26
+ c = CEML::Candidate.new('fred', ['new'], {}, nil, nil)
27
+ s.post c
28
+ assert s.launchable_location
29
+ end
30
+
6
31
  def test_incident
7
32
  play COMPLIMENT_SCRIPT
8
33
  player :joe, :organizer, :agent
@@ -18,10 +18,10 @@ class TestInstructions < Test::Unit::TestCase
18
18
  end
19
19
 
20
20
  def test_instructions
21
- assert_equal "run to the kitchen", pi('tell joe: run to the kitchen').tell([:joe]).text
21
+ assert_equal "run to the kitchen", pi('tell joe: run to the kitchen').i_tell([:joe]).text
22
22
  assert_equal ["favorite color?", "favorite soup?"], pi(
23
23
  "ask joe re color: favorite color?\nask joe re soup: favorite soup?"
24
- ).asks([:joe]).map(&:text)
24
+ ).i_asks([:joe]).map(&:text)
25
25
  end
26
26
 
27
27
  end
data/test/test_scripts.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'ceml'
2
2
 
3
- class TestInstructions < Test::Unit::TestCase
3
+ class TestScripts < Test::Unit::TestCase
4
4
 
5
5
  SCRIPTS = <<END_OF_SCRIPTS
6
6
  "Help moving |an object|" // okay?
data/try ADDED
@@ -0,0 +1,14 @@
1
+ #! /usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'ceml'
4
+ require 'pp'
5
+
6
+ begin
7
+ str = ARGV[1] ? ARGV[1].dup : STDIN.read
8
+ p = CEML::ScriptsParser.new
9
+ if result = p.parse(str, :root => ARGV[0].to_sym)
10
+ puts "worked!" # #{p.inspect}"
11
+ else
12
+ puts p.failure_reason
13
+ end
14
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 0
9
- version: 0.3.0
8
+ - 1
9
+ version: 0.3.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Joe Edelman
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-24 00:00:00 -08:00
17
+ date: 2010-12-26 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -47,6 +47,7 @@ files:
47
47
  - Rakefile
48
48
  - VERSION
49
49
  - beginners-guide.md
50
+ - ceml.gemspec
50
51
  - editors/CEML.tmbundle/Syntaxes/ceml.tmLanguage
51
52
  - editors/CEML.tmbundle/info.plist
52
53
  - examples/breakfast-exchange.ceml
@@ -54,22 +55,20 @@ files:
54
55
  - examples/high-fives.ceml
55
56
  - lib/ceml.rb
56
57
  - lib/ceml/casting.rb
58
+ - lib/ceml/casting_criterion.rb
57
59
  - lib/ceml/incident.rb
58
60
  - lib/ceml/instructions.rb
59
61
  - lib/ceml/script.rb
60
- - lib/ceml/tt/casting.rb
61
62
  - lib/ceml/tt/casting.treetop
62
- - lib/ceml/tt/instructions.rb
63
63
  - lib/ceml/tt/instructions.treetop
64
- - lib/ceml/tt/lexer.rb
65
64
  - lib/ceml/tt/lexer.treetop
66
- - lib/ceml/tt/scripts.rb
67
65
  - lib/ceml/tt/scripts.treetop
68
66
  - test/helper.rb
69
67
  - test/test_casting.rb
70
68
  - test/test_incident.rb
71
69
  - test/test_instructions.rb
72
70
  - test/test_scripts.rb
71
+ - try
73
72
  has_rdoc: true
74
73
  homepage: http://github.com/citizenlogistics/ceml
75
74
  licenses: []
@@ -106,3 +105,4 @@ test_files:
106
105
  - test/test_incident.rb
107
106
  - test/test_instructions.rb
108
107
  - test/test_scripts.rb
108
+ - examples/sample_delegate.rb