Class: StartMatchEmpty
- Inherits:
-
GrammarLinter
- Object
- GrammarPlugin
- GrammarLinter
- StartMatchEmpty
- Defined in:
- lib/ruby_grammar_builder/linters/start_match_empty.rb
Overview
Warns when a PatternRange has a start_pattern that matches the empty string
Class Method Summary collapse
-
.display_options(indent, options) ⇒ String
Displays the state of the options.
-
.options ⇒ Array<Symbol>
Contributes the option :zeroLengthStart?.
Instance Method Summary collapse
-
#pre_lint(pattern, options) ⇒ Boolean
Runs the linter on each pattern.
Methods inherited from GrammarLinter
Class Method Details
.display_options(indent, options) ⇒ String
Displays the state of the options
44 45 46 |
# File 'lib/ruby_grammar_builder/linters/start_match_empty.rb', line 44 def self.(indent, ) ",\n#{indent}zeroLengthStart?: #{[:zeroLengthStart?]}" end |
.options ⇒ Array<Symbol>
Contributes the option :zeroLengthStart?
:zeroLengthStart? disables this linter
35 36 37 |
# File 'lib/ruby_grammar_builder/linters/start_match_empty.rb', line 35 def self. [:zeroLengthStart?] end |
Instance Method Details
#pre_lint(pattern, options) ⇒ Boolean
Runs the linter on each pattern
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ruby_grammar_builder/linters/start_match_empty.rb', line 12 def pre_lint(pattern, ) return true unless pattern.is_a? PatternRange regexp = with_no_warnings do Regexp.new(pattern.start_pattern.evaluate.gsub("\\G", '\uFFFF')) end if "" =~ regexp and ![:zeroLengthStart?] puts "Warning: #{pattern.start_pattern.evaluate}" puts "matches the zero length string (\"\").\n\n" puts "This means that the patternRange always matches" puts "You can disable this warning by setting :zeroLengthStart? to true." puts "The pattern is:\n#{pattern}" end true # return true for warnings end |