equal
deleted
inserted
replaced
9 |
9 |
10 import scala.collection.mutable |
10 import scala.collection.mutable |
11 import scala.util.parsing.input.CharSequenceReader |
11 import scala.util.parsing.input.CharSequenceReader |
12 |
12 |
13 |
13 |
14 object Command_Span |
14 object Command_Span { |
15 { |
|
16 /* loaded files */ |
15 /* loaded files */ |
17 |
16 |
18 object Loaded_Files |
17 object Loaded_Files { |
19 { |
|
20 val none: Loaded_Files = Loaded_Files(Nil, -1) |
18 val none: Loaded_Files = Loaded_Files(Nil, -1) |
21 } |
19 } |
22 sealed case class Loaded_Files(files: List[String], index: Int) |
20 sealed case class Loaded_Files(files: List[String], index: Int) |
23 |
21 |
24 abstract class Load_Command(val name: String, val here: Scala_Project.Here) |
22 abstract class Load_Command(val name: String, val here: Scala_Project.Here) |
25 extends Isabelle_System.Service |
23 extends Isabelle_System.Service { |
26 { |
|
27 override def toString: String = name |
24 override def toString: String = name |
28 |
25 |
29 def position: Position.T = here.position |
26 def position: Position.T = here.position |
30 |
27 |
31 def extensions: List[String] = Nil |
28 def extensions: List[String] = Nil |
64 case object Theory_Span extends Kind |
61 case object Theory_Span extends Kind |
65 |
62 |
66 |
63 |
67 /* span */ |
64 /* span */ |
68 |
65 |
69 sealed case class Span(kind: Kind, content: List[Token]) |
66 sealed case class Span(kind: Kind, content: List[Token]) { |
70 { |
|
71 def is_theory: Boolean = kind == Theory_Span |
67 def is_theory: Boolean = kind == Theory_Span |
72 |
68 |
73 def name: String = |
69 def name: String = |
74 kind match { case k: Command_Span => k.name case _ => "" } |
70 kind match { case k: Command_Span => k.name case _ => "" } |
75 |
71 |
94 |
90 |
95 def content_reader: CharSequenceReader = Scan.char_reader(Token.implode(content)) |
91 def content_reader: CharSequenceReader = Scan.char_reader(Token.implode(content)) |
96 |
92 |
97 def length: Int = content.foldLeft(0)(_ + _.source.length) |
93 def length: Int = content.foldLeft(0)(_ + _.source.length) |
98 |
94 |
99 def compact_source: (String, Span) = |
95 def compact_source: (String, Span) = { |
100 { |
|
101 val source = Token.implode(content) |
96 val source = Token.implode(content) |
102 val content1 = new mutable.ListBuffer[Token] |
97 val content1 = new mutable.ListBuffer[Token] |
103 var i = 0 |
98 var i = 0 |
104 for (Token(kind, s) <- content) { |
99 for (Token(kind, s) <- content) { |
105 val n = s.length |
100 val n = s.length |
108 i += n |
103 i += n |
109 } |
104 } |
110 (source, Span(kind, content1.toList)) |
105 (source, Span(kind, content1.toList)) |
111 } |
106 } |
112 |
107 |
113 def clean_arguments: List[(Token, Int)] = |
108 def clean_arguments: List[(Token, Int)] = { |
114 { |
|
115 if (name.nonEmpty) { |
109 if (name.nonEmpty) { |
116 def clean(toks: List[(Token, Int)]): List[(Token, Int)] = |
110 def clean(toks: List[(Token, Int)]): List[(Token, Int)] = |
117 toks match { |
111 toks match { |
118 case (t1, i1) :: (t2, i2) :: rest => |
112 case (t1, i1) :: (t2, i2) :: rest => |
119 if (t1.is_keyword && t1.source == "%" && t2.is_name) clean(rest) |
113 if (t1.is_keyword && t1.source == "%" && t2.is_name) clean(rest) |
141 } |
135 } |
142 } |
136 } |
143 |
137 |
144 val empty: Span = Span(Ignored_Span, Nil) |
138 val empty: Span = Span(Ignored_Span, Nil) |
145 |
139 |
146 def unparsed(source: String, theory: Boolean): Span = |
140 def unparsed(source: String, theory: Boolean): Span = { |
147 { |
|
148 val kind = if (theory) Theory_Span else Malformed_Span |
141 val kind = if (theory) Theory_Span else Malformed_Span |
149 Span(kind, List(Token(Token.Kind.UNPARSED, source))) |
142 Span(kind, List(Token(Token.Kind.UNPARSED, source))) |
150 } |
143 } |
151 } |
144 } |