Class: Fluent::Config::BasicParser

Inherits:
Object
  • Object
show all
Extended by:
ClassMethods
Defined in:
lib/fluent/config/basic_parser.rb

Direct Known Subclasses

LiteralParser

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

LINE_END =
/(?:[ \t]*(?:\#.*)?(?:\z|[\r\n]))+/
SPACING =
/(?:[ \t\r\n]|\z|\#.*?(?:\z|[\r\n]))+/
ZERO_OR_MORE_SPACING =
/(?:[ \t\r\n]|\z|\#.*?(?:\z|[\r\n]))*/
SPACING_WITHOUT_COMMENT =
/(?:[ \t\r\n]|\z)+/

Instance Method Summary collapse

Methods included from ClassMethods

def_literal, def_symbol, symbol

Constructor Details

#initialize(strscan) ⇒ BasicParser

Returns a new instance of BasicParser.



23
24
25
# File 'lib/fluent/config/basic_parser.rb', line 23

def initialize(strscan)
  @ss = strscan
end

Instance Method Details

#check(pattern) ⇒ Object



74
75
76
# File 'lib/fluent/config/basic_parser.rb', line 74

def check(pattern)
  @ss.check(pattern)
end

#eof? ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/fluent/config/basic_parser.rb', line 66

def eof?
  @ss.eos?
end

#error_sample ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/fluent/config/basic_parser.rb', line 94

def error_sample
  pos = @ss.pos

  lines = @ss.string.lines.to_a
  lines.each_with_index { |line, ln|
    if line.size >= pos
      msgs = ["line #{ln + 1},#{pos}\n"]

      if ln > 0
        last_line = lines[ln - 1]
        msgs << "%3s: %s" % [ln, last_line]
      end

      msgs << "%3s: %s" % [ln + 1, line]
      msgs << "\n     #{'-' * pos}^\n"

      if next_line = lines[ln + 1]
        msgs << "%3s: %s" % [ln + 2, next_line]
      end

      return msgs.join
    end
    pos -= line.size
    last_line = line
  }
end

#getch ⇒ Object



62
63
64
# File 'lib/fluent/config/basic_parser.rb', line 62

def getch
  @ss.getch
end

#line_end ⇒ Object



78
79
80
# File 'lib/fluent/config/basic_parser.rb', line 78

def line_end
  skip(LINE_END)
end

#parse_error!(message) ⇒ Object

Raises:



90
91
92
# File 'lib/fluent/config/basic_parser.rb', line 90

def parse_error!(message)
  raise ConfigParseError, "#{message} at #{error_sample}"
end

#prev_match ⇒ Object



70
71
72
# File 'lib/fluent/config/basic_parser.rb', line 70

def prev_match
  @ss[0]
end

#scan(pattern) ⇒ Object



58
59
60
# File 'lib/fluent/config/basic_parser.rb', line 58

def scan(pattern)
  @ss.scan(pattern)
end

#skip(pattern) ⇒ Object



54
55
56
# File 'lib/fluent/config/basic_parser.rb', line 54

def skip(pattern)
  @ss.skip(pattern)
end

#spacing ⇒ Object



82
83
84
# File 'lib/fluent/config/basic_parser.rb', line 82

def spacing
  skip(SPACING)
end

#spacing_without_comment ⇒ Object



86
87
88
# File 'lib/fluent/config/basic_parser.rb', line 86

def spacing_without_comment
  skip(SPACING_WITHOUT_COMMENT)
end