Class: ReVIEW::Compiler
Defined Under Namespace
Classes: InlineSyntaxElement, SyntaxElement
Constant Summary
collapse
- SYNTAX =
{}
- INLINE =
{}
Instance Attribute Summary collapse
Class Method Summary
collapse
-
.defblock(name, argc, optional = false, &block) ⇒ Object
-
.definline(name) ⇒ Object
-
.defminicolumn(name, argc, _optional = false, &block) ⇒ Object
-
.defsingle(name, argc, &block) ⇒ Object
-
.defsyntax(name, type, argc, &block) ⇒ Object
-
.minicolumn_names ⇒ Object
Instance Method Summary
collapse
Constructor Details
#initialize(builder) ⇒ 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(builder)
@builder = builder
@non_parsed_commands = i[embed texequation graph]
@command_name_stack = []
end
|
Instance Attribute Details
Returns the value of attribute builder.
27
28
29
|
# File 'lib/review/compiler.rb', line 27
def builder
@builder
end
|
#previous_list_type ⇒ Object
Returns the value of attribute previous_list_type.
27
28
29
|
# File 'lib/review/compiler.rb', line 27
def previous_list_type
@previous_list_type
end
|
Class Method Details
.defblock(name, argc, optional = false, &block) ⇒ Object
91
92
93
|
# File 'lib/review/compiler.rb', line 91
def self.defblock(name, argc, optional = false, &block)
defsyntax(name, (optional ? :optional : :block), argc, &block)
end
|
.definline(name) ⇒ Object
107
108
109
|
# File 'lib/review/compiler.rb', line 107
def self.definline(name)
INLINE[name] = InlineSyntaxElement.new(name)
end
|
.defminicolumn(name, argc, _optional = false, &block) ⇒ Object
95
96
97
|
# File 'lib/review/compiler.rb', line 95
def self.defminicolumn(name, argc, _optional = false, &block)
defsyntax(name, :minicolumn, argc, &block)
end
|
.defsingle(name, argc, &block) ⇒ Object
99
100
101
|
# File 'lib/review/compiler.rb', line 99
def self.defsingle(name, argc, &block)
defsyntax(name, :line, argc, &block)
end
|
.defsyntax(name, type, argc, &block) ⇒ Object
103
104
105
|
# File 'lib/review/compiler.rb', line 103
def self.defsyntax(name, type, argc, &block)
SYNTAX[name] = SyntaxElement.new(name, type, argc, &block)
end
|
.minicolumn_names ⇒ Object
111
112
113
114
115
116
117
118
119
|
# File 'lib/review/compiler.rb', line 111
def self.minicolumn_names
buf = []
SYNTAX.each do |name, syntax|
if syntax.minicolumn?
buf << name.to_s
end
end
buf
end
|
Instance Method Details
#compile(chap) ⇒ Object
42
43
44
45
46
|
# File 'lib/review/compiler.rb', line 42
def compile(chap)
@chapter = chap
do_compile
@builder.result
end
|
#inline_defined?(name) ⇒ Boolean
139
140
141
|
# File 'lib/review/compiler.rb', line 139
def inline_defined?(name)
INLINE.key?(name.to_sym)
end
|
#non_escaped_commands ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/review/compiler.rb', line 34
def non_escaped_commands
if @builder.highlight?
i[list emlist listnum emlistnum cmd]
else
[]
end
end
|
29
30
31
32
|
# File 'lib/review/compiler.rb', line 29
def strategy
error 'Compiler#strategy is obsoleted. Use Compiler#builder.'
@builder
end
|
#syntax_defined?(name) ⇒ Boolean
121
122
123
|
# File 'lib/review/compiler.rb', line 121
def syntax_defined?(name)
SYNTAX.key?(name.to_sym)
end
|
#syntax_descriptor(name) ⇒ Object
125
126
127
|
# File 'lib/review/compiler.rb', line 125
def syntax_descriptor(name)
SYNTAX[name.to_sym]
end
|
#text(str, block_mode = false) ⇒ Object
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
|
# File 'lib/review/compiler.rb', line 638
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 << @builder.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
|