Class: Kwalify::BaseParser

Class | Kwalify::BaseParser
In: | kwalify/parser/base.rb
Parent: | Object

base class for Yaml::Parser

### Methods

_getch _set_column_and_linenum _syntax_error eos? group match? peep reset scan scan_string

### Constants

CHAR_TABLE | = | { "\""=>"\"", "\\"=>"\\", "n"=>"\n", "r"=>"\r", "t"=>"\t", "b"=>"\b" }

### Attributes

column | [R] |
filename | [R] |
linenum | [R] |

### Public Instance methods

_getch()

[Source]

    # File kwalify/parser/base.rb, line 67
      def _getch
        ch = @scanner.getch()
        if ch == "\n"
          @linenum += 1
          @column = 0
        else
          @column += 1
        end
        return ch
      end

_set_column_and_linenum(s)

[Source]

    # File kwalify/parser/base.rb, line 36
      def _set_column_and_linenum(s)
        pos = s.rindex(?\n)
        if pos
          @column = s.length - pos
          @linenum += s.count("\n")
        else
          @column += s.length
        end
      end

eos?()

[Source]

    # File kwalify/parser/base.rb, line 57
      def eos?
        return @scanner.eos?
      end

group(n)

[Source]

    # File kwalify/parser/base.rb, line 52
      def group(n)
        return @scanner[n]
      end

match?(regexp)

[Source]

    # File kwalify/parser/base.rb, line 47
      def match?(regexp)
        return @scanner.match?(regexp)
      end

peep(n=1)

[Source]

    # File kwalify/parser/base.rb, line 62
      def peep(n=1)
        return @scanner.peep(n)
      end

reset(input, filename=nil, untabify=false)

[Source]

    # File kwalify/parser/base.rb, line 18
      def reset(input, filename=nil, untabify=false)
        input = Kwalify::Util.untabify(input) if untabify
        @scanner = StringScanner.new(input)
        @filename = filename
        @linenum = 1
        @column  = 1
      end

scan(regexp)

[Source]

    # File kwalify/parser/base.rb, line 28
      def scan(regexp)
        ret = @scanner.scan(regexp)
        return nil if ret.nil?
        _set_column_and_linenum(ret)
        return ret
      end

scan_string()

[Source]

    # File kwalify/parser/base.rb, line 81
      def scan_string
        ch = _getch()
        ch == '"' || ch == "'" or raise "assertion error"
        endch = ch
        s = ''
        while !(ch = _getch()).nil? && ch != endch
          if ch != '\\'
            s << ch
          elsif (ch = _getch()).nil?
            raise _syntax_error("%s: string is not closed." % (endch == '"' ? "'\"'" : '"\'"'))
          elsif endch == '"'
            if CHAR_TABLE.key?(ch)
              s << CHAR_TABLE[ch]
            elsif ch == 'u'
              ch2 = scan(/(?:[0-9a-f][0-9a-f]){1,4}/)
              unless ch2
                raise _syntax_error("\\x: invalid unicode format.")
              end
              s << [ch2.hex].pack('U*')
            elsif ch == 'x'
              ch2 = scan(/[0-9a-zA-Z][0-9a-zA-Z]/)
              unless ch2
                raise _syntax_error("\\x: invalid binary format.")
              end
              s << [ch2].pack('H2')
            else
              s << "\\" << ch
            end
          elsif endch == "'"
            ch == '\'' || ch == '\\' ? s << ch : s << '\\' << ch
          else
            raise "unreachable"
          end
        end
        #_getch()
        return s
      end

### Protected Instance methods

_syntax_error(message, path=nil, linenum=@linenum, column=@column)

[Source]

    # File kwalify/parser/base.rb, line 120
      def _syntax_error(message, path=nil, linenum=@linenum, column=@column)
        #message = _build_message(message_key)
        return _error(Kwalify::SyntaxError, message.to_s, path, linenum, column)
      end

[Validate]