src/PresentationParser.rb
#This works just like it does in C++
This works just like it does in C
This works just like it does in C
def parse(str)
		re = /\s*(\D*?)(\d*):(\s*)(.*)/
		slides = Array.new
		num = 0
		state = Start
		currTitle = ""
		content = ""
		code = ""
		str.each_line { |line|	
			if line =~ re
				case $1
				when "Title" 
					case state
					when HasTitle
						slides << Slide.new(currTitle, num)
					when Bullets
						slides << BulletPointsSlide.new(currTitle, num, content)
					when Text
						slides << TextSlide.new(currTitle, num, content)
					when Code
						slides << CodeSlide.new(currTitle, num, code)
					when Composite
						slides << CodeTextCompositeSlide.new(currTitle, num, content, code)
					end
					num+=1          
					currTitle = $4
					content = code = ""
					state=HasTitle
				when "B" 
					if state != Bullets
						content = Array.new
					end
					bpArray = [$2.to_i,$4]	
					content << bpArray
					state = Bullets
				when "Text"
					if state != Text
						content = ""
					end
					content += $4 + "\n"
					if(state == Code)
						state = Composite
					else
						state = Text
					end
				when ""
					code += $3 + $4 + "\n"
					if(state == Text)
						state = Composite
					else
						state = Code
					end
				end
			elsif
				if line.strip != ''
					puts "Found bogus line '#{line}'"
				end
			end   
		}
		case state
		when HasTitle
			slides << Slide.new(currTitle, num)
		when Bullets
			slides << BulletPointsSlide.new(currTitle, num, content)
		when Text
			slides << TextSlide.new(currTitle, num, content)
		when Code
			slides << CodeSlide.new(currTitle, num, code)
		when Composite
			slides << CodeTextCompositeSlide.new(currTitle, num, content, code)
		end
		return slides
	end
def parse ( str ) re = / \s *( \D *?)( \d *):( \s *)(.*) / slides = Array . new num = 0 state = Start currTitle = "" content = "" code = "" str . each_line { | line | if line =~ re case $1 when "Title" case state when HasTitle slides << Slide . new ( currTitle , num ) when Bullets slides << BulletPointsSlide . new ( currTitle , num , content ) when Text slides << TextSlide . new ( currTitle , num , content ) when Code slides << CodeSlide . new ( currTitle , num , code ) when Composite slides << CodeTextCompositeSlide . new ( currTitle , num , content , code ) end num += 1 currTitle = $4 content = code = "" state = HasTitle when "B" if state != Bullets content = Array . new end bpArray = [ $2 . to_i , $4 ] content << bpArray state = Bullets when "Text" if state != Text content = "" end content += $4 + "\n" if ( state == Code ) state = Composite else state = Text end when "" code += $3 + $4 + "\n" if ( state == Text ) state = Composite else state = Code end end elsif if line . strip != '' puts "Found bogus line '#{line}'" end end } case state when HasTitle slides << Slide . new ( currTitle , num ) when Bullets slides << BulletPointsSlide . new ( currTitle , num , content ) when Text slides << TextSlide . new ( currTitle , num , content ) when Code slides << CodeSlide . new ( currTitle , num , code ) when Composite slides << CodeTextCompositeSlide . new ( currTitle , num , content , code ) end return slides end
This works just like it does in C++
This works just like it does in C ++
#Matches something like <text><number>:<anything goes here> #All these variables need to be declared up here. If they are #instantiated in the block below, they will only be in that block's #scope and will not be visible once the block exits (annoying). #The each method splits the string up at newlines by default, but it #takes a parameter and can split by anything. #Start of a new slide #Insert our working slide into the array #Bullet point #to_i converts string > integer				 #.strip removes leading and trailing whitespace #insert final slide
str