32 /*delimited content*/ |
32 /*delimited content*/ |
33 val STRING = Value("string") |
33 val STRING = Value("string") |
34 val ALT_STRING = Value("back-quoted string") |
34 val ALT_STRING = Value("back-quoted string") |
35 val VERBATIM = Value("verbatim text") |
35 val VERBATIM = Value("verbatim text") |
36 val CARTOUCHE = Value("text cartouche") |
36 val CARTOUCHE = Value("text cartouche") |
37 val COMMENT = Value("comment text") |
37 val INFORMAL_COMMENT = Value("informal comment") |
|
38 val FORMAL_COMMENT = Value("formal comment") |
38 /*special content*/ |
39 /*special content*/ |
39 val ERROR = Value("bad input") |
40 val ERROR = Value("bad input") |
40 val UNPARSED = Value("unparsed input") |
41 val UNPARSED = Value("unparsed input") |
41 } |
42 } |
42 |
43 |
43 |
44 |
44 /* parsers */ |
45 /* parsers */ |
45 |
46 |
46 object Parsers extends Parsers |
47 object Parsers extends Parsers |
47 |
48 |
48 trait Parsers extends Scan.Parsers |
49 trait Parsers extends Scan.Parsers with Comment.Parsers |
49 { |
50 { |
|
51 private def comment_marker: Parser[Token] = |
|
52 one(Symbol.is_comment) ^^ (x => Token(Token.Kind.KEYWORD, x)) |
|
53 |
50 private def delimited_token: Parser[Token] = |
54 private def delimited_token: Parser[Token] = |
51 { |
55 { |
52 val string = quoted("\"") ^^ (x => Token(Token.Kind.STRING, x)) |
56 val string = quoted("\"") ^^ (x => Token(Token.Kind.STRING, x)) |
53 val alt_string = quoted("`") ^^ (x => Token(Token.Kind.ALT_STRING, x)) |
57 val alt_string = quoted("`") ^^ (x => Token(Token.Kind.ALT_STRING, x)) |
54 val verb = verbatim ^^ (x => Token(Token.Kind.VERBATIM, x)) |
58 val verb = verbatim ^^ (x => Token(Token.Kind.VERBATIM, x)) |
55 val cart = cartouche ^^ (x => Token(Token.Kind.CARTOUCHE, x)) |
59 val cart = cartouche ^^ (x => Token(Token.Kind.CARTOUCHE, x)) |
56 val cmt = comment ^^ (x => Token(Token.Kind.COMMENT, x)) |
60 val cmt = comment ^^ (x => Token(Token.Kind.INFORMAL_COMMENT, x)) |
57 |
61 val formal_cmt = comment_cartouche ^^ (x => Token(Token.Kind.FORMAL_COMMENT, x)) |
58 string | (alt_string | (verb | (cart | cmt))) |
62 |
|
63 string | (alt_string | (verb | (cart | (cmt | formal_cmt)))) |
59 } |
64 } |
60 |
65 |
61 private def other_token(keywords: Keyword.Keywords): Parser[Token] = |
66 private def other_token(keywords: Keyword.Keywords): Parser[Token] = |
62 { |
67 { |
63 val letdigs1 = many1(Symbol.is_letdig) |
68 val letdigs1 = many1(Symbol.is_letdig) |
104 (((ident | (var_ | (type_ident | (type_var | (float | (nat_ | sym_ident)))))) ||| |
109 (((ident | (var_ | (type_ident | (type_var | (float | (nat_ | sym_ident)))))) ||| |
105 keyword) | bad)) |
110 keyword) | bad)) |
106 } |
111 } |
107 |
112 |
108 def token(keywords: Keyword.Keywords): Parser[Token] = |
113 def token(keywords: Keyword.Keywords): Parser[Token] = |
109 delimited_token | other_token(keywords) |
114 comment_marker | (delimited_token | other_token(keywords)) |
110 |
115 |
111 def token_line(keywords: Keyword.Keywords, ctxt: Scan.Line_Context) |
116 def token_line(keywords: Keyword.Keywords, ctxt: Scan.Line_Context) |
112 : Parser[(Token, Scan.Line_Context)] = |
117 : Parser[(Token, Scan.Line_Context)] = |
113 { |
118 { |
114 val string = |
119 val string = |
115 quoted_line("\"", ctxt) ^^ { case (x, c) => (Token(Token.Kind.STRING, x), c) } |
120 quoted_line("\"", ctxt) ^^ { case (x, c) => (Token(Token.Kind.STRING, x), c) } |
116 val alt_string = |
121 val alt_string = |
117 quoted_line("`", ctxt) ^^ { case (x, c) => (Token(Token.Kind.ALT_STRING, x), c) } |
122 quoted_line("`", ctxt) ^^ { case (x, c) => (Token(Token.Kind.ALT_STRING, x), c) } |
118 val verb = verbatim_line(ctxt) ^^ { case (x, c) => (Token(Token.Kind.VERBATIM, x), c) } |
123 val verb = verbatim_line(ctxt) ^^ { case (x, c) => (Token(Token.Kind.VERBATIM, x), c) } |
119 val cart = cartouche_line(ctxt) ^^ { case (x, c) => (Token(Token.Kind.CARTOUCHE, x), c) } |
124 val cart = cartouche_line(ctxt) ^^ { case (x, c) => (Token(Token.Kind.CARTOUCHE, x), c) } |
120 val cmt = comment_line(ctxt) ^^ { case (x, c) => (Token(Token.Kind.COMMENT, x), c) } |
125 val cmt = comment_line(ctxt) ^^ { case (x, c) => (Token(Token.Kind.INFORMAL_COMMENT, x), c) } |
|
126 val formal_cmt = |
|
127 comment_cartouche_line(ctxt) ^^ { case (x, c) => (Token(Token.Kind.FORMAL_COMMENT, x), c) } |
121 val other = other_token(keywords) ^^ { case x => (x, Scan.Finished) } |
128 val other = other_token(keywords) ^^ { case x => (x, Scan.Finished) } |
122 |
129 |
123 string | (alt_string | (verb | (cart | (cmt | other)))) |
130 string | (alt_string | (verb | (cart | (cmt | (formal_cmt | other))))) |
124 } |
131 } |
125 } |
132 } |
126 |
133 |
127 |
134 |
128 /* explode */ |
135 /* explode */ |
285 kind == Token.Kind.VAR || |
292 kind == Token.Kind.VAR || |
286 kind == Token.Kind.TYPE_IDENT || |
293 kind == Token.Kind.TYPE_IDENT || |
287 kind == Token.Kind.TYPE_VAR |
294 kind == Token.Kind.TYPE_VAR |
288 def is_text: Boolean = is_embedded || kind == Token.Kind.VERBATIM |
295 def is_text: Boolean = is_embedded || kind == Token.Kind.VERBATIM |
289 def is_space: Boolean = kind == Token.Kind.SPACE |
296 def is_space: Boolean = kind == Token.Kind.SPACE |
290 def is_comment: Boolean = kind == Token.Kind.COMMENT |
297 def is_comment: Boolean = kind == Token.Kind.INFORMAL_COMMENT || kind == Token.Kind.FORMAL_COMMENT |
291 def is_improper: Boolean = is_space || is_comment |
298 def is_improper: Boolean = is_space || is_comment |
292 def is_proper: Boolean = !is_space && !is_comment |
299 def is_proper: Boolean = !is_space && !is_comment |
293 def is_error: Boolean = kind == Token.Kind.ERROR |
300 def is_error: Boolean = kind == Token.Kind.ERROR |
294 def is_unparsed: Boolean = kind == Token.Kind.UNPARSED |
301 def is_unparsed: Boolean = kind == Token.Kind.UNPARSED |
295 |
302 |
311 def content: String = |
318 def content: String = |
312 if (kind == Token.Kind.STRING) Scan.Parsers.quoted_content("\"", source) |
319 if (kind == Token.Kind.STRING) Scan.Parsers.quoted_content("\"", source) |
313 else if (kind == Token.Kind.ALT_STRING) Scan.Parsers.quoted_content("`", source) |
320 else if (kind == Token.Kind.ALT_STRING) Scan.Parsers.quoted_content("`", source) |
314 else if (kind == Token.Kind.VERBATIM) Scan.Parsers.verbatim_content(source) |
321 else if (kind == Token.Kind.VERBATIM) Scan.Parsers.verbatim_content(source) |
315 else if (kind == Token.Kind.CARTOUCHE) Scan.Parsers.cartouche_content(source) |
322 else if (kind == Token.Kind.CARTOUCHE) Scan.Parsers.cartouche_content(source) |
316 else if (kind == Token.Kind.COMMENT) Scan.Parsers.comment_content(source) |
323 else if (kind == Token.Kind.INFORMAL_COMMENT) Scan.Parsers.comment_content(source) |
|
324 else if (kind == Token.Kind.FORMAL_COMMENT) Comment.content(source) |
317 else source |
325 else source |
318 |
326 |
319 def is_system_name: Boolean = |
327 def is_system_name: Boolean = |
320 { |
328 { |
321 val s = content |
329 val s = content |