Module: ParserMethods
- Included in:
- LazyPP::Parser
- Defined in:
- lib/readable-cpp/common.rb
Class Method Summary collapse
Instance Method Summary collapse
- #`(str) ⇒ Object
- #comma_list(rule, min = 0) ⇒ Object
- #join(rule, on, min = 0, max = nil) ⇒ Object
- #parens(rule) ⇒ Object
Class Method Details
.included(cls) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/readable-cpp/common.rb', line 19 def self.included(cls) raise <<-end unless cls < Parslet::Parser Hi there, you included ParserMethods in a class that doth not derive from Parslet::Parser. Be thou tripping? end cls.class_eval do rule(:l_paren) { str(?() } rule(:r_paren) { str(?)) } rule(:comma) { str(?,) } rule(:colon) { str(?:) } rule(:semicolon) { str(?;) } rule(:l_bracket) { str(?{) } rule(:r_bracket) { str(?}) } ## swap these in when im willing to change all references in parser.rb # rule(:l_bracket) { str(?[) } # rule(:r_bracket) { str(?]) } # rule(:l_brace) { str(?{) } # rule(:r_brace) { str(?}) } end end |
Instance Method Details
#`(str) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/readable-cpp/common.rb', line 3 def `(str) str.split(//). map{|c| match[c =~ /[A-Za-z]/ ? c.upcase<<c.downcase : c] }. reduce(:>>) end |
#comma_list(rule, min = 0) ⇒ Object
16 17 18 |
# File 'lib/readable-cpp/common.rb', line 16 def comma_list(rule, min = 0) join(rule, space? >> comma >> space?, min) end |
#join(rule, on, min = 0, max = nil) ⇒ Object
10 11 12 |
# File 'lib/readable-cpp/common.rb', line 10 def join(rule, on, min = 0, max = nil) rule >> (on >> rule).repeat(min, max) end |
#parens(rule) ⇒ Object
13 14 15 |
# File 'lib/readable-cpp/common.rb', line 13 def parens(rule) l_paren >> space? >> rule >> space? >> r_paren end |