Class: Pubid::Bipm::Parser

Inherits:
Parslet::Parser
  • Object
show all
Defined in:
lib/pubid/bipm/parser.rb

Overview

Parslet grammar for the four BIPM identifier families. The root branches by leading token / shape; each alternative is wrapped in a distinct key (:committee_short, :meeting_en, …) so the Builder can dispatch on the matched branch without re-inspecting the string.

Group and type-word alternations are built from the shared vocabularies on Identifier (sorted longest-first so e.g. "CCTF" is tried before "CCT").

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(input) ⇒ Object



179
180
181
# File 'lib/pubid/bipm/parser.rb', line 179

def self.parse(input)
  new.parse(input)
end

Instance Method Details

#alternation(tokens) ⇒ Object

Longest-first alternation over a list of literal tokens, so a token that is a prefix of another (e.g. "CCT" of "CCTF") never shadows it.



33
34
35
# File 'lib/pubid/bipm/parser.rb', line 33

def alternation(tokens)
  tokens.sort_by { |t| -t.length }.map { |t| str(t) }.reduce(:|)
end