Class: Fmt::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/fmt/parsers/parser.rb

Overview

Responsible for parsing various inputs and returning an AST (Abstract Syntax Tree)

Mechanics are similar to an ETL pipeline (Extract, Transform, Load), however, parsers only handle extracting and transforming.

Loading is handled by AST processors (Models)

See Also:

  • lib/fmt/models/

Constant Summary collapse

Cache =

: Fmt::LRUCache – local in-memory cache

Fmt::LRUCache.new

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.esc(value) ⇒ Object

Escapes a string for use in a regular expression



19
# File 'lib/fmt/parsers/parser.rb', line 19

def self.esc(value) = Regexp.escape(value.to_s)

Instance Method Details

#parseObject

Note:

Subclasses must implement the extract and transform methods

Parses input passed to the constructor and returns an AST (Abstract Syntax Tree)

  1. Extract components

  2. Transform to AST



29
30
31
# File 'lib/fmt/parsers/parser.rb', line 29

def parse
  extract.then { transform(**_1) }
end