Class: Ellipses::Client::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/ellipses/client/parser.rb

Defined Under Namespace

Classes: Lexeme, Parsed

Constant Summary collapse

PATTERN =
/
  ^
  (?<prefix>\s*)
  (?<directive>(?:[.]|>){3,}.*)
/x

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ Parser

Returns a new instance of Parser.



48
49
50
# File 'lib/ellipses/client/parser.rb', line 48

def initialize(line)
  @line = line
end

Instance Attribute Details

#lineObject (readonly)

Returns the value of attribute line.



46
47
48
# File 'lib/ellipses/client/parser.rb', line 46

def line
  @line
end

Class Method Details

.match?(line) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/ellipses/client/parser.rb', line 39

def match?(line)
  !line.match(PATTERN).nil?
end

.parse(line) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/ellipses/client/parser.rb', line 31

def parse(line)
  return unless (match = line.match(PATTERN))

  parser = new(match[:directive])

  Parsed.new lexemes: parser.(), prefix: match[:prefix]
end

Instance Method Details

#callObject



52
53
54
55
56
57
# File 'lib/ellipses/client/parser.rb', line 52

def call
  Shellwords.split(preprocess(line)).slice_after('|').map do |group|
    group.pop if group.last == '|'
    Lexeme.from_strings(group)
  end
end