Class: Kwalify::BaseParser
- Inherits:
-
Object
- Object
- Kwalify::BaseParser
- Defined in:
- lib/kwalify/parser/base.rb
Overview
base class for Yaml::Parser
Direct Known Subclasses
Constant Summary collapse
- CHAR_TABLE =
{ "\""=>"\"", "\\"=>"\\", "n"=>"\n", "r"=>"\r", "t"=>"\t", "b"=>"\b" }
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#linenum ⇒ Object
readonly
Returns the value of attribute linenum.
Instance Method Summary collapse
- #_getch ⇒ Object
- #_set_column_and_linenum(s) ⇒ Object
- #eos? ⇒ Boolean
- #group(n) ⇒ Object
- #match?(regexp) ⇒ Boolean
- #peep(n = 1) ⇒ Object
- #reset(input, filename = nil, untabify = false) ⇒ Object
- #scan(regexp) ⇒ Object
- #scan_string ⇒ Object
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
25 26 27 |
# File 'lib/kwalify/parser/base.rb', line 25 def column @column end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
25 26 27 |
# File 'lib/kwalify/parser/base.rb', line 25 def filename @filename end |
#linenum ⇒ Object (readonly)
Returns the value of attribute linenum.
25 26 27 |
# File 'lib/kwalify/parser/base.rb', line 25 def linenum @linenum end |
Instance Method Details
#_getch ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/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) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/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? ⇒ Boolean
57 58 59 |
# File 'lib/kwalify/parser/base.rb', line 57 def eos? return @scanner.eos? end |
#group(n) ⇒ Object
52 53 54 |
# File 'lib/kwalify/parser/base.rb', line 52 def group(n) return @scanner[n] end |
#match?(regexp) ⇒ Boolean
47 48 49 |
# File 'lib/kwalify/parser/base.rb', line 47 def match?(regexp) return @scanner.match?(regexp) end |
#peep(n = 1) ⇒ Object
62 63 64 |
# File 'lib/kwalify/parser/base.rb', line 62 def peep(n=1) return @scanner.peep(n) end |
#reset(input, filename = nil, untabify = false) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/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) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/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 ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/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 |