Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] rewriting ReVIEW::Compiler with kpeg #235

Open
wants to merge 248 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
248 commits
Select commit Hold shift + click to select a range
6684ac8
for debug
takahashim Feb 23, 2014
7594468
add task to compile kpeg
takahashim Feb 23, 2014
12a6c4a
remove unused methods in LineInput
takahashim Feb 23, 2014
10dac4a
use kpeg parser
takahashim Mar 1, 2014
43c2e2a
fix HTMLBuilder
takahashim Mar 1, 2014
bb69cd2
add literals_*.kpeg (for Ruby 1.8 and > 1.9)
takahashim Mar 1, 2014
0f9c460
escape in highlight()
takahashim Mar 1, 2014
4428945
fix some error
takahashim Mar 1, 2014
5a35b46
Revert "for debug"
takahashim Mar 1, 2014
4b38c03
fix HTMLBuilder and tests for HTMLBuilder
takahashim Mar 1, 2014
9dcf7fb
fix Builder
takahashim Mar 1, 2014
1b626f0
fix review.kpeg; escape in InlineElementContent
takahashim Mar 1, 2014
f5c4899
fix TOPBuilder and test for TOPBuilder
takahashim Mar 1, 2014
216755c
add test_helper method compile_headline
takahashim Mar 2, 2014
416c28d
fix escape; do escape only for Regexp pattern to avoid double escaping
takahashim Mar 2, 2014
9d1b4d8
fix highlight; do not escaping withoug highlighting
takahashim Mar 2, 2014
0604c46
Contents in BlockElement should be escaped
takahashim Mar 2, 2014
238a080
fix inline symtax
takahashim Mar 2, 2014
63b29ac
refactor BlockElementParagraph (remove instance variable)
takahashim Mar 2, 2014
df98767
fix some LATEXBuilder error (WIP)
takahashim Mar 2, 2014
e5a2ec2
fix I18n test
takahashim Mar 2, 2014
a578c11
fix inline syntax; parsing args should be done in compiler, not builders
takahashim Mar 2, 2014
5ea1697
fix compiler tests
takahashim Mar 2, 2014
8742a72
fix idgxmlbuilder
takahashim Mar 2, 2014
81cb9ea
fix inaobuilder
takahashim Mar 2, 2014
b1baa0d
fix tests of htmlbuilder; use copmile_inline instead of compile_href
takahashim Mar 2, 2014
a505040
fix tests for lineinput; remove unused methods
takahashim Mar 2, 2014
34e3ced
fix tests for markdownbuilder
takahashim Mar 2, 2014
01ffd13
remove unused method
takahashim Mar 2, 2014
927a2ac
fix test for builder; print/puts are not used, inline parsing is move…
takahashim Mar 2, 2014
7319a1d
fix # of args
takahashim Mar 3, 2014
c55e2a4
use Rules instead of Regexps
takahashim Mar 3, 2014
249d38f
use AST (ReVIEW::Node and subclasses)
takahashim Mar 4, 2014
3a7a5dd
remove unused code
takahashim Mar 4, 2014
3f100c1
kpeg don't use LineInput
takahashim Mar 4, 2014
71bbc17
fix failers
takahashim Mar 4, 2014
41a207b
//raw should not be use TextNode
takahashim Mar 4, 2014
d347f92
add AST(Node) class
takahashim Mar 4, 2014
331d8eb
fix inline
takahashim Mar 5, 2014
f06645f
Merge branch 'master' into kpeg
takahashim Jun 22, 2014
57a51fe
regenerate compiler.rb
takahashim Jun 23, 2014
1c2a01a
fix code and test(escaping, newline)
takahashim Jun 23, 2014
08b62e1
Merge branch 'master' into kpeg
takahashim Jul 3, 2014
249ce22
add InlineElementContentNode,fix Node#to_s
takahashim Jul 13, 2014
2de50cb
add Document, remove join
takahashim Jul 13, 2014
b0a9f01
add compile_block, fix compile_inline
takahashim Jul 13, 2014
7e73b02
fix test
takahashim Jul 13, 2014
2da8165
regenerate kpeg
takahashim Jul 13, 2014
959748b
use Node#to_doc instead of Node#to_s
takahashim Jul 13, 2014
b59a4c6
latexbuilder: fix newline
takahashim Jul 14, 2014
e0ae6e7
add Node#to_raw
takahashim Jul 14, 2014
e2790ed
fix RawNode#to_doc
takahashim Jul 14, 2014
1135ae0
add ast_inline_* to use raw text
takahashim Jul 14, 2014
6db7522
latexbuilder: fix test
takahashim Jul 14, 2014
6df93e5
regenerate kpeg
takahashim Jul 14, 2014
5932eda
add generated files
takahashim Jul 15, 2014
5b9b23f
remove non-used code
takahashim Jul 17, 2014
930c272
more fix
takahashim Jul 17, 2014
708b768
regenerate kpeg
takahashim Jul 17, 2014
daab0dd
add TaggedSectionNode
takahashim Jul 18, 2014
0d5a38e
add kpeg in development env
takahashim Jul 18, 2014
685e066
remove invalid line
takahashim Aug 15, 2014
45ba59e
add Builder#ast (@strategy.ast in Compiler)
takahashim Aug 15, 2014
0ff0760
fix @compiler.compile_headline; args is String, not AST
takahashim Aug 15, 2014
c0f535b
support node_* mehtods to use unescaped values
takahashim Aug 15, 2014
1253e72
ignore nil value in Node::to_doc
takahashim Aug 15, 2014
7c365b2
@label in HeadlineNode is not Node, but String
takahashim Aug 15, 2014
919384e
use node_inline_m and node_inline_idx; ignore inline_m and inline_idx
takahashim Aug 15, 2014
519d2c1
refactor Node class
takahashim Aug 15, 2014
0e298c4
Node#inspect as JSON
takahashim Aug 15, 2014
f1a84a7
not explode arg of Builder#node_inline_*
takahashim Aug 15, 2014
1b6953e
fix @<hd>; use node_inline_hd instead of inline_hd
takahashim Aug 15, 2014
bc65ac2
LATEXBuilder: fix and (too much?) simplify @<idx> and @<hidx>
takahashim Aug 15, 2014
d934865
refactoring
takahashim Aug 15, 2014
6d4d2d1
LATEXBuilder: fix @<idx> and @<hidx>
takahashim Aug 15, 2014
549118e
update ReVIEW::Compiler
takahashim Aug 15, 2014
bee5013
fix conflict
takahashim Aug 15, 2014
7d9aeac
HTMLBuilder: do not use puts and print
takahashim Aug 15, 2014
d953565
fix markdownbuilder
takahashim Aug 15, 2014
b94288d
MARKDOWNBuilder: add test
takahashim Aug 15, 2014
70f4d0e
Merge branch 'master' into kpeg
takahashim Aug 15, 2014
04e6f5b
HTMLBuilder: fix LF of bibpaper
takahashim Aug 15, 2014
ca603ab
support MARKDOWNBuilder
takahashim Aug 15, 2014
4648be1
TOPBuilder: fix LF
takahashim Aug 15, 2014
3dbe788
fix error
takahashim Aug 15, 2014
c37c261
merge commit 7c3384897795d94a05ab42b9777427c1ba5dc4d1
takahashim Aug 15, 2014
118d51d
add Node#to_json
takahashim Aug 15, 2014
5de538f
uncomment column test
takahashim Aug 16, 2014
0eb0899
support column
takahashim Aug 16, 2014
4bb92fb
LATEXBuilder: fix LF
takahashim Aug 16, 2014
23e16d6
regenerate
takahashim Aug 16, 2014
34f69fd
Builder: argument of inline_* is more ther one
takahashim Aug 17, 2014
3e7732d
Builder: "\n" in raw string should be LF
takahashim Aug 17, 2014
b2c6c9e
null BracketArg should be allowed
takahashim Aug 17, 2014
74d24e7
Revert "fix # of args"
takahashim Aug 17, 2014
8b05240
remove escaped quotation
takahashim Aug 17, 2014
10b1d21
compile_block should support multi blocks
takahashim Aug 19, 2014
630ba81
merge tests from master
takahashim Aug 19, 2014
2d058e9
regenerate
takahashim Aug 19, 2014
75ff551
merge master
takahashim Aug 24, 2014
420a331
move Array extensions: core_extensions -> review/extensions
takahashim Aug 25, 2014
508fe08
add argument of Node to compile_command, compile_block and compile_si…
takahashim Aug 26, 2014
b0407c1
LATEXBuilder: new handler for `//label` use Node, not converted text
takahashim Aug 26, 2014
a227a0f
add NEWLINE
takahashim Aug 26, 2014
d0875cd
remove unused newline
takahashim Aug 26, 2014
ae203c6
new LATEXBuilder remove unused extra NEWLINE
takahashim Aug 26, 2014
e77d370
Merge branch 'master' into kpeg
takahashim Aug 26, 2014
b49db58
remove extra newline
takahashim Aug 26, 2014
49b30af
LATEXBuilder: add newline at last of dd
takahashim Aug 26, 2014
ef8c1b8
regenarate
takahashim Aug 26, 2014
1cbbb51
LATEXBuilder: fix tests; remove extra newlines
takahashim Aug 26, 2014
e89049f
IDGXMLBuilder: add node_indepimage() instead of indepimage()
takahashim Aug 26, 2014
5c968d8
remove local var ast
takahashim Aug 26, 2014
f954c0e
add Node#parse_args
takahashim Aug 26, 2014
5350f28
use JSON gem for 1.8
takahashim Aug 26, 2014
aa108c4
support Ruby 1.8 :(
takahashim Aug 26, 2014
863d73d
fix order of libs
takahashim Aug 27, 2014
1deba6e
supress $stderr in test
takahashim Aug 27, 2014
325d549
add $KCODE into ReVIEW::Compiler to set Regexp UTF-8
takahashim Aug 27, 2014
1bbb236
regenerate
takahashim Aug 27, 2014
2b96f84
remove comment
takahashim Aug 27, 2014
8fbe005
move $KCODE to supress warning in 1.9
takahashim Aug 27, 2014
76bcfef
Revert "support Ruby 1.8 :("
takahashim Aug 27, 2014
dcc8314
add compat method of Enumerable#map in 1.8
takahashim Aug 27, 2014
9806558
remove unused methods
takahashim Aug 27, 2014
f11ed53
Merge branch 'master' into kpeg
takahashim Aug 27, 2014
8cd0cae
do not need compile_inline because content should have been already c…
takahashim Aug 30, 2014
d15bd28
add arguments for defsyntax; array to specify whether arguments need …
takahashim Aug 30, 2014
6019af4
Merge branch 'master' into kpeg
takahashim Aug 30, 2014
5c784ac
Merge branch 'master' into kpeg
takahashim Sep 3, 2014
e2e020b
merge master
takahashim Nov 9, 2014
160977a
remove require
takahashim Nov 9, 2014
d00f0d9
Merge branch 'master' into kpeg
takahashim Dec 9, 2014
e4b8136
merge master
takahashim Jan 22, 2015
03b0198
add kpeg
takahashim Jan 22, 2015
2d5fa04
fix tests; block has LF as terminator
takahashim Jan 22, 2015
71c6aa7
Merge branch 'master' into kpeg
takahashim Jan 22, 2015
85b4db8
Merge branch 'master' into kpeg
takahashim Jan 22, 2015
e96c7cc
no need to escape in inline_tag and block_tag
takahashim Jan 24, 2015
738be85
add nesting test
takahashim Jan 24, 2015
9871f5d
fix inline rules
takahashim Jan 24, 2015
12d8a06
kpeg: ContentInline should use NonInlineElement
takahashim Feb 11, 2015
87cfaf9
kpeg: simplify more
takahashim Feb 11, 2015
814b631
kpeg: add EOL( Newline or EOF)
takahashim Feb 11, 2015
16345ab
remove commentout
takahashim Feb 11, 2015
da43dcc
fix bug
takahashim Feb 11, 2015
dc47ba0
ContentInline and Inline should be same
takahashim Feb 11, 2015
6d0a8bb
kpeg: use Inline in BlockElementParagraph
takahashim Feb 11, 2015
6bf16c1
kpeg: Inline+ -> SinglelineContent
takahashim Feb 11, 2015
ae0f88d
kpeg: fix rule order
takahashim Feb 11, 2015
265ce5f
remove comment
takahashim Feb 11, 2015
1439bc1
kpeg: replace Newline -> BlankLine
takahashim Feb 12, 2015
f1f4da1
add NewLineNode
takahashim Feb 12, 2015
c977d01
remove split_paragraph and try to nest blocks
takahashim Feb 12, 2015
2958004
add CodeElementNode and defcodeblock
takahashim Feb 12, 2015
7445366
remove split_paragraph and use node_* methods
takahashim Feb 12, 2015
3ff11b9
fix other builders
takahashim Feb 12, 2015
88d5cf8
merge master
takahashim Feb 12, 2015
d11d5d5
revert node_* methods
takahashim Feb 12, 2015
d8db6c5
rename some symbols
takahashim Feb 13, 2015
c70b1de
fix some comments
takahashim Feb 13, 2015
c1daf78
fix Olist and Ulist; support Re:VIEW original syntax and markdown-lik…
takahashim Feb 14, 2015
3831f04
add comment
takahashim Feb 14, 2015
4ad4e03
fix dlist; use symbols instead of literals
takahashim Feb 15, 2015
ad658e4
remove split_paragraph
takahashim Feb 15, 2015
d028d0f
remove comments
takahashim Feb 15, 2015
719c0b6
remove tests for obsoleted methods print/puts
takahashim Feb 15, 2015
5f381c0
fix handling newline
takahashim Feb 15, 2015
5e3684c
add QuotedInlineText
takahashim Feb 15, 2015
d379d43
merge master
takahashim May 3, 2015
ec92a74
remove kpeg from Gemfile; added already in review.gemspec
takahashim May 3, 2015
eef76af
suport SinglelineComment in DListElement
takahashim May 3, 2015
8b16178
fix build error
takahashim May 3, 2015
a32a984
escape caption in @<hd>
takahashim May 3, 2015
928ba63
fix test: remove unused \n
takahashim May 3, 2015
d6f82da
JSON format of AST should be similar as that of review.js
takahashim May 3, 2015
4ac0348
avoid warning
takahashim May 3, 2015
392e1ee
Merge branch 'master' into kpeg
takahashim May 17, 2015
3203af2
Merge branch 'master' into kpeg
takahashim May 31, 2015
ae30fce
2.0.0.beta1
takahashim May 31, 2015
3d8a911
merged
takahashim Oct 2, 2015
a868e43
remove compile_inline()
takahashim Oct 2, 2015
194009c
merge master
takahashim Oct 17, 2015
40ebb2b
remove compile_inline
takahashim Oct 17, 2015
e9e64b8
Merge branch 'master' into kpeg
takahashim Oct 17, 2015
c8844f2
Merge branch 'master' into kpeg
takahashim Oct 17, 2015
033b570
fix rubocop warnings
takahashim Oct 17, 2015
a87451d
not support Ruby 1.8
takahashim Oct 17, 2015
6353b7e
generated ReVIEW::Compiler class is over 4000 lines... :(
takahashim Oct 17, 2015
c037f5b
Merge branch 'master' into kpeg
takahashim Oct 29, 2015
5dad64a
update version
takahashim Oct 29, 2015
2d72c0f
update gemspec for review-peg
takahashim Oct 30, 2015
e54be64
update version for review-peg
takahashim Oct 30, 2015
51f895a
add postfix "-peg"
takahashim Oct 31, 2015
af75378
remove rescue to debug easily
takahashim Oct 31, 2015
55ec89d
inline args should not be escaped
takahashim Oct 31, 2015
a5857a3
fix escaping arguments
takahashim Oct 31, 2015
c43eb12
update compiler
takahashim Oct 31, 2015
9efc04c
using part is not error
takahashim Oct 31, 2015
a4ea065
Revert "inline args should not be escaped"
takahashim Nov 1, 2015
f366b63
add postfix "-peg"
takahashim Nov 1, 2015
68d791a
fix lost argument
takahashim Nov 1, 2015
34a156c
add ComplexInlineElementNode
takahashim Nov 1, 2015
58a2a93
IDGXMLBuilder: remote escape_html
takahashim Nov 1, 2015
3006358
regenerate Compiler
takahashim Nov 1, 2015
4bf93f2
fix test; add definline directive
takahashim Nov 1, 2015
2a55128
HTMLBuilder: fix texequation
takahashim Nov 4, 2015
5168412
bump up
takahashim Nov 4, 2015
fbb98da
fix gem description
takahashim Nov 4, 2015
3d4a22e
fix invalid JSON generation
takahashim Nov 9, 2015
6b3156a
LATEXBuilder: //table should use AST
takahashim Nov 9, 2015
34082a4
bump up
takahashim Nov 9, 2015
78ed9a5
LATEXBuilder: id should not be escaped
takahashim Nov 10, 2015
b0549fd
bump up
takahashim Nov 10, 2015
267ffb7
fix @<img> and @<table> to unescape id
takahashim Nov 12, 2015
b68f1d8
perfomance tuning
takahashim Nov 12, 2015
97fbd5f
fix other inlines
takahashim Nov 12, 2015
c2fa9ee
remove compiler/literals_1_9.*
takahashim Nov 12, 2015
c6e4c1a
bump up
takahashim Nov 12, 2015
8855251
fix @<imgref>; use node_inline_imgref instead of inline_imgref
takahashim Nov 23, 2015
d32fafd
do not use super in node_*
takahashim Nov 23, 2015
2b39bc5
fix indent
takahashim Nov 23, 2015
f612bf0
support Ruby 1.9
takahashim Nov 23, 2015
93e3c1f
Merge pull request #466 from kmuto/inline_title
takahashim Nov 23, 2015
2ff543a
add "\n" before caption
takahashim Nov 23, 2015
a796166
fix test
takahashim Nov 23, 2015
3c1e100
Merge pull request #467 from kmuto/add-br-before-caption
takahashim Nov 23, 2015
eee67f5
fix caption of //list, //listnum
takahashim Nov 23, 2015
7d05bf4
Merge pull request #468 from kmuto/listcaption
takahashim Nov 23, 2015
08d5cf2
bump up
takahashim Nov 23, 2015
b254d15
do not escape content of footnote
takahashim Nov 23, 2015
c1ae972
Merge pull request #469 from kmuto/nonescape-footnote
takahashim Nov 23, 2015
cd14546
merge master
takahashim Nov 23, 2015
aff7574
bump up
takahashim Nov 23, 2015
88103d4
merged
takahashim Jan 24, 2016
bb47f4f
fix rubocop
takahashim Jan 24, 2016
d9841c8
merge master
takahashim Feb 7, 2016
0cd6254
fix test
takahashim Feb 7, 2016
d9b56d0
TOCParser: remove compile_inline
takahashim Feb 7, 2016
9ff4f6f
Merge branch 'master' into kpeg
takahashim Feb 14, 2016
03509ae
Merge branch 'master' into kpeg
takahashim Mar 20, 2016
a428dd4
fix tests
takahashim Mar 20, 2016
3b507b5
Merge branch 'master' into kpeg
takahashim Nov 9, 2016
baf8041
merge master
takahashim Nov 14, 2016
0ab5d7b
Merge branch 'master' into kpeg
takahashim Nov 15, 2016
a514b1d
delete duplicated definition
takahashim Nov 16, 2016
ffe89eb
review/compiler does not define module ReVIEW
takahashim Nov 16, 2016
0822bdd
suppress rubocop
takahashim Nov 16, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ AllCops:
Exclude:
- lib/lineinput.rb
- lib/uuid.rb
- lib/review/compiler.rb
DisplayCopNames: true

inherit_from: .rubocop_todo.yml
Expand Down Expand Up @@ -49,6 +50,10 @@ Style/OpMethod:
Style/VariableName:
Enabled: true

# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 4500

Style/ConditionalAssignment:
Enabled: false

Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in review.gemspec
gemspec

gem "json"
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'fileutils'

begin
require 'bundler'
Bundler::GemHelper.install_tasks
Expand All @@ -20,6 +22,11 @@ task :rubocop do
end
end

task :kpeg do
FileUtils.rm_f "lib/review/compiler.rb"
sh "kpeg -s lib/review/review.kpeg -o lib/review/compiler.rb"
end

Rake::TestTask.new("test") do |t|
t.libs << "test"
t.test_files = Dir.glob("test/**/test_*.rb")
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions bin/review-compile → bin/review-compile-peg
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _main
exit 1
end

begin
## begin
loader = ReVIEW::YAMLLoader.new
if config["yaml"]
config.deep_merge!(loader.load_file(config["yaml"]))
Expand Down Expand Up @@ -166,11 +166,11 @@ def _main
else
raise "must not happen: #{mode}"
end
rescue ReVIEW::ApplicationError => err
raise if $DEBUG
error err.message
exit 1
end
# rescue ReVIEW::ApplicationError => err
# raise if $DEBUG
# error err.message
# exit 1
# end
end

def error(msg)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
38 changes: 0 additions & 38 deletions lib/lineinput.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,36 +58,6 @@ def next?
peek() ? true : false
end

def skip_blank_lines
n = 0
while line = gets()
unless line.strip.empty?
ungets line
return n
end
n += 1
end
n
end

def gets_if(re)
line = gets()
if not line or not (re =~ line)
ungets line
return nil
end
line
end

def gets_unless(re)
line = gets()
if not line or re =~ line
ungets line
return nil
end
line
end

def each
while line = gets()
yield line
Expand Down Expand Up @@ -144,12 +114,4 @@ def until_terminator(re)
nil
end

def getblock(term_re)
buf = []
until_terminator(term_re) do |line|
buf.push line
end
buf
end

end
10 changes: 7 additions & 3 deletions lib/review/book/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,14 @@ def item_type
end

def number(id)
chapter = @index.fetch(id)
chapter.format_number
chapter = @index.fetch(id, nil)
if chapter
return chapter.format_number
else
return "#{I18n.t("part", chapter.number)}"
end
rescue # part
"#{I18n.t("part", chapter.number)}"
raise "invalid number error: id:#{id}, capter:#{chapter}"
end

def title(id)
Expand Down
106 changes: 62 additions & 44 deletions lib/review/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class Builder

CAPTION_TITLES = %w(note memo tip info warning important caution notice)

attr_accessor :output
attr_accessor :ast

def pre_paragraph
nil
end
Expand All @@ -43,6 +46,7 @@ def bind(compiler, chapter, location)
@compiler = compiler
@chapter = chapter
@location = location
@ast = nil
@output = StringIO.new
@book = @chapter.book if @chapter.present?
@tabwidth = nil
Expand All @@ -64,11 +68,11 @@ def result
alias_method :raw_result, :result

def print(*s)
@output.print(*s)
raise NotImplementedError, "XXX: `print` method is obsoleted. Do not use it."
end

def puts(*s)
@output.puts(*s)
raise NotImplementedError, "XXX: `puts` method is obsoleted. Do not use it."
end

def target_name
Expand All @@ -83,27 +87,33 @@ def headline_prefix(level)
end
private :headline_prefix

def list(lines, id, caption, lang = nil)
def list(lines, id, caption = nil, lang = nil)
buf = ""
begin
list_header id, caption, lang
buf << list_header(id, caption, lang)
rescue KeyError
error "no such list: #{id}"
end
list_body id, lines, lang
buf << list_body(id, lines, lang)
buf
end

def listnum(lines, id, caption, lang = nil)
def listnum(lines, id, caption = nil, lang = nil)
buf = ""
begin
list_header id, caption, lang
buf << list_header(id, caption, lang)
rescue KeyError
error "no such list: #{id}"
end
listnum_body lines, lang
buf << listnum_body(lines, lang)
buf
end

def source(lines, caption, lang = nil)
source_header caption
source_body lines, lang
def source(lines, caption = nil)
buf = ""
buf << source_header(caption)
buf << source_body(lines, lang)
buf
end

def image(lines, id, caption, metric = nil)
Expand All @@ -116,6 +126,7 @@ def image(lines, id, caption, metric = nil)
end

def table(lines, id = nil, caption = nil)
buf = ""
rows = []
sepidx = nil
lines.each_with_index do |line, idx|
Expand All @@ -130,26 +141,27 @@ def table(lines, id = nil, caption = nil)
rows = adjust_n_cols(rows)

begin
table_header id, caption unless caption.nil?
buf << table_header(id, caption) unless caption.nil?
rescue KeyError
error "no such table: #{id}"
end
return if rows.empty?
table_begin rows.first.size
return buf if rows.empty?
buf << table_begin(rows.first.size)
if sepidx
sepidx.times do
tr rows.shift.map {|s| th(s) }
buf << tr(rows.shift.map {|s| th(s) })
end
rows.each do |cols|
tr cols.map {|s| td(s) }
buf << tr(cols.map {|s| td(s) })
end
else
rows.each do |cols|
h, *cs = *cols
tr [th(h)] + cs.map {|s| td(s) }
buf << tr([th(h)] + cs.map {|s| td(s) })
end
end
table_end
buf << table_end
buf
end

def adjust_n_cols(rows)
Expand Down Expand Up @@ -178,12 +190,12 @@ def adjust_n_cols(rows)
# footnote_end
#end

def compile_inline(s)
@compiler.text(s)
end
# def compile_inline(s)
# @compiler.text(s)
# end

def inline_chapref(id)
compile_inline @book.chapter_index.display_string(id)
@book.chapter_index.display_string(id)
rescue KeyError
error "unknown chapter: #{id}"
nofunc_text("[UnknownChapter:#{id}]")
Expand All @@ -197,7 +209,7 @@ def inline_chap(id)
end

def inline_title(id)
compile_inline @book.chapter_index.title(id)
@book.chapter_index.title(id)
rescue KeyError
error "unknown chapter: #{id}"
nofunc_text("[UnknownChapter:#{id}]")
Expand All @@ -217,8 +229,14 @@ def inline_img(id)
nofunc_text("[UnknownImage:#{id}]")
end

def inline_imgref(id)
img = inline_img(id)
def node_inline_img(node)
id = node[0].to_raw
inline_img(id)
end

def node_inline_imgref(node)
id = node[0].to_raw
img = node_inline_img(node)

if @chapter.image(id).caption
"#{img}#{I18n.t('image_quote', @chapter.image(id).caption)}"
Expand All @@ -245,22 +263,17 @@ def inline_bou(str)
text(str)
end

def inline_ruby(arg)
base, *ruby = *arg.scan(/(?:(?:(?:\\\\)*\\,)|[^,\\]+)+/)
base = base.gsub(/\\,/, ",") if base
ruby = ruby.join(",").gsub(/\\,/, ",") if ruby
def inline_ruby(base, ruby)
compile_ruby(base, ruby)
end

def inline_kw(arg)
word, alt = *arg.split(',', 2)
def inline_kw(word, alt = nil)
compile_kw(word, alt)
end

def inline_href(arg)
url, label = *arg.scan(/(?:(?:(?:\\\\)*\\,)|[^,\\]+)+/).map(&:lstrip)
url = url.gsub(/\\,/, ",").strip
label = label.gsub(/\\,/, ",").strip if label
def inline_href(url, label = nil)
url = url.strip
label = label.strip if label
compile_href(url, label)
end

Expand All @@ -269,15 +282,18 @@ def text(str)
end

def bibpaper(lines, id, caption)
bibpaper_header id, caption
buf = ""
buf << bibpaper_header(id, caption)
unless lines.empty?
puts ""
bibpaper_bibpaper id, caption, lines
buf << "\n"
buf << bibpaper_bibpaper(id, caption, lines)
end
puts ""
buf << "\n"
buf
end

def inline_hd(id)
def node_inline_hd(nodelist)
id = nodelist[0].to_raw
m = /\A([^|]+)\|(.+)/.match(id)
if m && m[1]
chapter = @book.contents.detect{|chap| chap.id == m[1]}
Expand Down Expand Up @@ -318,12 +334,12 @@ def raw(str)
builders = matched[1].split(/,/).map{|i| i.gsub(/\s/, '') }
c = target_name
if builders.include?(c)
print matched[2].gsub("\\n", "\n")
matched[2].gsub("\\n", "\n")
else
""
end
else
print str.gsub("\\n", "\n")
str.gsub("\\n", "\n")
end
end

Expand All @@ -332,7 +348,7 @@ def warn(msg)
end

def error(msg)
raise ApplicationError, "#{@location}: error: #{msg}"
raise ApplicationError, "error: #{msg} at #{@compiler.show_pos} \n (#{@compiler.failure_oneline})"
end

def handle_metric(str)
Expand Down Expand Up @@ -418,8 +434,9 @@ def image_ext
raise NotImplementedError
end

### XXX
def inline_include(file_name)
compile_inline File.read(file_name)
File.read(file_name)
end

def include(file_name)
Expand All @@ -433,6 +450,7 @@ def ul_item_begin(lines)
end

def ul_item_end
""
end

def inline_raw(args)
Expand Down
Loading