rley 0.0.03 → 0.0.04

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjJiNzZiMzIzYzk1MDE0NWJmNjE5ZDZiYjRiZDA1YjU4MjM1ZjgyYQ==
4
+ ODc2MTFmNTM3MjNjNTEyMzYzOWNmNmQ1OGM0NDUwNGFiNjViYzEyMw==
5
5
  data.tar.gz: !binary |-
6
- MzUxMjZjNWNmZTIxMThhYzY3Y2UyYzIzMTM1Yjg4MThlZTYzN2E4YQ==
6
+ YjA5ZWUzYzczYzJhODQxMmM3MDJhNzYzMTA0NWRjNmNkNWYyOTFiNA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NGMxMWU5YmE4NGZjMzJmZmI1YzU1MmE1MWVhNTRhMjU3ODdmYTQxYzYyZDk4
10
- Y2EyYzFjZmExMjc5MjU5YzFjNzQ5ZmJiMjU5ZDY1NTM4ZDRkYTVlZWQ1YWM3
11
- MmI5YWQ3YzUzMGM0NTY2YWEyZTE0Y2JkNmVkZDc0NWU2N2Q0ZTg=
9
+ YTBmMGU1NWIxYjhlODQ2YmNkZWQyYmIwZGZiNDQzNGExNGI0ZjgwNjZmYjNi
10
+ NmZmZDNkOWZkNjE5NmI4ZjE0ZjJkZmIwNzUxOWIxNzUxZDI0ZWRlZWJjZWI1
11
+ NjM0NGM3NGM0NmI5N2QzNjBhNjExNjRmMWM4MDJkZmFiMDE5ZTQ=
12
12
  data.tar.gz: !binary |-
13
- NjRlNGViNGRmNjVlMzQ1ZDVkNjc4NjYwNmU5MTU0YzJiYTIxYjViMmM2YTc2
14
- ZDYwODNlY2Q2ZTY1ZDQwMzNiOTQ2NTYwNTlhYjE4NDk4NDFiYmI5NjY1YjUx
15
- NzU3Nzk4ODA2NzdkY2QwMjk0ZmIxYmVhNzc1NDc0Y2YyNTdiZmY=
13
+ MWQyYjUzMzVmZjRlNDE4ZGZmODMwNmNkNWQ4ODZhM2U5NGFhM2ZmNzM4MjQ3
14
+ MDI3M2JlMWFiNDNiN2VlNTYxYTE3YWZlZTFiYzFkYTViMmFhMjlmMzk2OGY1
15
+ MDY3NjI4M2Y0NDE3MTQ2ODI2OTU3MjJhYTg4YjJmYjU2NmZlMzk=
@@ -1,3 +1,6 @@
1
+ ### 0.0.04 / 2014-11-12
2
+ * [CHANGE] Class `DottedItem` moved to `Rley` module.
3
+
1
4
  ### 0.0.03 / 2014-11-12
2
5
  * [CHANGE] File `README.md`: Added gem version badge.
3
6
 
@@ -3,7 +3,7 @@
3
3
 
4
4
  module Rley # Module used as a namespace
5
5
  # The version number of the gem.
6
- Version = '0.0.03'
6
+ Version = '0.0.04'
7
7
 
8
8
  # Brief description of the gem.
9
9
  Description = "Ruby implementation of the Earley's parsing algorithm"
@@ -1,80 +1,85 @@
1
- # A dotted item is a parse state for a given production/grammar rule
2
- # It partitions the rhs of the rule in two parts.
3
- # The left part consists of the symbols in the rules that are matched
4
- # by the input tokens.
5
- # The right part consists of symbols that are predicted to match the
6
- # input tokens.
7
- # The terminology stems from the traditional way to visualize the partition
8
- # by using a fat dot character as a separator between the left and right parts
9
- # An item with the dot at the beginning (i.e. before any rhs symbol)
10
- # is called a predicted item.
11
- # An item with the dot at the end (i.e. after all rhs symbols)
12
- # is called a reduce item.
13
- # An item with a dot in front of a terminal is called a shift item.
14
- class DottedItem
15
- # Production rule
16
- attr_reader(:production)
1
+ module Rley # This module is used as a namespace
17
2
 
18
- # Index of the next symbol (from the rhs) after the 'dot'.
19
- # If the dot is at the end of the rhs (i.e.) there is no next
20
- # symbol, then the position takes the value -1.
21
- # It the rhs is empty, then the postion is -2
22
- attr_reader(:position)
3
+ # A dotted item is a parse state for a given production/grammar rule
4
+ # It partitions the rhs of the rule in two parts.
5
+ # The left part consists of the symbols in the rules that are matched
6
+ # by the input tokens.
7
+ # The right part consists of symbols that are predicted to match the
8
+ # input tokens.
9
+ # The terminology stems from the traditional way to visualize the partition
10
+ # by using a fat dot character as a separator between the left and right
11
+ # parts
12
+ # An item with the dot at the beginning (i.e. before any rhs symbol)
13
+ # is called a predicted item.
14
+ # An item with the dot at the end (i.e. after all rhs symbols)
15
+ # is called a reduce item.
16
+ # An item with a dot in front of a terminal is called a shift item.
17
+ class DottedItem
18
+ # Production rule
19
+ attr_reader(:production)
23
20
 
24
- # @param aProduction
25
- def initialize(aProduction, aPosition)
26
- @production = aProduction
27
- @position = valid_position(aPosition)
28
- end
29
-
30
- # Return true if the dot position is at the start of the rhs.
31
- def at_start?()
32
- return position == 0 || position == -2
33
- end
21
+ # Index of the next symbol (from the rhs) after the 'dot'.
22
+ # If the dot is at the end of the rhs (i.e.) there is no next
23
+ # symbol, then the position takes the value -1.
24
+ # It the rhs is empty, then the postion is -2
25
+ attr_reader(:position)
34
26
 
35
- # An item with the dot at the beginning is called
36
- # predicted item
37
- alias :predicted_item? :at_start?
38
-
39
- # A dotted item is called a reduce item if the dot is at the end.
40
- def reduce_item?()
41
- return position < 0 # Either -1 or -2
42
- end
43
-
44
- # The non-terminal symbol that is on the left-side of the production
45
- def lhs()
46
- return production.lhs
47
- end
48
-
49
- # Return the symbol after the dot.
50
- # nil is returned if the dot is at the end
51
- def next_symbol()
52
- result = (position < 0) ? nil : production.rhs[position]
53
- end
27
+ # @param aProduction
28
+ def initialize(aProduction, aPosition)
29
+ @production = aProduction
30
+ @position = valid_position(aPosition)
31
+ end
32
+
33
+ # Return true if the dot position is at the start of the rhs.
34
+ def at_start?()
35
+ return position == 0 || position == -2
36
+ end
54
37
 
55
- # An item with the dot in front of a terminal is called a shift item
56
- def shift_item?()
57
- end
38
+ # An item with the dot at the beginning is called
39
+ # predicted item
40
+ alias :predicted_item? :at_start?
58
41
 
59
- private
42
+ # A dotted item is called a reduce item if the dot is at the end.
43
+ def reduce_item?()
44
+ return position < 0 # Either -1 or -2
45
+ end
46
+
47
+ # The non-terminal symbol that is on the left-side of the production
48
+ def lhs()
49
+ return production.lhs
50
+ end
51
+
52
+ # Return the symbol after the dot.
53
+ # nil is returned if the dot is at the end
54
+ def next_symbol()
55
+ result = (position < 0) ? nil : production.rhs[position]
56
+ end
60
57
 
61
- # Return the given after its validation.
62
- def valid_position(aPosition)
63
- rhs_size = production.rhs.size
64
- if aPosition < 0 || aPosition > rhs_size
65
- fail StandardError, 'Out of bound index'
58
+ # An item with the dot in front of a terminal is called a shift item
59
+ def shift_item?()
66
60
  end
67
61
 
68
- if rhs_size == 0
69
- index = -2 # Minus 2 at start/end of empty production
70
- elsif aPosition == rhs_size
71
- index = -1 # Minus 1 at end of non-empty production
72
- else
73
- index = aPosition
62
+ private
63
+
64
+ # Return the given after its validation.
65
+ def valid_position(aPosition)
66
+ rhs_size = production.rhs.size
67
+ if aPosition < 0 || aPosition > rhs_size
68
+ fail StandardError, 'Out of bound index'
69
+ end
70
+
71
+ if rhs_size == 0
72
+ index = -2 # Minus 2 at start/end of empty production
73
+ elsif aPosition == rhs_size
74
+ index = -1 # Minus 1 at end of non-empty production
75
+ else
76
+ index = aPosition
77
+ end
78
+
79
+ return index
74
80
  end
81
+ end # class
75
82
 
76
- return index
77
- end
78
- end # class
83
+ end # module
79
84
 
80
85
  # End of file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rley
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.03
4
+ version: 0.0.04
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitri Geshef