Class: Rubycc::Pkgconf::Parser
- Inherits:
-
Object
- Object
- Rubycc::Pkgconf::Parser
- Defined in:
- lib/rubycc/pkgconf/parser.rb
Overview
Parses one .pc file's text into a Package. The grammar covered is
exactly what the real .pc files this environment ships (zlib.pc,
libffi.pc, openssl.pc's Requires chain — see test/fixtures/pkgconfig)
and mkmf's own pkg_config() call shape actually use: #-comments and
blank lines, name=value variable assignments, ${name} expansion
inside both variable and field values, and the seven fields
Name/Description/Version/Requires/Requires.private/Libs/Libs.private/
Cflags. Any other field line (URL:, Conflicts:, ...) is accepted and
ignored — mkmf's pkg_config() never reads them — rather than rejected,
so a real-world .pc with extra fields still parses.
Constant Summary collapse
- VARIABLE_LINE =
/\A([A-Za-z_][A-Za-z0-9_.]*)=(.*)\z/- FIELD_LINE =
/\A([A-Za-z][A-Za-z0-9.]*)\s*:\s*(.*)\z/- VARIABLE_REFERENCE =
/\$\{([A-Za-z_][A-Za-z0-9_.]*)\}/- REQUIRES_OPERATOR =
A single
Requires/Requires.privateentry with a version comparison attached, spaced (zlib >= 1.2) or not (zlib>=1.2). /\A(<=|>=|==|!=|<|>|=)\z/- KNOWN_FIELDS =
%w[Name Description Version Requires Requires.private Libs Libs.private Cflags].freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(text, path: nil) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(text, path: nil) ⇒ Parser
Returns a new instance of Parser.
30 31 32 33 34 35 |
# File 'lib/rubycc/pkgconf/parser.rb', line 30 def initialize(text, path: nil) @text = text @path = path @variables = {} @fields = {} end |
Class Method Details
.parse(text, path: nil) ⇒ Object
26 27 28 |
# File 'lib/rubycc/pkgconf/parser.rb', line 26 def self.parse(text, path: nil) new(text, path: path).parse end |
Instance Method Details
#parse ⇒ Object
37 38 39 40 41 42 |
# File 'lib/rubycc/pkgconf/parser.rb', line 37 def parse @text.each_line.with_index(1) do |raw_line, line_number| parse_line(raw_line.chomp, line_number) end build_package end |