Class: Libis::Metadata::Parser::BasicParser
- Inherits:
-
Parslet::Parser
- Object
- Parslet::Parser
- Libis::Metadata::Parser::BasicParser
show all
- Defined in:
- lib/libis/metadata/parser/basic_parser.rb
Overview
New style parsers and converters for metadata. New, not finished and untested.
Instance Method Summary
collapse
Instance Method Details
#any_quoted(key = :text) ⇒ Object
100
101
102
103
104
105
106
|
# File 'lib/libis/metadata/parser/basic_parser.rb', line 100
def any_quoted(key = :text)
scope {
quote.capture(:quote) >>
dynamic {|_, c| (str(c.captures[:quote]).absent? >> any).repeat(1)}.maybe.as(key) >>
dynamic {|_, c| str(c.captures[:quote])}
}
end
|
#complement(char) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/libis/metadata/parser/basic_parser.rb', line 71
def complement(char)
case char
when '('
')'
when '{'
'}'
when '['
']'
else
char
end
end
|
#grouped(foo, left_paren = lparen) ⇒ Object
84
85
86
87
88
89
90
|
# File 'lib/libis/metadata/parser/basic_parser.rb', line 84
def grouped(foo, left_paren = lparen)
scope {
left_paren.capture(:paren).as(:lparen) >>
foo >>
dynamic {|_, c| str(complement(c.captures[:paren]))}.as(:rparen)
}
end
|
#grouped_anonymous(foo, left_paren = lparen) ⇒ Object
92
93
94
95
96
97
98
|
# File 'lib/libis/metadata/parser/basic_parser.rb', line 92
def grouped_anonymous(foo, left_paren = lparen)
scope {
left_paren.capture(:paren) >>
foo >>
dynamic {|_, c| str(complement(c.captures[:paren]))}
}
end
|
108
109
110
|
# File 'lib/libis/metadata/parser/basic_parser.rb', line 108
def transformer
self.class::Transformer.new rescue nil
end
|