Class: MaRuKu::In::Markdown::SpanLevelParser::CharSourceManual
Overview
a string scanner coded by me
Constant Summary
CharSource, Close_class, EscapedCharInInlineCode, EscapedCharInQuotes, EscapedCharInText, Punct_class, R_REF_ID, Rules, SPACE
Constants included
from Strings
Strings::Abbreviation, Strings::AttributeDefinitionList, Strings::Definition, Strings::EMailAddress, Strings::FootnoteText, Strings::HeaderWithAttributes, Strings::HeaderWithId, Strings::IncompleteLink, Strings::InlineAttributeList, Strings::LinkRegex, Strings::MightBeTableHeader, Strings::Sep, Strings::TabSize, Strings::TableSeparator
Instance Method Summary
collapse
#apply_one_rule, #describe_pos, #educate, #extension_meta, #interpret_extension, #is_ial, #md_al, #merge_ial, #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_simple, #read_span, #read_strong, #read_url, #read_url_el, #read_xml_instr_span, #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_strong, #md_url, #md_xml_instr
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, #sanitize_ref_id, #spaces_before_first_char, #split_lines, #strip_hashes, #strip_indent, #unquote
Constructor Details
Returns a new instance of CharSourceManual.
44
45
46
47
48
49
|
# File 'lib/amp-front/third_party/maruku/input/charsource.rb', line 44
def initialize(s, parent=nil)
raise "Passed #{s.class}" if not s.kind_of? String
@buffer = s
@buffer_index = 0
@parent = parent
end
|
Instance Method Details
#consume_whitespace ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/amp-front/third_party/maruku/input/charsource.rb', line 123
def consume_whitespace
while c = cur_char
if (c == ?\s || c == ?\t)
ignore_char
else
break
end
end
end
|
Return current char as a FixNum (or nil).
52
|
# File 'lib/amp-front/third_party/maruku/input/charsource.rb', line 52
def cur_char; @buffer[@buffer_index] end
|
#cur_chars(n) ⇒ Object
Return the next n chars as a String.
55
|
# File 'lib/amp-front/third_party/maruku/input/charsource.rb', line 55
def cur_chars(n); @buffer[@buffer_index,n] end
|
#cur_chars_are(string) ⇒ Object
80
81
82
83
84
85
86
87
88
|
# File 'lib/amp-front/third_party/maruku/input/charsource.rb', line 80
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
76
77
78
|
# File 'lib/amp-front/third_party/maruku/input/charsource.rb', line 76
def current_remaining_buffer
@buffer[@buffer_index, @buffer.size-@buffer_index]
end
|
144
145
146
147
148
149
150
|
# File 'lib/amp-front/third_party/maruku/input/charsource.rb', line 144
def describe
s = describe_pos(@buffer, @buffer_index)
if @parent
s += "\n\n" + @parent.describe
end
s
end
|
#ignore_char ⇒ Object
66
67
68
69
|
# File 'lib/amp-front/third_party/maruku/input/charsource.rb', line 66
def ignore_char
@buffer_index+=1
nil
end
|
#ignore_chars(n) ⇒ Object
71
72
73
74
|
# File 'lib/amp-front/third_party/maruku/input/charsource.rb', line 71
def ignore_chars(n)
@buffer_index+=n
nil
end
|
#next_char ⇒ Object
Return the char after current char as a FixNum (or nil).
58
|
# File 'lib/amp-front/third_party/maruku/input/charsource.rb', line 58
def next_char; @buffer[@buffer_index+1] end
|
#next_matches(r) ⇒ Object
90
91
92
93
94
|
# File 'lib/amp-front/third_party/maruku/input/charsource.rb', line 90
def next_matches(r)
r2 = /^.{#{@buffer_index}}#{r}/m
md = r2.match @buffer
return !!md
end
|
#read_regexp(r) ⇒ Object
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/amp-front/third_party/maruku/input/charsource.rb', line 112
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/amp-front/third_party/maruku/input/charsource.rb', line 96
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
135
136
137
138
139
140
141
142
|
# File 'lib/amp-front/third_party/maruku/input/charsource.rb', line 135
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
60
61
62
63
64
|
# File 'lib/amp-front/third_party/maruku/input/charsource.rb', line 60
def shift_char
c = @buffer[@buffer_index]
@buffer_index+=1
c
end
|