Module: Antelope::Generation::Constructor::Nullable
- Included in:
- Antelope::Generation::Constructor
- Defined in:
- lib/antelope/generation/constructor/nullable.rb
Overview
Contains the methods to determine if an object is nullable.
Instance Method Summary collapse
-
#initialize ⇒ Object
Initialize.
-
#nullable?(token) ⇒ Boolean
Determine if a given token is nullable.
-
#nullifying(tok) { ... } ⇒ Boolean
private
Helps keep track of the nonterminals we're checking for nullability.
Instance Method Details
#initialize ⇒ Object
Initialize.
11 12 13 |
# File 'lib/antelope/generation/constructor/nullable.rb', line 11 def initialize = Set.new end |
#nullable?(token) ⇒ Boolean
Determine if a given token is nullable. This is how the method should behave:
nullable?(
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/antelope/generation/constructor/nullable.rb', line 28 def nullable?(token) case token when Grammar::Token::Nonterminal (token) do productions = grammar.productions[token.name] !!productions.any? { |prod| nullable?(prod[:items]) } end when Array token.dup.delete_if { |tok| .include?(tok) }.all? { |tok| nullable?(tok) } when Grammar::Token::Epsilon true when Grammar::Token::Terminal false else incorrect_argument! token, Grammar::Token, Array end end |
#nullifying(tok) { ... } ⇒ Boolean (private)
Helps keep track of the nonterminals we're checking for nullability. This helps prevent recursion.
55 56 57 58 59 60 |
# File 'lib/antelope/generation/constructor/nullable.rb', line 55 def (tok) << tok out = yield .delete tok out end |