sexpr 0.6.0 → 1.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 67f9fda1b0281f22e49fc267f432c1bed5ba6f270911b0470786662533d257d0
4
+ data.tar.gz: 97b7fc7fce491b594f4fb52a06daa5837407a5d5db59ab6bb6ae56e517e38492
5
+ SHA512:
6
+ metadata.gz: 808fbbb1bd28d417addfd740a85c441e022208ed87111a713bd4cd1920254b606181c3c8a2bbabd2c4fcaa707543b11d3baa1db6e661378fa7f7b350256599f7
7
+ data.tar.gz: 2c3795497e39ededc4cec8897fd178a34911fa3647a40561d8218da19bc9b72671de4b6d86bbd5854beb1d9ebc2907d86536d33531fe7c8b38074338c8824263
data/CHANGELOG.md CHANGED
@@ -1,4 +1,10 @@
1
- # 0.6.0 / 2013-09-26
1
+ # 1.0.0 / 2021-12-11
2
+
3
+ * Upgrade project structure to modern Enspirit practices
4
+
5
+ * Citrus dependency upgraded to 3.x and code fixed accordingly
6
+
7
+ # 0.6.0 / 2012-09-13
2
8
 
3
9
  * Major enhancements (possibly breaking changes)
4
10
 
data/Gemfile CHANGED
@@ -1,9 +1,2 @@
1
1
  source 'http://rubygems.org'
2
-
3
- group :development do
4
- gem "path", "~> 1.3"
5
- gem "citrus", "~> 2.4"
6
- gem "rake", "~> 10.0"
7
- gem "rspec", "~> 2.10"
8
- gem "wlang", "~> 0.10.2"
9
- end
2
+ gemspec
data/README.md CHANGED
@@ -1,8 +1,5 @@
1
1
  # Sexpr
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/blambeau/sexpr.png)](http://travis-ci.org/blambeau/sexpr)
4
- [![Dependency Status](https://gemnasium.com/blambeau/sexpr.png)](https://gemnasium.com/blambeau/sexpr)
5
-
6
3
  A ruby compilation framework around s-expressions.
7
4
 
8
5
  ## Links
@@ -87,4 +84,29 @@ https://github.com/blambeau/sexpr
87
84
 
88
85
  ### Where to read next?
89
86
 
90
- Have a look at the examples directory.
87
+ Have a look at the examples directory.
88
+
89
+ ## Public API
90
+
91
+ `sexpr` uses Semver and reached 1.0. The public API is as follows:
92
+
93
+ * The structure of YAML grammar files
94
+ * The `Sexpr` module and its public methods
95
+ * The behavior of the `Grammar` class through its public methods
96
+ * The behavior of the `Node` class (public methods)
97
+ * The behavior of the `Processor` and `Rewriter` classes (public & protected methods)
98
+ * The list of error classes and when they are raised
99
+
100
+ ## Contribute
101
+
102
+ Please use github issues and pull requests for all questions, bug reports,
103
+ and contributions. Don't hesitate to get in touch with us with an early code
104
+ spike if you plan to add non trivial features.
105
+
106
+ ## Licence
107
+
108
+ This software is distributed by Enspirit SRL under a MIT Licence. Please
109
+ contact Bernard Lambeau (blambeau@gmail.com) with any question.
110
+
111
+ Enspirit (https://enspirit.be) and Klaro App (https://klaro.cards) are both
112
+ actively using and contributing to the library.
data/lib/sexpr/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Sexpr
2
2
  module Version
3
3
 
4
- MAJOR = 0
5
- MINOR = 6
4
+ MAJOR = 1
5
+ MINOR = 0
6
6
  TINY = 0
7
7
 
8
8
  def self.to_s
data/lib/sexpr.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'yaml'
2
2
  require_relative "sexpr/version"
3
- require_relative "sexpr/loader"
4
3
  require_relative "sexpr/errors"
5
4
  require_relative "sexpr/node"
6
5
  require_relative "sexpr/grammar"
@@ -14,6 +13,8 @@ require_relative "sexpr/rewriter"
14
13
  module Sexpr
15
14
  extend Grammar::Tagging
16
15
 
16
+ YAML_OPTIONS = { :permitted_classes => %w[Regexp], :aliases => true }
17
+
17
18
  PathLike = lambda{|x|
18
19
  x.respond_to?(:to_path) or (x.is_a?(String) and File.exists?(x))
19
20
  }
@@ -30,11 +31,11 @@ module Sexpr
30
31
 
31
32
  def self.load_file(input, options = {})
32
33
  path = input.to_path rescue input.to_s
33
- load_hash YAML.load_file(path), options.merge(:path => input)
34
+ load_hash load_yaml(File.read(path)), options.merge(:path => input)
34
35
  end
35
36
 
36
37
  def self.load_string(input, options = {})
37
- load_hash YAML.load(input), options
38
+ load_hash load_yaml(input), options
38
39
  end
39
40
 
40
41
  def self.load_hash(input, options = {})
@@ -42,4 +43,11 @@ module Sexpr
42
43
  Grammar.new input, options
43
44
  end
44
45
 
46
+ def self.load_yaml(source)
47
+ if YAML.name == 'Psych' && Psych::VERSION >= '3.1'
48
+ YAML.safe_load(source, **YAML_OPTIONS)
49
+ else
50
+ YAML.load(source)
51
+ end
52
+ end
45
53
  end # module Sexpr
@@ -3,13 +3,13 @@ describe BoolExpr, 'the validation feature' do
3
3
  subject{ BoolExpr }
4
4
 
5
5
  it 'validates s-expressions' do
6
- subject.match?([:bool_lit, true]).should be_true
7
- subject.match?([:bool_lit, "x"]).should be_false
6
+ subject.match?([:bool_lit, true]).should be_truthy
7
+ subject.match?([:bool_lit, "x"]).should be_falsey
8
8
  end
9
9
 
10
10
  it 'validates s-expressions against specific rules' do
11
- subject[:bool_lit].match?([:bool_lit, true]).should be_true
12
- subject[:bool_and].match?([:bool_lit, true]).should be_false
11
+ subject[:bool_lit].match?([:bool_lit, true]).should be_truthy
12
+ subject[:bool_and].match?([:bool_lit, true]).should be_falsey
13
13
  end
14
14
 
15
15
  end
@@ -35,15 +35,15 @@ describe "the README examples" do
35
35
 
36
36
  # the grammar can be used to verify the structure of s-expressions
37
37
  f = (grammar === [:bool_and, [:bool_not, [:var_ref, "x"]], [:bool_lit, true]])
38
- f.should be_true
38
+ f.should be_truthy
39
39
 
40
40
  f = (grammar === [:bool_and, [:bool_lit, "true"]])
41
- f.should be_false
41
+ f.should be_falsey
42
42
 
43
43
  # the grammar can also be used to automatically have support on top of
44
44
  # such s-expressions
45
45
  expr = grammar.sexpr([:bool_lit, true])
46
- (Sexpr===expr).should be_true
46
+ (Sexpr===expr).should be_truthy
47
47
 
48
48
  (expr.sexpr_type).should eq(:bool_lit)
49
49
  # => :bool_lit
@@ -58,7 +58,7 @@ describe "the README examples" do
58
58
  copy.should eq([:bool_lit, [:bool_lit, false]])
59
59
  # => [:bool_lit, [:bool_lit, false]]
60
60
 
61
- (Sexpr===copy).should be_true
61
+ (Sexpr===copy).should be_truthy
62
62
 
63
63
  end
64
64
 
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'path'
2
2
  root = Path.backfind('.[lib]')
3
3
 
4
+ require 'rspec'
4
5
  require 'citrus'
5
6
 
6
7
  $LOAD_PATH.unshift (root/"lib").to_s
@@ -72,7 +72,7 @@ module Sexpr
72
72
  end
73
73
  it 'compiles its elements' do
74
74
  subject.terms.size.should eq(3)
75
- subject.terms.all?{|x| x.is_a?(Matcher::Terminal)}.should be_true
75
+ subject.terms.all?{|x| x.is_a?(Matcher::Terminal)}.should be_truthy
76
76
  end
77
77
  end
78
78
 
@@ -83,7 +83,7 @@ module Sexpr
83
83
  end
84
84
  it 'compiles its elements' do
85
85
  subject.terms.size.should eq(3)
86
- subject.terms.all?{|x| x.is_a?(Matcher::Terminal)}.should be_true
86
+ subject.terms.all?{|x| x.is_a?(Matcher::Terminal)}.should be_truthy
87
87
  end
88
88
  end
89
89
 
@@ -17,7 +17,7 @@ module Sexpr
17
17
  }
18
18
 
19
19
  let(:rules){
20
- YAML.load(yaml)
20
+ Sexpr.load_yaml(yaml)
21
21
  }
22
22
 
23
23
  subject{ compile_rules(rules) }
@@ -4,16 +4,16 @@ module Sexpr::Grammar
4
4
  include Tagging
5
5
 
6
6
  it 'recognizes s-expressions' do
7
- looks_a_sexpr?([:lit]).should be_true
7
+ looks_a_sexpr?([:lit]).should be_truthy
8
8
  end
9
9
 
10
10
  it 'does not recognize empty arrays' do
11
- looks_a_sexpr?([]).should be_false
11
+ looks_a_sexpr?([]).should be_falsey
12
12
  end
13
13
 
14
14
  it 'does not recognize others' do
15
- looks_a_sexpr?(nil).should be_false
16
- looks_a_sexpr?(:lit).should be_false
15
+ looks_a_sexpr?(nil).should be_falsey
16
+ looks_a_sexpr?(:lit).should be_falsey
17
17
  end
18
18
 
19
19
  end
@@ -10,7 +10,7 @@ module Sexpr::Matcher
10
10
  context 'when match' do
11
11
  let(:sexpr){ [:hello, "world"] }
12
12
 
13
- it{ should be_true }
13
+ it{ should be_truthy }
14
14
  end
15
15
 
16
16
  [
@@ -24,7 +24,7 @@ module Sexpr::Matcher
24
24
  context "when no match, e.g. #{example.inspect}" do
25
25
  let(:sexpr){ example }
26
26
 
27
- it{ should be_false }
27
+ it{ should be_falsey }
28
28
  end
29
29
  end
30
30
 
@@ -7,7 +7,7 @@ module Sexpr::Matcher
7
7
 
8
8
  it 'returns true on match' do
9
9
  rule.should be_match("hello")
10
- (rule === "hello").should be_true
10
+ (rule === "hello").should be_truthy
11
11
  end
12
12
 
13
13
  it 'returns false on no match' do
@@ -9,7 +9,7 @@ module Sexpr::Matcher
9
9
 
10
10
  it 'returns true on match' do
11
11
  rule.should be_match(true)
12
- (rule === true).should be_true
12
+ (rule === true).should be_truthy
13
13
  end
14
14
 
15
15
  it 'returns false on no match' do
@@ -25,7 +25,7 @@ module Sexpr::Matcher
25
25
 
26
26
  it 'returns true on match' do
27
27
  rule.should be_match(false)
28
- (rule === false).should be_true
28
+ (rule === false).should be_truthy
29
29
  end
30
30
 
31
31
  it 'returns false on no match' do
@@ -41,7 +41,7 @@ module Sexpr::Matcher
41
41
 
42
42
  it 'returns true on match' do
43
43
  rule.should be_match(nil)
44
- (rule === nil).should be_true
44
+ (rule === nil).should be_truthy
45
45
  end
46
46
 
47
47
  it 'returns false on no match' do
@@ -12,19 +12,19 @@ module Sexpr::Matcher
12
12
  let(:arg){ /^[a-z]+$/ }
13
13
 
14
14
  it 'matches a matching string' do
15
- terminal.terminal_match?("hello").should be_true
15
+ terminal.terminal_match?("hello").should be_truthy
16
16
  end
17
17
 
18
18
  it 'matches a non matching string' do
19
- terminal.terminal_match?("12").should be_false
19
+ terminal.terminal_match?("12").should be_falsey
20
20
  end
21
21
 
22
22
  it 'does not match a sexp' do
23
- terminal.terminal_match?([:sexp, "Hello World"]).should be_false
23
+ terminal.terminal_match?([:sexp, "Hello World"]).should be_falsey
24
24
  end
25
25
 
26
26
  it 'does not match nil' do
27
- terminal.terminal_match?(nil).should be_false
27
+ terminal.terminal_match?(nil).should be_falsey
28
28
  end
29
29
  end
30
30
 
@@ -32,18 +32,18 @@ module Sexpr::Matcher
32
32
  let(:arg){ true }
33
33
 
34
34
  it 'matches true' do
35
- terminal.terminal_match?(true).should be_true
35
+ terminal.terminal_match?(true).should be_truthy
36
36
  end
37
37
 
38
38
  it 'does not match false/nil' do
39
- terminal.terminal_match?(false).should be_false
40
- terminal.terminal_match?(nil).should be_false
39
+ terminal.terminal_match?(false).should be_falsey
40
+ terminal.terminal_match?(nil).should be_falsey
41
41
  end
42
42
 
43
43
  it 'does not match anything else' do
44
- terminal.terminal_match?([]).should be_false
45
- terminal.terminal_match?([:sexp]).should be_false
46
- terminal.terminal_match?("true").should be_false
44
+ terminal.terminal_match?([]).should be_falsey
45
+ terminal.terminal_match?([:sexp]).should be_falsey
46
+ terminal.terminal_match?("true").should be_falsey
47
47
  end
48
48
  end
49
49
 
@@ -51,18 +51,18 @@ module Sexpr::Matcher
51
51
  let(:arg){ false }
52
52
 
53
53
  it 'matches false' do
54
- terminal.terminal_match?(false).should be_true
54
+ terminal.terminal_match?(false).should be_truthy
55
55
  end
56
56
 
57
57
  it 'does not match true/nil' do
58
- terminal.terminal_match?(true).should be_false
59
- terminal.terminal_match?(nil).should be_false
58
+ terminal.terminal_match?(true).should be_falsey
59
+ terminal.terminal_match?(nil).should be_falsey
60
60
  end
61
61
 
62
62
  it 'does not match anything else' do
63
- terminal.terminal_match?([]).should be_false
64
- terminal.terminal_match?([:sexp]).should be_false
65
- terminal.terminal_match?("false").should be_false
63
+ terminal.terminal_match?([]).should be_falsey
64
+ terminal.terminal_match?([:sexp]).should be_falsey
65
+ terminal.terminal_match?("false").should be_falsey
66
66
  end
67
67
  end
68
68
 
@@ -70,18 +70,18 @@ module Sexpr::Matcher
70
70
  let(:arg){ nil }
71
71
 
72
72
  it 'matches nil' do
73
- terminal.terminal_match?(nil).should be_true
73
+ terminal.terminal_match?(nil).should be_truthy
74
74
  end
75
75
 
76
76
  it 'does not match true/false' do
77
- terminal.terminal_match?(true).should be_false
78
- terminal.terminal_match?(false).should be_false
77
+ terminal.terminal_match?(true).should be_falsey
78
+ terminal.terminal_match?(false).should be_falsey
79
79
  end
80
80
 
81
81
  it 'does not match anything else' do
82
- terminal.terminal_match?([]).should be_false
83
- terminal.terminal_match?([:sexp]).should be_false
84
- terminal.terminal_match?("nil").should be_false
82
+ terminal.terminal_match?([]).should be_falsey
83
+ terminal.terminal_match?([:sexp]).should be_falsey
84
+ terminal.terminal_match?("nil").should be_falsey
85
85
  end
86
86
  end
87
87
 
@@ -89,18 +89,18 @@ module Sexpr::Matcher
89
89
  let(:arg){ Symbol }
90
90
 
91
91
  it 'matches a symbol' do
92
- terminal.terminal_match?(:hello).should be_true
92
+ terminal.terminal_match?(:hello).should be_truthy
93
93
  end
94
94
 
95
95
  it 'does not match a string' do
96
- terminal.terminal_match?("hello").should be_false
96
+ terminal.terminal_match?("hello").should be_falsey
97
97
  end
98
98
 
99
99
  it 'does not match anything else' do
100
- terminal.terminal_match?(nil).should be_false
101
- terminal.terminal_match?([]).should be_false
102
- terminal.terminal_match?([:sexp]).should be_false
103
- terminal.terminal_match?("nil").should be_false
100
+ terminal.terminal_match?(nil).should be_falsey
101
+ terminal.terminal_match?([]).should be_falsey
102
+ terminal.terminal_match?([:sexp]).should be_falsey
103
+ terminal.terminal_match?("nil").should be_falsey
104
104
  end
105
105
  end
106
106
 
@@ -11,7 +11,7 @@ module Sexpr::Parser
11
11
  end
12
12
 
13
13
  it 'returns false when not recognized' do
14
- (Citrus.recognizes?(self)).should be_false
14
+ (Citrus.recognizes?(self)).should be_falsey
15
15
  end
16
16
 
17
17
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  describe Sexpr do
3
3
 
4
4
  it "should have a version number" do
5
- Sexpr.const_defined?(:VERSION).should be_true
5
+ Sexpr.const_defined?(:VERSION).should be_truthy
6
6
  end
7
7
 
8
8
  end
data/tasks/test.rake CHANGED
@@ -1,26 +1,11 @@
1
- require "rspec/core/rake_task"
2
1
  namespace :test do
2
+ require 'rspec/core/rake_task'
3
3
 
4
- desc "Run unit tests"
4
+ desc %q{Run all RSpec tests}
5
5
  RSpec::Core::RakeTask.new(:unit) do |t|
6
- t.pattern = "spec/unit/**/test_*.rb"
7
- t.fail_on_error = true
8
- t.failure_message = nil
9
- t.verbose = true
10
- t.rspec_path = "rspec"
11
- t.rspec_opts = ["--color", "--backtrace"]
6
+ t.rspec_opts = %w[-I. -Ilib -Ispec --pattern=spec/**/test_*.rb --color .]
12
7
  end
13
8
 
14
- desc "Run unit tests"
15
- RSpec::Core::RakeTask.new(:integration) do |t|
16
- t.pattern = "spec/integration/**/test_*.rb"
17
- t.fail_on_error = true
18
- t.failure_message = nil
19
- t.verbose = true
20
- t.rspec_path = "rspec"
21
- t.rspec_opts = ["--color", "--backtrace"]
22
- end
23
-
24
- task :all => [ :unit, :integration ]
9
+ task :all => :"unit"
25
10
  end
26
- task :test => [ :"test:all" ]
11
+ task :test => :"test:all"