equal
deleted
inserted
replaced
8 |
8 |
9 package isabelle |
9 package isabelle |
10 |
10 |
11 |
11 |
12 import scala.util.matching.Regex |
12 import scala.util.matching.Regex |
13 import scala.util.parsing.combinator.Parsers |
13 import scala.util.parsing.combinator |
14 import scala.util.parsing.combinator.lexical.Scanners |
14 import scala.util.parsing.combinator.lexical.Scanners |
15 import scala.util.parsing.input.CharArrayReader.EofCh |
15 import scala.util.parsing.input.CharArrayReader.EofCh |
16 |
16 |
17 |
17 |
18 object JSON { |
18 object JSON { |
122 } |
122 } |
123 |
123 |
124 |
124 |
125 /* parser */ |
125 /* parser */ |
126 |
126 |
127 trait Parser extends Parsers { |
127 trait Parsers extends combinator.Parsers { |
128 type Elem = Token |
128 type Elem = Token |
129 |
129 |
130 def $$$(name: String): Parser[Token] = elem(name, _.is_keyword(name)) |
130 def $$$(name: String): Parser[Token] = elem(name, _.is_keyword(name)) |
131 def string: Parser[String] = elem("string", _.is_string) ^^ (_.text) |
131 def string: Parser[String] = elem("string", _.is_string) ^^ (_.text) |
132 def number: Parser[Double] = elem("number", _.is_number) ^^ (tok => tok.text.toDouble) |
132 def number: Parser[Double] = elem("number", _.is_number) ^^ (tok => tok.text.toDouble) |
150 case NoSuccess(_, next) => error("Malformed JSON input at " + next.pos) |
150 case NoSuccess(_, next) => error("Malformed JSON input at " + next.pos) |
151 } |
151 } |
152 } |
152 } |
153 } |
153 } |
154 |
154 |
155 object Parser extends Parser |
155 object Parsers extends Parsers |
156 |
156 |
157 |
157 |
158 /* standard format */ |
158 /* standard format */ |
159 |
159 |
160 def parse(s: S, strict: Boolean = true): T = Parser.parse(s, strict) |
160 def parse(s: S, strict: Boolean = true): T = Parsers.parse(s, strict) |
161 |
161 |
162 object Format { |
162 object Format { |
163 def unapply(s: S): Option[T] = |
163 def unapply(s: S): Option[T] = |
164 try { Some(parse(s, strict = false)) } |
164 try { Some(parse(s, strict = false)) } |
165 catch { case ERROR(_) => None } |
165 catch { case ERROR(_) => None } |