Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
Jordan Orelli | 2a4f77d8f9 | 9 years ago |
Jordan Orelli | fc69b7d45e | 9 years ago |
@ -0,0 +1,3 @@
|
|||||||
|
Gemfile.lock
|
||||||
|
.bundle
|
||||||
|
|
@ -0,0 +1,18 @@
|
|||||||
|
require 'sanitize'
|
||||||
|
require 'treetop'
|
||||||
|
|
||||||
|
base_path = File.expand_path(File.dirname(__FILE__))
|
||||||
|
require File.join(base_path, 'bristlecode_nodes.rb')
|
||||||
|
|
||||||
|
class Bristle
|
||||||
|
Treetop.load(File.join(File.expand_path(File.dirname(__FILE__)), 'bristlecode_parser.treetop'))
|
||||||
|
@@parser = BristlecodeParser.new
|
||||||
|
|
||||||
|
def self.parse(doc)
|
||||||
|
tree = @@parser.parse(doc)
|
||||||
|
if tree.nil?
|
||||||
|
raise Exception, "Bristlecode parse error at offset: #{@@parser.index}"
|
||||||
|
end
|
||||||
|
tree
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,56 @@
|
|||||||
|
module Bristlecode
|
||||||
|
class RootNode < Treetop::Runtime::SyntaxNode
|
||||||
|
def to_html
|
||||||
|
elements.each{|elem| elem.to_html}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class TextNode < Treetop::Runtime::SyntaxNode
|
||||||
|
def initialize(input, interval, elements)
|
||||||
|
@text = input[interval]
|
||||||
|
end
|
||||||
|
|
||||||
|
def text_value
|
||||||
|
@text
|
||||||
|
end
|
||||||
|
|
||||||
|
def inspect(indent="")
|
||||||
|
s = "#{indent}TextNode:\n"
|
||||||
|
text_value.each_line{|line| s += "#{indent} #{line}"}
|
||||||
|
s
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_html
|
||||||
|
text_value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
##############################
|
||||||
|
# bold
|
||||||
|
##############################
|
||||||
|
|
||||||
|
class BoldNode < Treetop::Runtime::SyntaxNode
|
||||||
|
end
|
||||||
|
|
||||||
|
class BoldOpenNode < Treetop::Runtime::SyntaxNode
|
||||||
|
end
|
||||||
|
|
||||||
|
class BoldCloseNode < Treetop::Runtime::SyntaxNode
|
||||||
|
end
|
||||||
|
|
||||||
|
##############################
|
||||||
|
# italic
|
||||||
|
##############################
|
||||||
|
|
||||||
|
class ItalicNode < Treetop::Runtime::SyntaxNode
|
||||||
|
end
|
||||||
|
|
||||||
|
class ItalicOpenNode < Treetop::Runtime::SyntaxNode
|
||||||
|
end
|
||||||
|
|
||||||
|
class ItalicCloseNode < Treetop::Runtime::SyntaxNode
|
||||||
|
end
|
||||||
|
|
||||||
|
class TagNode < Treetop::Runtime::SyntaxNode
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,51 @@
|
|||||||
|
grammar Bristlecode
|
||||||
|
rule root
|
||||||
|
(tag / text)* <RootNode>
|
||||||
|
end
|
||||||
|
|
||||||
|
rule text
|
||||||
|
(!tag .)+ <TextNode>
|
||||||
|
end
|
||||||
|
|
||||||
|
rule tag
|
||||||
|
bold / italic
|
||||||
|
end
|
||||||
|
|
||||||
|
##############################
|
||||||
|
# bold
|
||||||
|
##############################
|
||||||
|
|
||||||
|
rule bold
|
||||||
|
bold_open
|
||||||
|
((!bold_close .)+ <TextNode>)
|
||||||
|
bold_close
|
||||||
|
<BoldNode>
|
||||||
|
end
|
||||||
|
|
||||||
|
rule bold_open
|
||||||
|
'[b]' <BoldOpenNode> / '[B]' <BoldOpenNode>
|
||||||
|
end
|
||||||
|
|
||||||
|
rule bold_close
|
||||||
|
'[/b]' <BoldCloseNode> / '[/B]' <BoldCloseNode>
|
||||||
|
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
|
Loading…
Reference in New Issue