201 (CHAPTER, Keyword.THY_DECL) + (SESSION, Keyword.THY_DECL) + |
201 (CHAPTER, Keyword.THY_DECL) + (SESSION, Keyword.THY_DECL) + |
202 IN + DESCRIPTION + OPTIONS + THEORIES + FILES |
202 IN + DESCRIPTION + OPTIONS + THEORIES + FILES |
203 |
203 |
204 private object Parser extends Parse.Parser |
204 private object Parser extends Parse.Parser |
205 { |
205 { |
206 def entry(pos: Position.T): Parser[Entry] = chapter(pos) | session_entry(pos) |
206 val chapter: Parser[Chapter] = |
207 |
|
208 def chapter(pos: Position.T): Parser[Chapter] = |
|
209 { |
207 { |
210 val chapter_name = atom("chapter name", _.is_name) |
208 val chapter_name = atom("chapter name", _.is_name) |
211 |
209 |
212 command(CHAPTER) ~! chapter_name ^^ { case _ ~ a => Chapter(a) } |
210 command(CHAPTER) ~! chapter_name ^^ { case _ ~ a => Chapter(a) } |
213 } |
211 } |
214 |
212 |
215 def session_entry(pos: Position.T): Parser[Session_Entry] = |
213 val session_entry: Parser[Session_Entry] = |
216 { |
214 { |
217 val session_name = atom("session name", _.is_name) |
215 val session_name = atom("session name", _.is_name) |
218 |
216 |
219 val option = |
217 val option = |
220 name ~ opt(keyword("=") ~! name ^^ { case _ ~ x => x }) ^^ { case x ~ y => (x, y) } |
218 name ~ opt(keyword("=") ~! name ^^ { case _ ~ x => x }) ^^ { case x ~ y => (x, y) } |
232 (opt(session_name ~! keyword("+") ^^ { case x ~ _ => x }) ~ |
230 (opt(session_name ~! keyword("+") ^^ { case x ~ _ => x }) ~ |
233 ((keyword(DESCRIPTION) ~! text ^^ { case _ ~ x => x }) | success("")) ~ |
231 ((keyword(DESCRIPTION) ~! text ^^ { case _ ~ x => x }) | success("")) ~ |
234 ((keyword(OPTIONS) ~! options ^^ { case _ ~ x => x }) | success(Nil)) ~ |
232 ((keyword(OPTIONS) ~! options ^^ { case _ ~ x => x }) | success(Nil)) ~ |
235 rep1(theories) ~ |
233 rep1(theories) ~ |
236 ((keyword(FILES) ~! rep1(path) ^^ { case _ ~ x => x }) | success(Nil))))) ^^ |
234 ((keyword(FILES) ~! rep1(path) ^^ { case _ ~ x => x }) | success(Nil))))) ^^ |
237 { case _ ~ (a ~ b ~ c ~ (_ ~ (d ~ e ~ f ~ g ~ h))) => |
235 { case pos ~ (a ~ b ~ c ~ (_ ~ (d ~ e ~ f ~ g ~ h))) => |
238 Session_Entry(pos, a, b, c, d, e, f, g, h) } |
236 Session_Entry(pos, a, b, c, d, e, f, g, h) } |
239 } |
237 } |
240 |
238 |
241 def parse_entries(root: Path): List[(String, Session_Entry)] = |
239 def parse_entries(root: Path): List[(String, Session_Entry)] = |
242 { |
240 { |
243 val toks = root_syntax.scan(File.read(root)) |
241 val toks = root_syntax.scan(File.read(root)) |
244 |
242 |
245 parse_all(rep(entry(root.position)), Token.reader(toks, root.implode)) match { |
243 parse_all(rep(chapter | session_entry), Token.reader(toks, root.implode)) match { |
246 case Success(result, _) => |
244 case Success(result, _) => |
247 var chapter = chapter_default |
245 var chapter = chapter_default |
248 val entries = new mutable.ListBuffer[(String, Session_Entry)] |
246 val entries = new mutable.ListBuffer[(String, Session_Entry)] |
249 result.foreach { |
247 result.foreach { |
250 case Chapter(name) => chapter = name |
248 case Chapter(name) => chapter = name |