sexpr 0.6.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7443a85e9707b7dda46f8ad3114a60b0dde2e1d79d109e0f9c035032c7ff7076
4
+ data.tar.gz: 44aa06026a8e7109aa341a8dfa33520ababa941b3c1b2a59c6f459f98c69361a
5
+ SHA512:
6
+ metadata.gz: 863dd88e82ba1d50cc4c83c18f0aceed3415b7dc3ef5a448e95878ac78bba3561a806e3ad2d4a6e2f8ed4561a810851b1d24831ab782dc97418b05ecc5d9d688
7
+ data.tar.gz: 678512db91ae099f49129aed7672ea3e5d236b1f34539c467497bdf4959bd264fec74631963e01e1aad92b6baee78d66eedb7c3d6b09b84623469cca58d23d67
data/CHANGELOG.md CHANGED
@@ -1,4 +1,19 @@
1
- # 0.6.0 / 2013-09-26
1
+ ## 1.1.0 / 2023-06-09
2
+
3
+ * Removed (tested) support for ruby < 2.7. No breaking change though,
4
+ but those versions are no longer supported
5
+
6
+ * Bumped path dependency to 2.1.x
7
+
8
+ * Fix File.exists? usages not working under ruby 3.2
9
+
10
+ ## 1.0.0 / 2021-12-11
11
+
12
+ * Upgrade project structure to modern Enspirit practices
13
+
14
+ * Citrus dependency upgraded to 3.x and code fixed accordingly
15
+
16
+ ## 0.6.0 / 2012-09-13
2
17
 
3
18
  * Major enhancements (possibly breaking changes)
4
19
 
@@ -14,7 +29,7 @@
14
29
  module used to tag a given grammar rule production.
15
30
  * `Grammar#looks_a_sexpr?(arg)` became public.
16
31
 
17
- # 0.5.1 / 2012-03-13
32
+ ## 0.5.1 / 2012-03-13
18
33
 
19
34
  * Minor enhancements
20
35
 
@@ -27,7 +42,7 @@
27
42
  * Use `reference.const_get(name, *false*)` when looking for tagging modules to avoid
28
43
  finding ruby classes such as Array when tagging sexpr such as [:array, ...].
29
44
 
30
- # 0.5.0 / 2012-02-25
45
+ ## 0.5.0 / 2012-02-25
31
46
 
32
47
  * Major enhancements
33
48
 
@@ -66,7 +81,7 @@
66
81
  * The `Processor#main_processor` feature (undocumented and unused in examples) has been
67
82
  removed. Using preprocessors is much cleaner that linking processors to each other.
68
83
 
69
- # 0.4.0 / 2012-02-23
84
+ ## 0.4.0 / 2012-02-23
70
85
 
71
86
  * Major enhancements
72
87
 
@@ -95,7 +110,7 @@
95
110
  tracking markers (see enhancements). To palliate to this, default parsing options can
96
111
  now be specified through `Grammar#default_parse_options` (see enhancements).
97
112
 
98
- # 0.3.0 / 2012-02-21
113
+ ## 0.3.0 / 2012-02-21
99
114
 
100
115
  * Breaking changes
101
116
 
@@ -118,7 +133,7 @@
118
133
  to module names. That convention may however be overridden with specific grammar
119
134
  methods (see the BoolExpr example).
120
135
 
121
- # 0.2.0 / 2012-02-21
136
+ ## 0.2.0 / 2012-02-21
122
137
 
123
138
  * Enhancements
124
139
 
@@ -126,8 +141,8 @@
126
141
  * The root rule to use can now be specified in the options hash taken as second argument
127
142
  of `SexpGrammar.grammar(..., :root => :some_rule_name)`
128
143
 
129
- # 0.1.0 / 2012-02-20
144
+ ## 0.1.0 / 2012-02-20
130
145
 
131
146
  * Enhancements
132
147
 
133
- * Birthday!
148
+ * Birthday!
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.
@@ -38,7 +38,7 @@ module Sexpr
38
38
 
39
39
  def install_parser
40
40
  @parser = option(:parser)
41
- if @parser.is_a?(String) && !File.exists?(@parser)
41
+ if @parser.is_a?(String) && !File.exist?(@parser)
42
42
  unless path
43
43
  raise Errno::ENOENT, "#{@parser} (no main path)"
44
44
  end
@@ -53,4 +53,4 @@ module Sexpr
53
53
 
54
54
  end # module Options
55
55
  end # module Grammar
56
- end # module Sexpr
56
+ end # module Sexpr
@@ -12,7 +12,7 @@ module Sexpr
12
12
 
13
13
  def looks_a_citrus_file?(arg)
14
14
  arg = arg.to_path if arg.respond_to?(:to_path)
15
- arg.is_a?(String) && File.exists?(arg) && (File.extname(arg) == ".citrus")
15
+ arg.is_a?(String) && File.exist?(arg) && (File.extname(arg) == ".citrus")
16
16
  end
17
17
 
18
18
  def looks_a_citrus_grammar?(arg)
@@ -53,4 +53,4 @@ module Sexpr
53
53
  Sexpr::Parser.register self
54
54
  end # class Citrus
55
55
  end # module Parser
56
- end # module Sexpr
56
+ end # module Sexpr
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 = 1
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,8 +13,10 @@ 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
- x.respond_to?(:to_path) or (x.is_a?(String) and File.exists?(x))
19
+ x.respond_to?(:to_path) or (x.is_a?(String) and File.exist?(x))
19
20
  }
20
21
 
21
22
  def self.load(input, options = {})
@@ -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
 
45
- end # module Sexpr
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
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
@@ -8,7 +8,7 @@ module Sexpr
8
8
  end
9
9
 
10
10
  it 'accepts a path' do
11
- input_text(Path.here).should eq(File.read(__FILE__))
11
+ input_text(Path.file).should eq(File.read(__FILE__))
12
12
  end
13
13
 
14
14
  it 'accepts an IO' do
@@ -24,4 +24,4 @@ module Sexpr
24
24
  end
25
25
 
26
26
  end
27
- end
27
+ 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"