Class: MaRuKu::In::Markdown::SpanLevelParser::CharSourceManual
Overview
a string scanner coded by me
Constant Summary
CharSource, EscapedCharInInlineCode, EscapedCharInQuotes, EscapedCharInText, R_REF_ID, SPACE
Constants included
from Strings
Strings::Abbreviation, Strings::AttributeDefinitionList, Strings::Definition, Strings::EMailAddress, Strings::FootnoteText, Strings::HeaderWithAttributes, Strings::HeaderWithId, Strings::IncompleteLink, Strings::LinkRegex, Strings::MightBeTableHeader, Strings::Sep, Strings::TabSize, Strings::TableSeparator, Strings::URL
Instance Method Summary
collapse
#describe_pos, #is_ial, #md_al, #parse_lines_as_span, #parse_span_better, #read_attribute_list, #read_em, #read_email_el, #read_emstrong, #read_footnote_ref, #read_image, #read_inline_code, #read_inline_html, #read_link, #read_quoted, #read_quoted_or_unquoted, #read_ref_id, #read_server_directive, #read_simple, #read_span, #read_strong, #read_url, #read_url_el, #unit_tests_for_attribute_lists
Methods included from Helpers
#md_abbr, #md_abbr_def, #md_ald, #md_br, #md_code, #md_codeblock, #md_el, #md_em, #md_email, #md_emstrong, #md_entity, #md_foot_ref, #md_footnote, #md_header, #md_hrule, #md_html, #md_ial, #md_im_image, #md_im_link, #md_image, #md_li, #md_link, #md_par, #md_quote, #md_ref_def, #md_server, #md_strong, #md_url
Methods included from Strings
#add_tabs, #dbg_describe_ary, #force_linebreak?, #line_md_type, #normalize_key_and_value, #num_leading_hashes, #number_of_leading_spaces, #parse_email_headers, #spaces_before_first_char, #split_lines, #strip_hashes, #strip_indent, #unquote
Constructor Details
Returns a new instance of CharSourceManual.
44
45
46
47
|
# File 'lib/maruku/input/charsource.rb', line 44
def initialize(s)
@buffer = s
@buffer_index = 0
end
|
Instance Method Details
#consume_whitespace ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/maruku/input/charsource.rb', line 121
def consume_whitespace
while c = cur_char
if (c == 32 || c == ?\t)
ignore_char
else
break
end
end
end
|
#cur_char ⇒ Object
Return current char as a FixNum (or nil).
50
|
# File 'lib/maruku/input/charsource.rb', line 50
def cur_char; @buffer[@buffer_index] end
|
#cur_chars(n) ⇒ Object
Return the next n chars as a String.
53
|
# File 'lib/maruku/input/charsource.rb', line 53
def cur_chars(n); @buffer[@buffer_index,n] end
|
#cur_chars_are(string) ⇒ Object
78
79
80
81
82
83
84
85
86
|
# File 'lib/maruku/input/charsource.rb', line 78
def cur_chars_are(string)
if false
r2 = /^.{#{@buffer_index}}#{Regexp.escape string}/m
@buffer =~ r2
else
cur_chars(string.size) == string
end
end
|
#current_remaining_buffer ⇒ Object
74
75
76
|
# File 'lib/maruku/input/charsource.rb', line 74
def current_remaining_buffer
@buffer[@buffer_index, @buffer.size-@buffer_index]
end
|
#describe ⇒ Object
142
143
144
|
# File 'lib/maruku/input/charsource.rb', line 142
def describe
describe_pos(@buffer, @buffer_index)
end
|
#ignore_char ⇒ Object
64
65
66
67
|
# File 'lib/maruku/input/charsource.rb', line 64
def ignore_char
@buffer_index+=1
nil
end
|
#ignore_chars(n) ⇒ Object
69
70
71
72
|
# File 'lib/maruku/input/charsource.rb', line 69
def ignore_chars(n)
@buffer_index+=n
nil
end
|
#next_char ⇒ Object
Return the char after current char as a FixNum (or nil).
56
|
# File 'lib/maruku/input/charsource.rb', line 56
def next_char; @buffer[@buffer_index+1] end
|
#next_matches(r) ⇒ Object
88
89
90
91
92
|
# File 'lib/maruku/input/charsource.rb', line 88
def next_matches(r)
r2 = /^.{#{@buffer_index}}#{r}/m
md = r2.match @buffer
return !!md
end
|
#read_regexp(r) ⇒ Object
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/maruku/input/charsource.rb', line 110
def read_regexp(r)
r2 = /^#{r}/
rest = current_remaining_buffer
m = r2.match(rest)
if m
@buffer_index += m.to_s.size
end
return m
end
|
#read_regexp3(r) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/maruku/input/charsource.rb', line 94
def read_regexp3(r)
r2 = /^.{#{@buffer_index}}#{r}/m
m = r2.match @buffer
if m
consumed = m.to_s.size - @buffer_index
ignore_chars consumed
else
end
m
end
|
#read_text_chars(out) ⇒ Object
133
134
135
136
137
138
139
140
|
# File 'lib/maruku/input/charsource.rb', line 133
def read_text_chars(out)
s = @buffer.size; c=nil
while @buffer_index < s && (c=@buffer[@buffer_index]) &&
((c>=?a && c<=?z) || (c>=?A && c<=?Z))
out << c
@buffer_index += 1
end
end
|
#shift_char ⇒ Object
58
59
60
61
62
|
# File 'lib/maruku/input/charsource.rb', line 58
def shift_char
c = @buffer[@buffer_index]
@buffer_index+=1
c
end
|