gisele-language 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/CHANGELOG.md +5 -0
  2. data/Gemfile +12 -0
  3. data/Gemfile.lock +26 -0
  4. data/LICENCE.md +22 -0
  5. data/Manifest.txt +13 -0
  6. data/README.md +7 -0
  7. data/Rakefile +11 -0
  8. data/gisele-language.gemspec +188 -0
  9. data/gisele-language.noespec +24 -0
  10. data/lib/gisele/language/ast/bool_and.rb +14 -0
  11. data/lib/gisele/language/ast/bool_expr.rb +22 -0
  12. data/lib/gisele/language/ast/bool_not.rb +14 -0
  13. data/lib/gisele/language/ast/bool_or.rb +14 -0
  14. data/lib/gisele/language/ast/case_st.rb +14 -0
  15. data/lib/gisele/language/ast/else_clause.rb +14 -0
  16. data/lib/gisele/language/ast/elsif_clause.rb +14 -0
  17. data/lib/gisele/language/ast/if_st.rb +14 -0
  18. data/lib/gisele/language/ast/node.rb +35 -0
  19. data/lib/gisele/language/ast/task_call_st.rb +14 -0
  20. data/lib/gisele/language/ast/var_ref.rb +14 -0
  21. data/lib/gisele/language/ast/when_clause.rb +14 -0
  22. data/lib/gisele/language/ast/while_st.rb +14 -0
  23. data/lib/gisele/language/grammar.citrus +236 -0
  24. data/lib/gisele/language/grammar.sexp.yml +83 -0
  25. data/lib/gisele/language/processors/elsif_flattener.rb +36 -0
  26. data/lib/gisele/language/processors/if_to_case.rb +65 -0
  27. data/lib/gisele/language/processors/scoping_helper.rb +32 -0
  28. data/lib/gisele/language/processors/sugar_removal.rb +17 -0
  29. data/lib/gisele/language/processors.rb +4 -0
  30. data/lib/gisele/language/syntax/bool_and.rb +14 -0
  31. data/lib/gisele/language/syntax/bool_expr.rb +14 -0
  32. data/lib/gisele/language/syntax/bool_lit.rb +14 -0
  33. data/lib/gisele/language/syntax/bool_not.rb +14 -0
  34. data/lib/gisele/language/syntax/bool_or.rb +14 -0
  35. data/lib/gisele/language/syntax/bool_paren.rb +14 -0
  36. data/lib/gisele/language/syntax/case_st.rb +19 -0
  37. data/lib/gisele/language/syntax/else_clause.rb +14 -0
  38. data/lib/gisele/language/syntax/elsif_clause.rb +16 -0
  39. data/lib/gisele/language/syntax/event_set.rb +15 -0
  40. data/lib/gisele/language/syntax/fluent_def.rb +18 -0
  41. data/lib/gisele/language/syntax/if_st.rb +18 -0
  42. data/lib/gisele/language/syntax/implicit_seq_st.rb +16 -0
  43. data/lib/gisele/language/syntax/node.rb +40 -0
  44. data/lib/gisele/language/syntax/par_st.rb +14 -0
  45. data/lib/gisele/language/syntax/seq_st.rb +14 -0
  46. data/lib/gisele/language/syntax/st_list.rb +14 -0
  47. data/lib/gisele/language/syntax/task_call_st.rb +14 -0
  48. data/lib/gisele/language/syntax/task_def.rb +18 -0
  49. data/lib/gisele/language/syntax/trackvar_def.rb +19 -0
  50. data/lib/gisele/language/syntax/unit_def.rb +14 -0
  51. data/lib/gisele/language/syntax/var_ref.rb +14 -0
  52. data/lib/gisele/language/syntax/when_clause.rb +16 -0
  53. data/lib/gisele/language/syntax/while_st.rb +16 -0
  54. data/lib/gisele/language.rb +31 -0
  55. data/lib/gisele-language/loader.rb +3 -0
  56. data/lib/gisele-language/version.rb +16 -0
  57. data/lib/gisele-language.rb +19 -0
  58. data/spec/fixtures/tasks/complete.gis +40 -0
  59. data/spec/fixtures/tasks/simple.ast +51 -0
  60. data/spec/fixtures/tasks/simple.gis +16 -0
  61. data/spec/language/ast/test_bool_expr.rb +50 -0
  62. data/spec/language/grammar_sexp/test_case_st.rb +20 -0
  63. data/spec/language/grammar_sexp/test_event_set.rb +14 -0
  64. data/spec/language/grammar_sexp/test_fluent_def.rb +18 -0
  65. data/spec/language/grammar_sexp/test_initially.rb +18 -0
  66. data/spec/language/grammar_sexp/test_nop_st.rb +10 -0
  67. data/spec/language/grammar_sexp/test_when_clause.rb +12 -0
  68. data/spec/language/processors/test_elsif_flattener.rb +94 -0
  69. data/spec/language/processors/test_if_to_case.rb +105 -0
  70. data/spec/language/processors/test_scoping_helper.rb +45 -0
  71. data/spec/language/syntax/grammar/test_bool_expr.rb +34 -0
  72. data/spec/language/syntax/grammar/test_boolean_literal.rb +17 -0
  73. data/spec/language/syntax/grammar/test_case_st.rb +60 -0
  74. data/spec/language/syntax/grammar/test_event.rb +18 -0
  75. data/spec/language/syntax/grammar/test_event_name.rb +21 -0
  76. data/spec/language/syntax/grammar/test_event_set.rb +26 -0
  77. data/spec/language/syntax/grammar/test_fluent_def.rb +21 -0
  78. data/spec/language/syntax/grammar/test_if_st.rb +21 -0
  79. data/spec/language/syntax/grammar/test_par_st.rb +11 -0
  80. data/spec/language/syntax/grammar/test_process_statement.rb +19 -0
  81. data/spec/language/syntax/grammar/test_seq_st.rb +11 -0
  82. data/spec/language/syntax/grammar/test_spaces.rb +19 -0
  83. data/spec/language/syntax/grammar/test_spacing.rb +17 -0
  84. data/spec/language/syntax/grammar/test_task_def.rb +35 -0
  85. data/spec/language/syntax/grammar/test_task_name.rb +19 -0
  86. data/spec/language/syntax/grammar/test_task_start_or_end.rb +17 -0
  87. data/spec/language/syntax/grammar/test_trackvar_def.rb +21 -0
  88. data/spec/language/syntax/grammar/test_unit_def.rb +29 -0
  89. data/spec/language/syntax/grammar/test_variable_name.rb +51 -0
  90. data/spec/language/syntax/grammar/test_when_clause.rb +21 -0
  91. data/spec/language/syntax/grammar/test_while_st.rb +11 -0
  92. data/spec/language/syntax/to_ast/test_bool_expr.rb +32 -0
  93. data/spec/language/syntax/to_ast/test_case_st.rb +47 -0
  94. data/spec/language/syntax/to_ast/test_else_clause.rb +13 -0
  95. data/spec/language/syntax/to_ast/test_elsif_clause.rb +15 -0
  96. data/spec/language/syntax/to_ast/test_event_set.rb +24 -0
  97. data/spec/language/syntax/to_ast/test_fluent_def.rb +26 -0
  98. data/spec/language/syntax/to_ast/test_if_st.rb +39 -0
  99. data/spec/language/syntax/to_ast/test_par_st.rb +12 -0
  100. data/spec/language/syntax/to_ast/test_seq_st.rb +12 -0
  101. data/spec/language/syntax/to_ast/test_task_call_st.rb +10 -0
  102. data/spec/language/syntax/to_ast/test_task_def.rb +44 -0
  103. data/spec/language/syntax/to_ast/test_trackvar_def.rb +26 -0
  104. data/spec/language/syntax/to_ast/test_unit_def.rb +28 -0
  105. data/spec/language/syntax/to_ast/test_var_ref.rb +12 -0
  106. data/spec/language/syntax/to_ast/test_when_clause.rb +15 -0
  107. data/spec/language/syntax/to_ast/test_while_st.rb +24 -0
  108. data/spec/language/test_syntax.rb +51 -0
  109. data/spec/spec_helper.rb +44 -0
  110. data/spec/test_gisele-language.rb +8 -0
  111. data/tasks/gem.rake +73 -0
  112. data/tasks/spec_test.rake +71 -0
  113. metadata +269 -0
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ module Gisele::Language::Syntax
3
+ describe BoolExpr, "to_ast" do
4
+
5
+ it 'is correctly extended by Sexpr' do
6
+ ast("true", :bool_expr).should be_a(Gisele::Language::AST::BoolExpr)
7
+ end
8
+
9
+ it 'returns expected ast on simple expressions' do
10
+ expected = \
11
+ [:bool_expr, [:bool_and, [:var_ref, "diagKnown"], [:var_ref, "platLow"]]]
12
+ ast("diagKnown and platLow", :bool_expr).should eq(expected)
13
+ end
14
+
15
+ it 'respects priorities' do
16
+ expected = [:bool_expr,
17
+ [:bool_or, [:bool_and, [:var_ref, "diagKnown"], [:var_ref, "platLow"]], [:var_ref, "platHigh"]]]
18
+ ast("diagKnown and platLow or platHigh", :bool_expr).should eq(expected)
19
+ end
20
+
21
+ it 'supports double negations' do
22
+ expected = [:bool_expr, [:bool_not, [:bool_not, [:var_ref, "diagKnown"]]]]
23
+ ast("not not(diagKnown)", :bool_expr).should eq(expected)
24
+ end
25
+
26
+ it 'makes boolean literals explicit' do
27
+ ast("true", :bool_expr).should eq([:bool_expr, [:bool_lit, true]])
28
+ ast("false", :bool_expr).should eq([:bool_expr, [:bool_lit, false]])
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+ module Gisele::Language::Syntax
3
+ describe CaseSt, "to_ast" do
4
+
5
+ it 'arranges when clauses as expected' do
6
+ expr = <<-CASE_ST.strip
7
+ case
8
+ when good
9
+ Task1
10
+ when bad
11
+ Task2
12
+ end
13
+ CASE_ST
14
+ when_clause1 = ast("when good Task1", :when_clause)
15
+ when_clause2 = ast("when bad Task2", :when_clause)
16
+ expected = [:case_st, nil, when_clause1, when_clause2]
17
+ ast(expr, :case_st).should eq(expected)
18
+ end
19
+
20
+ it 'puts the else clause at the end' do
21
+ expr = <<-CASE_ST.strip
22
+ case
23
+ when good
24
+ Task1
25
+ else
26
+ Task2
27
+ end
28
+ CASE_ST
29
+ when_clause = ast("when good Task1", :when_clause)
30
+ else_clause = ast("else Task2", :else_clause)
31
+ expected = [:case_st, nil, when_clause, else_clause]
32
+ ast(expr, :case_st).should eq(expected)
33
+ end
34
+
35
+ it 'supports an optional variable name' do
36
+ expr = <<-CASE_ST.strip
37
+ case someVariable
38
+ when good
39
+ Task1
40
+ end
41
+ CASE_ST
42
+ expected = [:var_ref, "someVariable"]
43
+ ast(expr, :case_st)[1].should eq(expected)
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+ module Gisele::Language::Syntax
3
+ describe ElseClause, "to_ast" do
4
+
5
+ it 'parses as expected' do
6
+ expr = "else Task1"
7
+ expected = \
8
+ [:else_clause, [:task_call_st, "Task1"]]
9
+ ast(expr, :else_clause).should eq(expected)
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+ module Gisele::Language::Syntax
3
+ describe ElsifClause, "to_ast" do
4
+
5
+ it 'parses as expected' do
6
+ expr = "elsif goodCond Task1"
7
+ expected = \
8
+ [:elsif_clause,
9
+ [:bool_expr, [:var_ref, "goodCond"]],
10
+ [:task_call_st, "Task1"]]
11
+ ast(expr, :elsif_clause).should eq(expected)
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ module Gisele::Language::Syntax
3
+ describe EventSet, "to_ast" do
4
+
5
+ it 'converts empty lists as expected' do
6
+ expr = '{ }'
7
+ expected = [:event_set]
8
+ ast(expr, :event_set).should eq(expected)
9
+ end
10
+
11
+ it 'converts singleton lists as expected' do
12
+ expr = '{Diagnosis:start}'
13
+ expected = [:event_set, "Diagnosis:start"]
14
+ ast(expr, :event_set).should eq(expected)
15
+ end
16
+
17
+ it 'converts non empty lists as expected' do
18
+ expr = '{Diagnosis:start, an_event, another_one}'
19
+ expected = [:event_set, "Diagnosis:start", "an_event", "another_one"]
20
+ ast(expr, :event_set).should eq(expected)
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+ module Gisele::Language::Syntax
3
+ describe FluentDef, "to_ast" do
4
+
5
+ it 'converts fluent definitions as expected' do
6
+ defn = "fluent diagKnown {Diagnosis:start, diagnosis}, {Treatment:end} initially false"
7
+ expected = [:fluent_def,
8
+ "diagKnown",
9
+ [:event_set, "Diagnosis:start", "diagnosis"],
10
+ [:event_set, "Treatment:end"],
11
+ false]
12
+ ast(defn, :fluent_def).should eq(expected)
13
+ end
14
+
15
+ it 'does not require the initial value' do
16
+ defn = "fluent diagKnown {Diagnosis:start, diagnosis}, {Treatment:end}"
17
+ expected = [:fluent_def,
18
+ "diagKnown",
19
+ [:event_set, "Diagnosis:start", "diagnosis"],
20
+ [:event_set, "Treatment:end"],
21
+ nil]
22
+ ast(defn, :fluent_def).should eq(expected)
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ module Gisele::Language::Syntax
3
+ describe IfSt, "to_ast" do
4
+
5
+ it 'parses as expected' do
6
+ expr = "if goodCond Task1 end"
7
+ expected = \
8
+ [:if_st,
9
+ [:bool_expr, [:var_ref, "goodCond"]],
10
+ [:task_call_st, "Task1"]]
11
+ ast(expr, :if_st).should eq(expected)
12
+ end
13
+
14
+ it 'supports a else clause' do
15
+ expr = "if goodCond Task1 else Task2 end"
16
+ expected = \
17
+ [:if_st,
18
+ [:bool_expr, [:var_ref, "goodCond"]],
19
+ [:task_call_st, "Task1"],
20
+ [:else_clause, [:task_call_st, "Task2"]] ]
21
+ ast(expr, :if_st).should eq(expected)
22
+ end
23
+
24
+ it 'supports elsif clauses' do
25
+ expr = "if goodCond Task1 elsif otherCond Task2 elsif stillAnother Task3 else Task4 end"
26
+ expected = \
27
+ [:if_st,
28
+ [:bool_expr, [:var_ref, "goodCond"]], [:task_call_st, "Task1"],
29
+ [:elsif_clause,
30
+ [:bool_expr, [:var_ref, "otherCond"]], [:task_call_st, "Task2"]],
31
+ [:elsif_clause,
32
+ [:bool_expr, [:var_ref, "stillAnother"]], [:task_call_st, "Task3"]],
33
+ [:else_clause,
34
+ [:task_call_st, "Task4"]] ]
35
+ ast(expr, :if_st).should eq(expected)
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ module Gisele::Language::Syntax
3
+ describe ParSt, "to_ast" do
4
+
5
+ it 'parses as expected' do
6
+ expr = "par Task1 Task2 end"
7
+ expected = [:par_st, [:task_call_st, "Task1"], [:task_call_st, "Task2"]]
8
+ ast(expr, :par_st).should eq(expected)
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ module Gisele::Language::Syntax
3
+ describe SeqSt, "to_ast" do
4
+
5
+ it 'parses as expected' do
6
+ expr = "seq Task1 Task2 end"
7
+ expected = [:seq_st, [:task_call_st, "Task1"], [:task_call_st, "Task2"]]
8
+ ast(expr, :seq_st).should eq(expected)
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ module Gisele::Language::Syntax
3
+ describe TaskCallSt, "to_ast" do
4
+
5
+ it 'converts a call as expected' do
6
+ ast("Diagnosis", :task_call_st).should eq([:task_call_st, "Diagnosis"])
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ module Gisele::Language::Syntax
3
+ describe TaskDef, "to_ast" do
4
+
5
+ it 'parses an explicit definition as expected' do
6
+ expr = <<-EXPR.strip
7
+ task Task1
8
+ fluent diagKnown {}, {}
9
+ Task2
10
+ end
11
+ EXPR
12
+ expected = \
13
+ [:task_def, "Task1",
14
+ [:fluent_def, "diagKnown", [:event_set], [:event_set], nil],
15
+ [:task_call_st, "Task2"]]
16
+ ast(expr, :task_def).should eq(expected)
17
+ end
18
+
19
+ it 'uses :nop_st if no statement' do
20
+ expr = <<-EXPR.strip
21
+ task Task1
22
+ fluent diagKnown {}, {}
23
+ end
24
+ EXPR
25
+ expected = \
26
+ [:task_def, "Task1",
27
+ [:fluent_def, "diagKnown", [:event_set], [:event_set], nil],
28
+ [:nop_st]]
29
+ ast(expr, :task_def).should eq(expected)
30
+ end
31
+
32
+ it 'uses :nop_st when empty' do
33
+ expr = <<-EXPR.strip
34
+ task Task1
35
+ end
36
+ EXPR
37
+ expected = \
38
+ [:task_def, "Task1",
39
+ [:nop_st]]
40
+ ast(expr, :task_def).should eq(expected)
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+ module Gisele::Language::Syntax
3
+ describe TrackvarDef, "to_ast" do
4
+
5
+ it 'converts tracking variable definitions as expected' do
6
+ defn = "trackvar mplus {Diagnosis:start}"
7
+ expected = [:trackvar_def,
8
+ "mplus",
9
+ [:event_set, "Diagnosis:start"],
10
+ [:event_set],
11
+ nil]
12
+ ast(defn, :trackvar_def).should eq(expected)
13
+ end
14
+
15
+ it 'supports obsolete events and initial value' do
16
+ defn = "trackvar mplus {Diagnosis:start}, {Treatment:end} initially true"
17
+ expected = [:trackvar_def,
18
+ "mplus",
19
+ [:event_set, "Diagnosis:start"],
20
+ [:event_set, "Treatment:end"],
21
+ true]
22
+ ast(defn, :trackvar_def).should eq(expected)
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ module Gisele::Language::Syntax
3
+ describe UnitDef, 'to_ast' do
4
+
5
+ it 'converts a single task definition as expected' do
6
+ expr = <<-UNIT.strip
7
+ task Task1 end
8
+ UNIT
9
+ expected = \
10
+ [:unit_def,
11
+ [:task_def, "Task1", [:nop_st]]]
12
+ ast(expr, :unit_def).should eq(expected)
13
+ end
14
+
15
+ it 'accepts multiple task definitions' do
16
+ expr = <<-UNIT.strip
17
+ task Task1 end
18
+ task Task2 end
19
+ UNIT
20
+ expected = \
21
+ [:unit_def,
22
+ [:task_def, "Task1", [:nop_st]],
23
+ [:task_def, "Task2", [:nop_st]] ]
24
+ ast(expr, :unit_def).should eq(expected)
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ module Gisele::Language::Syntax
3
+ describe VarRef, "to_ast" do
4
+
5
+ it 'converts a reference as expected' do
6
+ defn = "goodCond"
7
+ expected = [:var_ref, "goodCond"]
8
+ ast(defn, :var_ref).should eq(expected)
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+ module Gisele::Language::Syntax
3
+ describe WhenClause, 'to_ast' do
4
+
5
+ it 'converts a when clause as expected' do
6
+ expr = 'when goodCond Task'
7
+ expected = \
8
+ [:when_clause,
9
+ [:bool_expr, [:var_ref, "goodCond"] ],
10
+ [:task_call_st, "Task"]]
11
+ ast(expr, :when_clause).should eq(expected)
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ module Gisele::Language::Syntax
3
+ describe WhileSt, "to_ast" do
4
+
5
+ it 'parses as expected' do
6
+ expr = "while goodCond Task1 end"
7
+ expected = \
8
+ [:while_st,
9
+ [:bool_expr, [:var_ref, "goodCond"]],
10
+ [:task_call_st, "Task1"]]
11
+ ast(expr, :while_st).should eq(expected)
12
+ end
13
+
14
+ it 'recognizes implicit sequences' do
15
+ expr = "while goodCond Task1 Task2 end"
16
+ expected = \
17
+ [:while_st,
18
+ [:bool_expr, [:var_ref, "goodCond"]],
19
+ [:seq_st, [:task_call_st, "Task1"], [:task_call_st, "Task2"]]]
20
+ ast(expr, :while_st).should eq(expected)
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ describe Gisele do
3
+ include Gisele
4
+
5
+ describe "parse" do
6
+
7
+ it 'works with a file' do
8
+ parsed = parse(fixtures_dir/:tasks/"simple.gis")
9
+ parsed.should be_a(Citrus::Match)
10
+ end
11
+
12
+ it 'works on a String' do
13
+ parsed = parse("task Hello end")
14
+ parsed.should be_a(Citrus::Match)
15
+ end
16
+
17
+ it 'accepts parse options' do
18
+ parsed = parse("if goodCond Task1 end", :root => :if_st)
19
+ parsed.should be_a(Citrus::Match)
20
+ end
21
+
22
+ end
23
+
24
+ describe "ast" do
25
+
26
+ it 'accepts parse options' do
27
+ ast = ast(parse("if goodCond Task1 end", :root => :if_st))
28
+ ast.should be_a(Sexpr)
29
+ ast.first.should eq(:if_st)
30
+ end
31
+
32
+ it 'sets traceability marks correctly' do
33
+ ast = ast(parse("if goodCond Task1 end", :root => :if_st))
34
+ ast.tracking_markers[:citrus_match].should_not be_nil
35
+ end
36
+
37
+ fixture_files('tasks/**/*.gis').each do |file|
38
+ it "works on #{file}" do
39
+ parsed = ast(parse(file))
40
+ parsed.should be_a(Array)
41
+ parsed.should be_a(Sexpr)
42
+ parsed.first.should eq(:unit_def)
43
+ if (astfile = file.sub_ext(".ast")).exist?
44
+ parsed.should eq(Kernel::eval(astfile.read, TOPLEVEL_BINDING, astfile.to_s))
45
+ end
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+ end
@@ -0,0 +1,44 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'gisele-language'
3
+
4
+ module SpecHelpers
5
+
6
+ def parse(text, rule, consume = true)
7
+ grammar = Gisele::Language::Grammar
8
+ grammar.parse(text, :root => rule, :consume => consume)
9
+ end
10
+
11
+ def ast(text, rule, consume = true)
12
+ ast = parse(text, rule, consume).to_ast
13
+ unless sexp_grammar[rule] === ast
14
+ raise "expected #{ast} to match #{rule} (#{text})"
15
+ end
16
+ ast
17
+ end
18
+
19
+ def fixtures_dir
20
+ (Path.dir/:fixtures)
21
+ end
22
+
23
+ def fixture_files(glob)
24
+ fixtures_dir.glob(glob)
25
+ end
26
+
27
+ def sexp_grammar
28
+ Gisele::Language
29
+ end
30
+
31
+ def simple_ast
32
+ Gisele::ast(fixtures_dir/:tasks/"simple.gis")
33
+ end
34
+
35
+ def complete_ast
36
+ Gisele::ast(fixtures_dir/:tasks/"complete.gis")
37
+ end
38
+
39
+ end
40
+
41
+ RSpec.configure do |c|
42
+ c.include SpecHelpers
43
+ c.extend SpecHelpers
44
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ describe Gisele::Language do
3
+
4
+ it "should have a version number" do
5
+ Gisele::Language.const_defined?(:VERSION).should be_true
6
+ end
7
+
8
+ end
data/tasks/gem.rake ADDED
@@ -0,0 +1,73 @@
1
+ # Installs rake tasks for gemming and packaging
2
+ #
3
+ # This file installs the 'rake package', 'rake gem' tasks and associates
4
+ # (clobber_package, repackage, ...). It is automatically generated by Noe
5
+ # from your .noespec file, and should therefore be configured there, under
6
+ # the variables/rake_tasks/gem entry, as illustrated below:
7
+ #
8
+ # variables:
9
+ # rake_tasks:
10
+ # gem:
11
+ # package_dir: pkg
12
+ # need_tar: false
13
+ # need_tar_gz: false
14
+ # need_tar_bz2: false
15
+ # need_zip: false
16
+ # ...
17
+ #
18
+ # If you have specific needs requiring manual intervention on this file,
19
+ # don't forget to set safe-override to false in your noe specification:
20
+ #
21
+ # template-info:
22
+ # manifest:
23
+ # tasks/gem.rake:
24
+ # safe-override: false
25
+ #
26
+ begin
27
+ require 'rubygems/package_task'
28
+
29
+ # Dynamically load the gem spec
30
+ gemspec_file = File.expand_path('../../gisele-language.gemspec', __FILE__)
31
+ gemspec = Kernel.eval(File.read(gemspec_file))
32
+
33
+ Gem::PackageTask.new(gemspec) do |t|
34
+
35
+ # Name of the package
36
+ t.name = gemspec.name
37
+
38
+ # Version of the package
39
+ t.version = gemspec.version
40
+
41
+ # Directory used to store the package files
42
+ t.package_dir = "pkg"
43
+
44
+ # True if a gzipped tar file (tgz) should be produced
45
+ t.need_tar = false
46
+
47
+ # True if a gzipped tar file (tar.gz) should be produced
48
+ t.need_tar_gz = false
49
+
50
+ # True if a bzip2'd tar file (tar.bz2) should be produced
51
+ t.need_tar_bz2 = false
52
+
53
+ # True if a zip file should be produced (default is false)
54
+ t.need_zip = false
55
+
56
+ # List of files to be included in the package.
57
+ t.package_files = gemspec.files
58
+
59
+ # Tar command for gzipped or bzip2ed archives.
60
+ t.tar_command = "tar"
61
+
62
+ # Zip command for zipped archives.
63
+ t.zip_command = "zip"
64
+
65
+ end
66
+ rescue LoadError
67
+ task :gem do
68
+ abort 'rubygems/package_task is not available. You should verify your rubygems installation'
69
+ end
70
+ task :package do
71
+ abort 'rubygems/package_task is not available. You should verify your rubygems installation'
72
+ end
73
+ end
@@ -0,0 +1,71 @@
1
+ # Installs a rake task for for running examples written using rspec.
2
+ #
3
+ # This file installs the 'rake spec_test' (aliased as 'rake spec') as well as
4
+ # extends 'rake test' to run spec tests, if any. It is automatically generated
5
+ # by Noe from your .noespec file, and should therefore be configured there,
6
+ # under the variables/rake_tasks/spec_test entry, as illustrated below:
7
+ #
8
+ # variables:
9
+ # rake_tasks:
10
+ # spec_test:
11
+ # pattern: spec/**/*_spec.rb
12
+ # verbose: true
13
+ # rspec_opts: [--color, --backtrace]
14
+ # ...
15
+ #
16
+ # If you have specific needs requiring manual intervention on this file,
17
+ # don't forget to set safe-override to false in your noe specification:
18
+ #
19
+ # template-info:
20
+ # manifest:
21
+ # tasks/spec_test.rake:
22
+ # safe-override: false
23
+ #
24
+ # This file has been written to conform to RSpec v2.4.0. More information about
25
+ # rspec and options of the rake task defined below can be found on
26
+ # http://relishapp.com/rspec
27
+ #
28
+ begin
29
+ require "rspec/core/rake_task"
30
+ desc "Run RSpec code examples"
31
+ RSpec::Core::RakeTask.new(:spec_test) do |t|
32
+ # Glob pattern to match files.
33
+ t.pattern = "spec/**/test_*.rb"
34
+
35
+ # Whether or not to fail Rake when an error occurs (typically when
36
+ # examples fail).
37
+ t.fail_on_error = true
38
+
39
+ # A message to print to stderr when there are failures.
40
+ t.failure_message = nil
41
+
42
+ # Use verbose output. If this is set to true, the task will print the
43
+ # executed spec command to stdout.
44
+ t.verbose = true
45
+
46
+ # Use rcov for code coverage?
47
+ t.rcov = false
48
+
49
+ # Path to rcov.
50
+ t.rcov_path = "rcov"
51
+
52
+ # Command line options to pass to rcov. See 'rcov --help' about this
53
+ t.rcov_opts = []
54
+
55
+ # Command line options to pass to ruby. See 'ruby --help' about this
56
+ t.ruby_opts = []
57
+
58
+ # Path to rspec
59
+ t.rspec_path = "rspec"
60
+
61
+ # Command line options to pass to rspec. See 'rspec --help' about this
62
+ t.rspec_opts = ["--color", "--backtrace"]
63
+ end
64
+ rescue LoadError => ex
65
+ task :spec_test do
66
+ abort 'rspec is not available. In order to run spec, you must: gem install rspec'
67
+ end
68
+ ensure
69
+ task :spec => [:spec_test]
70
+ task :test => [:spec_test]
71
+ end