Class: ReVIEW::Compiler
Defined Under Namespace
Classes: InlineSyntaxElement, SyntaxElement
Constant Summary
collapse
- SYNTAX =
{}
- INLINE =
{}
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(strategy) ⇒ Compiler
Returns a new instance of Compiler.
17
18
19
20
21
22
23
24
25
|
# File 'lib/review/compiler.rb', line 17
def initialize(strategy)
@strategy = strategy
@non_parsed_commands = %i[embed texequation graph]
@command_name_stack = []
end
|
Instance Attribute Details
Returns the value of attribute strategy.
27
28
29
|
# File 'lib/review/compiler.rb', line 27
def strategy
@strategy
end
|
Class Method Details
.defblock(name, argc, optional = false, &block) ⇒ Object
74
75
76
|
# File 'lib/review/compiler.rb', line 74
def self.defblock(name, argc, optional = false, &block)
defsyntax(name, (optional ? :optional : :block), argc, &block)
end
|
.defsingle(name, argc, &block) ⇒ Object
78
79
80
|
# File 'lib/review/compiler.rb', line 78
def self.defsingle(name, argc, &block)
defsyntax(name, :line, argc, &block)
end
|
.defsyntax(name, type, argc, &block) ⇒ Object
82
83
84
|
# File 'lib/review/compiler.rb', line 82
def self.defsyntax(name, type, argc, &block)
SYNTAX[name] = SyntaxElement.new(name, type, argc, &block)
end
|
Instance Method Details
#compile(chap) ⇒ Object
29
30
31
32
33
|
# File 'lib/review/compiler.rb', line 29
def compile(chap)
@chapter = chap
do_compile
@strategy.result
end
|
#inline_defined?(name) ⇒ Boolean
108
109
110
|
# File 'lib/review/compiler.rb', line 108
def inline_defined?(name)
INLINE.key?(name.to_sym)
end
|
#syntax_defined?(name) ⇒ Boolean
90
91
92
|
# File 'lib/review/compiler.rb', line 90
def syntax_defined?(name)
SYNTAX.key?(name.to_sym)
end
|
#syntax_descriptor(name) ⇒ Object
94
95
96
|
# File 'lib/review/compiler.rb', line 94
def syntax_descriptor(name)
SYNTAX[name.to_sym]
end
|
#text(str, block_mode = false) ⇒ Object
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
|
# File 'lib/review/compiler.rb', line 557
def text(str, block_mode = false)
return '' if str.empty?
words = replace_fence(str).split(/(@<\w+>\{(?:[^\}\\]|\\.)*?\})/, -1)
words.each do |w|
if w.scan(/@<\w+>/).size > 1 && !/\A@<raw>/.match(w)
error "`@<xxx>' seen but is not valid inline op: #{w}"
end
end
result = ''
until words.empty?
if in_non_escaped_command? && block_mode
result << revert_replace_fence(words.shift)
else
result << @strategy.nofunc_text(revert_replace_fence(words.shift))
end
break if words.empty?
result << compile_inline(revert_replace_fence(words.shift.gsub(/\\\}/, '}').gsub(/\\\\/, '\\')))
end
result
rescue => e
error e.message
end
|