Class: MaRuKu::In::Markdown::SpanLevelParser::CharSourceManual

Inherits:
Object
  • Object
show all
Includes:
MaRuKu::In::Markdown::SpanLevelParser, Strings
Defined in:
lib/maruku/input/charsource.rb,
lib/maruku/input/charsource.rb

Overview

a string scanner coded by me

Constant Summary

Constants included from MaRuKu::In::Markdown::SpanLevelParser

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

Methods included from MaRuKu::In::Markdown::SpanLevelParser

#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

#initialize(s) ⇒ CharSourceManual

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_whitespaceObject



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)
#				puts "ignoring #{c}"
			ignore_char
		else
#				puts "#{c} is not ws: "<<c
			break
		end
	end
end

#cur_charObject

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)
	# There is a bug here
	if false
		r2 = /^.{#{@buffer_index}}#{Regexp.escape string}/m
		@buffer =~ r2
	else
		cur_chars(string.size) == string
	end
end

#current_remaining_bufferObject



74
75
76
# File 'lib/maruku/input/charsource.rb', line 74

def current_remaining_buffer
	@buffer[@buffer_index, @buffer.size-@buffer_index]
end

#describeObject



142
143
144
# File 'lib/maruku/input/charsource.rb', line 142

def describe
	describe_pos(@buffer, @buffer_index)
end

#ignore_charObject



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_charObject

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
#				puts "#{r} matched #{rest.inspect}: #{m.to_s.inspect}"
	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
#			puts "Consumed #{consumed} chars (entire is #{m.to_s.inspect})"
		ignore_chars consumed
	else
#			puts "Could not read regexp #{r2.inspect} from buffer "+
#			" index=#{@buffer_index}"
#			puts "Cur chars = #{cur_chars(20).inspect}"
#			puts "Matches? = #{cur_chars(20) =~ r}"
	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_charObject



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