equal
deleted
inserted
replaced
67 def buffer(): mutable.ListBuffer[Document] = new mutable.ListBuffer[Document] |
67 def buffer(): mutable.ListBuffer[Document] = new mutable.ListBuffer[Document] |
68 |
68 |
69 var stack: List[(Command, mutable.ListBuffer[Document])] = |
69 var stack: List[(Command, mutable.ListBuffer[Document])] = |
70 List((Command.empty, buffer())) |
70 List((Command.empty, buffer())) |
71 |
71 |
72 def open(command: Command) { stack = (command, buffer()) :: stack } |
72 def open(command: Command): Unit = { stack = (command, buffer()) :: stack } |
73 |
73 |
74 def close(): Boolean = |
74 def close(): Boolean = |
75 stack match { |
75 stack match { |
76 case (command, body) :: (_, body2) :: _ => |
76 case (command, body) :: (_, body2) :: _ => |
77 body2 += Block(command.span.name, command.source, body.toList) |
77 body2 += Block(command.span.name, command.source, body.toList) |
79 true |
79 true |
80 case _ => |
80 case _ => |
81 false |
81 false |
82 } |
82 } |
83 |
83 |
84 def flush() { if (is_plain_theory(stack.head._1)) close() } |
84 def flush(): Unit = if (is_plain_theory(stack.head._1)) close() |
85 |
85 |
86 def result(): List[Document] = |
86 def result(): List[Document] = |
87 { |
87 { |
88 while (close()) { } |
88 while (close()) { } |
89 stack.head._2.toList |
89 stack.head._2.toList |
90 } |
90 } |
91 |
91 |
92 def add(command: Command) |
92 def add(command: Command): Unit = |
93 { |
93 { |
94 if (command.span.is_begin || is_plain_theory(command)) { flush(); open(command) } |
94 if (command.span.is_begin || is_plain_theory(command)) { flush(); open(command) } |
95 else if (command.span.is_end) { flush(); close() } |
95 else if (command.span.is_end) { flush(); close() } |
96 |
96 |
97 stack.head._2 += Atom(command.source.length) |
97 stack.head._2 += Atom(command.source.length) |
123 private def buffer(): mutable.ListBuffer[Document] = new mutable.ListBuffer[Document] |
123 private def buffer(): mutable.ListBuffer[Document] = new mutable.ListBuffer[Document] |
124 |
124 |
125 private var stack: List[(Int, Item, mutable.ListBuffer[Document])] = |
125 private var stack: List[(Int, Item, mutable.ListBuffer[Document])] = |
126 List((0, No_Item, buffer())) |
126 List((0, No_Item, buffer())) |
127 |
127 |
128 @tailrec private def close(level: Int => Boolean) |
128 @tailrec private def close(level: Int => Boolean): Unit = |
129 { |
129 { |
130 stack match { |
130 stack match { |
131 case (lev, item, body) :: (_, _, body2) :: _ if level(lev) => |
131 case (lev, item, body) :: (_, _, body2) :: _ if level(lev) => |
132 body2 += Block(item.name, item.source, body.toList) |
132 body2 += Block(item.name, item.source, body.toList) |
133 stack = stack.tail |
133 stack = stack.tail |
140 { |
140 { |
141 close(_ => true) |
141 close(_ => true) |
142 stack.head._3.toList |
142 stack.head._3.toList |
143 } |
143 } |
144 |
144 |
145 def add(item: Item) |
145 def add(item: Item): Unit = |
146 { |
146 { |
147 item.heading_level match { |
147 item.heading_level match { |
148 case Some(i) => |
148 case Some(i) => |
149 close(_ > i) |
149 close(_ > i) |
150 stack = (i + 1, item, buffer()) :: stack |
150 stack = (i + 1, item, buffer()) :: stack |