re_duxml 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ast_ext/node.rb +52 -52
- data/lib/re_duxml/array.rb +36 -37
- data/lib/re_duxml/element/parameterization.rb +18 -18
- data/lib/re_duxml/element.rb +8 -8
- data/lib/re_duxml/evaluate/parser.rb +3 -2
- data/lib/re_duxml/evaluate.rb +78 -77
- data/lib/re_duxml.rb +104 -99
- data/lib/ruby_ext/boolean.rb +37 -37
- data/lib/ruby_ext/fixnum.rb +5 -5
- data/lib/ruby_ext/macro.rb +50 -50
- data/lib/ruby_ext/regexp.rb +6 -6
- data/lib/ruby_ext/string.rb +14 -14
- data/lib/symbolic_ext/coerced.rb +15 -15
- data/lib/symbolic_ext/symbolic.rb +26 -26
- data/lib/symbolic_ext/variable.rb +60 -60
- data/xml/logic.xml +152 -152
- metadata +20 -6
data/lib/ruby_ext/boolean.rb
CHANGED
@@ -1,38 +1,38 @@
|
|
1
|
-
# Copyright (c) 2016 Freescale Semiconductor Inc.
|
2
|
-
require_relative '../../lib/ast_ext/node'
|
3
|
-
|
4
|
-
class TrueClass
|
5
|
-
def ternary(a, b)
|
6
|
-
a
|
7
|
-
end
|
8
|
-
|
9
|
-
def and(obj)
|
10
|
-
obj
|
11
|
-
end
|
12
|
-
|
13
|
-
def or(obj)
|
14
|
-
true
|
15
|
-
end
|
16
|
-
|
17
|
-
def not
|
18
|
-
false
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class FalseClass
|
23
|
-
def ternary(a, b)
|
24
|
-
b
|
25
|
-
end
|
26
|
-
|
27
|
-
def and(obj)
|
28
|
-
false
|
29
|
-
end
|
30
|
-
|
31
|
-
def or(obj)
|
32
|
-
obj
|
33
|
-
end
|
34
|
-
|
35
|
-
def not
|
36
|
-
true
|
37
|
-
end
|
1
|
+
# Copyright (c) 2016 Freescale Semiconductor Inc.
|
2
|
+
require_relative '../../lib/ast_ext/node'
|
3
|
+
|
4
|
+
class TrueClass
|
5
|
+
def ternary(a, b)
|
6
|
+
a
|
7
|
+
end
|
8
|
+
|
9
|
+
def and(obj)
|
10
|
+
obj
|
11
|
+
end
|
12
|
+
|
13
|
+
def or(obj)
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
def not
|
18
|
+
false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class FalseClass
|
23
|
+
def ternary(a, b)
|
24
|
+
b
|
25
|
+
end
|
26
|
+
|
27
|
+
def and(obj)
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
31
|
+
def or(obj)
|
32
|
+
obj
|
33
|
+
end
|
34
|
+
|
35
|
+
def not
|
36
|
+
true
|
37
|
+
end
|
38
38
|
end
|
data/lib/ruby_ext/fixnum.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# Copyright (c) 2016 Freescale Semiconductor Inc.
|
2
|
-
require_relative '../ast_ext/node'
|
3
|
-
|
4
|
-
class Fixnum
|
5
|
-
include AST
|
1
|
+
# Copyright (c) 2016 Freescale Semiconductor Inc.
|
2
|
+
require_relative '../ast_ext/node'
|
3
|
+
|
4
|
+
class Fixnum
|
5
|
+
include AST
|
6
6
|
end
|
data/lib/ruby_ext/macro.rb
CHANGED
@@ -1,51 +1,51 @@
|
|
1
|
-
# Copyright (c) 2016 Freescale Semiconductor Inc.
|
2
|
-
require_relative 'string'
|
3
|
-
|
4
|
-
# string wrapped in parameter expression macro symbol and delimiters,
|
5
|
-
# indicating content is to be parsed and resolved when building and validating XML design
|
6
|
-
class Macro
|
7
|
-
include Enumerable
|
8
|
-
include Comparable
|
9
|
-
|
10
|
-
# is '@' by default
|
11
|
-
MACRO_SYMBOL = '@'
|
12
|
-
# are parentheses by default e.g. '()'
|
13
|
-
DELIMITERS = %w{( )}
|
14
|
-
|
15
|
-
@macro_string
|
16
|
-
|
17
|
-
# string including MACRO_SYMBOL and DELIMITERS
|
18
|
-
attr_accessor :macro_string
|
19
|
-
|
20
|
-
# checks a string to see if it's a valid macro expression without leading or trailing non-expression or delimiter text
|
21
|
-
def self.is_macro?(str)
|
22
|
-
str[0,2] == MACRO_SYMBOL+DELIMITERS.first && str[-1] == DELIMITERS.last && str.balanced_parens?
|
23
|
-
end
|
24
|
-
|
25
|
-
# takes given string and wraps in MACRO_SYMBOL and DELIMITERS if not already wrapped
|
26
|
-
# e.g. str => 'asdf'
|
27
|
-
# Macro.new str => '@(asdf)'
|
28
|
-
def initialize(str)
|
29
|
-
@macro_string = Macro.is_macro?(str) ? str : "#{MACRO_SYMBOL}#{DELIMITERS.first}#{str}#{DELIMITERS.last}"
|
30
|
-
end
|
31
|
-
|
32
|
-
# compares #demacro'd @macro_string to obj
|
33
|
-
def <=>(obj)
|
34
|
-
demacro <=> obj
|
35
|
-
end
|
36
|
-
|
37
|
-
# just yields each character of #demacro'd @macro_string
|
38
|
-
def each(&block)
|
39
|
-
demacro.split(//).each do |char| yield char end
|
40
|
-
end
|
41
|
-
|
42
|
-
# returns string without MACRO_SYMBOL and DELIMITERS
|
43
|
-
def demacro
|
44
|
-
macro_string[2..-2]
|
45
|
-
end
|
46
|
-
|
47
|
-
# returns nil if not, and match data for any parameter names found
|
48
|
-
def parameterized?
|
49
|
-
macro_string.match Regexp.identifier
|
50
|
-
end
|
1
|
+
# Copyright (c) 2016 Freescale Semiconductor Inc.
|
2
|
+
require_relative 'string'
|
3
|
+
|
4
|
+
# string wrapped in parameter expression macro symbol and delimiters,
|
5
|
+
# indicating content is to be parsed and resolved when building and validating XML design
|
6
|
+
class Macro
|
7
|
+
include Enumerable
|
8
|
+
include Comparable
|
9
|
+
|
10
|
+
# is '@' by default
|
11
|
+
MACRO_SYMBOL = '@'
|
12
|
+
# are parentheses by default e.g. '()'
|
13
|
+
DELIMITERS = %w{( )}
|
14
|
+
|
15
|
+
@macro_string
|
16
|
+
|
17
|
+
# string including MACRO_SYMBOL and DELIMITERS
|
18
|
+
attr_accessor :macro_string
|
19
|
+
|
20
|
+
# checks a string to see if it's a valid macro expression without leading or trailing non-expression or delimiter text
|
21
|
+
def self.is_macro?(str)
|
22
|
+
str[0,2] == MACRO_SYMBOL+DELIMITERS.first && str[-1] == DELIMITERS.last && str.balanced_parens?
|
23
|
+
end
|
24
|
+
|
25
|
+
# takes given string and wraps in MACRO_SYMBOL and DELIMITERS if not already wrapped
|
26
|
+
# e.g. str => 'asdf'
|
27
|
+
# Macro.new str => '@(asdf)'
|
28
|
+
def initialize(str)
|
29
|
+
@macro_string = Macro.is_macro?(str) ? str : "#{MACRO_SYMBOL}#{DELIMITERS.first}#{str}#{DELIMITERS.last}"
|
30
|
+
end
|
31
|
+
|
32
|
+
# compares #demacro'd @macro_string to obj
|
33
|
+
def <=>(obj)
|
34
|
+
demacro <=> obj
|
35
|
+
end
|
36
|
+
|
37
|
+
# just yields each character of #demacro'd @macro_string
|
38
|
+
def each(&block)
|
39
|
+
demacro.split(//).each do |char| yield char end
|
40
|
+
end
|
41
|
+
|
42
|
+
# returns string without MACRO_SYMBOL and DELIMITERS
|
43
|
+
def demacro
|
44
|
+
macro_string[2..-2]
|
45
|
+
end
|
46
|
+
|
47
|
+
# returns nil if not, and match data for any parameter names found
|
48
|
+
def parameterized?
|
49
|
+
macro_string.match Regexp.identifier
|
50
|
+
end
|
51
51
|
end # class Macro
|
data/lib/ruby_ext/regexp.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# Copyright (c) 2016 Freescale Semiconductor Inc.
|
2
|
-
class Regexp
|
3
|
-
# @return [Regexp] single and double quoted strings
|
4
|
-
def self.string
|
5
|
-
/['"][^'"]*['"]/
|
6
|
-
end
|
1
|
+
# Copyright (c) 2016 Freescale Semiconductor Inc.
|
2
|
+
class Regexp
|
3
|
+
# @return [Regexp] single and double quoted strings
|
4
|
+
def self.string
|
5
|
+
/['"][^'"]*['"]/
|
6
|
+
end
|
7
7
|
end
|
data/lib/ruby_ext/string.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
# Copyright (c) 2016 Freescale Semiconductor Inc.
|
2
|
-
require 'duxml'
|
3
|
-
|
4
|
-
# extending String with #parameterized? and #balanced_parens? only to assist macro.rb
|
5
|
-
class String
|
6
|
-
# returns whether or not contents include any Macro strings i.e. Parameter expressions
|
7
|
-
def parameterized?
|
8
|
-
self.include?('@(')
|
9
|
-
end
|
10
|
-
|
11
|
-
# returns whether number of open parentheses and close parentheses match
|
12
|
-
def balanced_parens?
|
13
|
-
self.match(/\(/).size == self.match(/\)/).size
|
14
|
-
end
|
1
|
+
# Copyright (c) 2016 Freescale Semiconductor Inc.
|
2
|
+
require 'duxml'
|
3
|
+
|
4
|
+
# extending String with #parameterized? and #balanced_parens? only to assist macro.rb
|
5
|
+
class String
|
6
|
+
# returns whether or not contents include any Macro strings i.e. Parameter expressions
|
7
|
+
def parameterized?
|
8
|
+
self.include?('@(')
|
9
|
+
end
|
10
|
+
|
11
|
+
# returns whether number of open parentheses and close parentheses match
|
12
|
+
def balanced_parens?
|
13
|
+
self.match(/\(/).size == self.match(/\)/).size
|
14
|
+
end
|
15
15
|
end # class String
|
data/lib/symbolic_ext/coerced.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
# Copyright (c) 2016 Freescale Semiconductor Inc.
|
2
|
-
require_relative 'variable'
|
3
|
-
|
4
|
-
module Symbolic
|
5
|
-
class Coerced
|
6
|
-
include AST
|
7
|
-
|
8
|
-
def %(numeric)
|
9
|
-
numeric.new_ast(:%, @symbolic)
|
10
|
-
end
|
11
|
-
|
12
|
-
def **(numeric)
|
13
|
-
numeric.new_ast(:**, @symbolic)
|
14
|
-
end
|
15
|
-
end
|
1
|
+
# Copyright (c) 2016 Freescale Semiconductor Inc.
|
2
|
+
require_relative 'variable'
|
3
|
+
|
4
|
+
module Symbolic
|
5
|
+
class Coerced
|
6
|
+
include AST
|
7
|
+
|
8
|
+
def %(numeric)
|
9
|
+
numeric.new_ast(:%, @symbolic)
|
10
|
+
end
|
11
|
+
|
12
|
+
def **(numeric)
|
13
|
+
numeric.new_ast(:**, @symbolic)
|
14
|
+
end
|
15
|
+
end
|
16
16
|
end
|
@@ -1,26 +1,26 @@
|
|
1
|
-
# Copyright (c) 2016 Freescale Semiconductor Inc.
|
2
|
-
require_relative 'coerced'
|
3
|
-
|
4
|
-
module Symbolic
|
5
|
-
include AST
|
6
|
-
|
7
|
-
def %(var)
|
8
|
-
return 0 if self.object_id == var.object_id
|
9
|
-
return self % var if self.is_a?(Numeric) && var.is_a?(Numeric)
|
10
|
-
new_ast :%, var
|
11
|
-
end
|
12
|
-
|
13
|
-
def -@(var)
|
14
|
-
return -var unless var.is_a?(Node)
|
15
|
-
return -var.type if var.type.is_a?(Numeric)
|
16
|
-
reversed = var.type.reverse
|
17
|
-
reversed ? new_ast(reversed, *var.children.dup) : new_ast(:-@, [var])
|
18
|
-
end
|
19
|
-
|
20
|
-
def not(var)
|
21
|
-
return nil if var.is_a?(Symbolic::Variable)
|
22
|
-
return !var unless var.is_a?(Node)
|
23
|
-
inverted = var.type.inverse
|
24
|
-
inverted ? new_ast(inverted, *var.children.dup) : new_ast(:!, [var])
|
25
|
-
end
|
26
|
-
end
|
1
|
+
# Copyright (c) 2016 Freescale Semiconductor Inc.
|
2
|
+
require_relative 'coerced'
|
3
|
+
|
4
|
+
module Symbolic
|
5
|
+
include AST
|
6
|
+
|
7
|
+
def %(var)
|
8
|
+
return 0 if self.object_id == var.object_id
|
9
|
+
return self % var if self.is_a?(Numeric) && var.is_a?(Numeric)
|
10
|
+
new_ast :%, var
|
11
|
+
end
|
12
|
+
|
13
|
+
def -@(var)
|
14
|
+
return -var unless var.is_a?(Node)
|
15
|
+
return -var.type if var.type.is_a?(Numeric)
|
16
|
+
reversed = var.type.reverse
|
17
|
+
reversed ? new_ast(reversed, *var.children.dup) : new_ast(:-@, [var])
|
18
|
+
end
|
19
|
+
|
20
|
+
def not(var)
|
21
|
+
return nil if var.is_a?(Symbolic::Variable)
|
22
|
+
return !var unless var.is_a?(Node)
|
23
|
+
inverted = var.type.inverse
|
24
|
+
inverted ? new_ast(inverted, *var.children.dup) : new_ast(:!, [var])
|
25
|
+
end
|
26
|
+
end
|
@@ -1,61 +1,61 @@
|
|
1
|
-
# Copyright (c) 2016 Freescale Semiconductor Inc.
|
2
|
-
require 'symbolic'
|
3
|
-
require_relative '../ruby_ext/fixnum'
|
4
|
-
require_relative '../ruby_ext/boolean'
|
5
|
-
|
6
|
-
module Symbolic
|
7
|
-
class Variable
|
8
|
-
include AST
|
9
|
-
|
10
|
-
def and(obj)
|
11
|
-
return self if obj.equal?(true) || obj.equal?(self)
|
12
|
-
return false if obj.equal?(false)
|
13
|
-
nil
|
14
|
-
end
|
15
|
-
|
16
|
-
def or(obj)
|
17
|
-
return self if obj.equal?(false) || obj.equal?(self)
|
18
|
-
return true if obj.equal?(true)
|
19
|
-
nil
|
20
|
-
end
|
21
|
-
|
22
|
-
def <(obj)
|
23
|
-
eql?(obj) ? false : nil
|
24
|
-
end
|
25
|
-
|
26
|
-
def >(obj)
|
27
|
-
eql?(obj) ? false : nil
|
28
|
-
end
|
29
|
-
|
30
|
-
def !=(obj)
|
31
|
-
if obj.is_a?(Variable) || obj.is_a?(Numeric)
|
32
|
-
return object_id == obj.object_id ? false : nil
|
33
|
-
end
|
34
|
-
|
35
|
-
return !self if obj.equal?(true)
|
36
|
-
return self if obj.equal?(false)
|
37
|
-
return false if obj.equal?(self)
|
38
|
-
nil
|
39
|
-
end
|
40
|
-
|
41
|
-
def ==(obj)
|
42
|
-
if obj.is_a?(Variable) || obj.is_a?(Numeric)
|
43
|
-
result = object_id == obj.object_id ? true : nil
|
44
|
-
return result
|
45
|
-
end
|
46
|
-
|
47
|
-
return !self if obj.equal?(false)
|
48
|
-
return self if obj.equal?(true)
|
49
|
-
return true if obj.equal?(self)
|
50
|
-
nil
|
51
|
-
end
|
52
|
-
|
53
|
-
def >=(obj)
|
54
|
-
object_id == obj.object_id ? true : nil
|
55
|
-
end
|
56
|
-
|
57
|
-
def <=(obj)
|
58
|
-
object_id == obj.object_id ? true : nil
|
59
|
-
end
|
60
|
-
end # class Variable
|
1
|
+
# Copyright (c) 2016 Freescale Semiconductor Inc.
|
2
|
+
require 'symbolic'
|
3
|
+
require_relative '../ruby_ext/fixnum'
|
4
|
+
require_relative '../ruby_ext/boolean'
|
5
|
+
|
6
|
+
module Symbolic
|
7
|
+
class Variable
|
8
|
+
include AST
|
9
|
+
|
10
|
+
def and(obj)
|
11
|
+
return self if obj.equal?(true) || obj.equal?(self)
|
12
|
+
return false if obj.equal?(false)
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def or(obj)
|
17
|
+
return self if obj.equal?(false) || obj.equal?(self)
|
18
|
+
return true if obj.equal?(true)
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def <(obj)
|
23
|
+
eql?(obj) ? false : nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def >(obj)
|
27
|
+
eql?(obj) ? false : nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def !=(obj)
|
31
|
+
if obj.is_a?(Variable) || obj.is_a?(Numeric)
|
32
|
+
return object_id == obj.object_id ? false : nil
|
33
|
+
end
|
34
|
+
|
35
|
+
return !self if obj.equal?(true)
|
36
|
+
return self if obj.equal?(false)
|
37
|
+
return false if obj.equal?(self)
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
|
41
|
+
def ==(obj)
|
42
|
+
if obj.is_a?(Variable) || obj.is_a?(Numeric)
|
43
|
+
result = object_id == obj.object_id ? true : nil
|
44
|
+
return result
|
45
|
+
end
|
46
|
+
|
47
|
+
return !self if obj.equal?(false)
|
48
|
+
return self if obj.equal?(true)
|
49
|
+
return true if obj.equal?(self)
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
|
53
|
+
def >=(obj)
|
54
|
+
object_id == obj.object_id ? true : nil
|
55
|
+
end
|
56
|
+
|
57
|
+
def <=(obj)
|
58
|
+
object_id == obj.object_id ? true : nil
|
59
|
+
end
|
60
|
+
end # class Variable
|
61
61
|
end # module Symbolic
|