ehhhhh treetop isn't my favorite right now

treetop
Jordan Orelli 9 years ago
parent fc69b7d45e
commit 2a4f77d8f9

@ -15,7 +15,9 @@ module Bristlecode
end end
def inspect(indent="") def inspect(indent="")
"#{indent}TextNode: #{text_value}" s = "#{indent}TextNode:\n"
text_value.each_line{|line| s += "#{indent} #{line}"}
s
end end
def to_html def to_html
@ -23,13 +25,30 @@ module Bristlecode
end end
end end
##############################
# bold
##############################
class BoldNode < Treetop::Runtime::SyntaxNode
end
class BoldOpenNode < Treetop::Runtime::SyntaxNode class BoldOpenNode < Treetop::Runtime::SyntaxNode
end end
class BoldCloseNode < Treetop::Runtime::SyntaxNode class BoldCloseNode < Treetop::Runtime::SyntaxNode
end end
class BoldNode < Treetop::Runtime::SyntaxNode ##############################
# italic
##############################
class ItalicNode < Treetop::Runtime::SyntaxNode
end
class ItalicOpenNode < Treetop::Runtime::SyntaxNode
end
class ItalicCloseNode < Treetop::Runtime::SyntaxNode
end end
class TagNode < Treetop::Runtime::SyntaxNode class TagNode < Treetop::Runtime::SyntaxNode

@ -1,6 +1,6 @@
grammar Bristlecode grammar Bristlecode
rule root rule root
(tag / text)+ <RootNode> (tag / text)* <RootNode>
end end
rule text rule text
@ -8,7 +8,7 @@ grammar Bristlecode
end end
rule tag rule tag
(bold) <TagNode> bold / italic
end end
############################## ##############################
@ -29,4 +29,23 @@ grammar Bristlecode
rule bold_close rule bold_close
'[/b]' <BoldCloseNode> / '[/B]' <BoldCloseNode> '[/b]' <BoldCloseNode> / '[/B]' <BoldCloseNode>
end end
##############################
# italic
##############################
rule italic
italic_open
((!italic_close .)+ <TextNode>)
italic_close
<ItalicNode>
end
rule italic_open
'[i]' <ItalicOpenNode> / '[I]' <ItalicOpenNode>
end
rule italic_close
'[/i]' <ItalicCloseNode> / '[/I]' <ItalicCloseNode>
end
end end

Loading…
Cancel
Save