X-Git-Url: http://nitlanguage.org diff --git a/src/test_parser.nit b/src/test_parser.nit index 89682cc..fa95f13 100644 --- a/src/test_parser.nit +++ b/src/test_parser.nit @@ -19,28 +19,14 @@ module test_parser import parser import parser_util - -class PrintTreeVisitor - super Visitor - private var rank: Int = 0 - redef fun visit(n) - do - if n isa Token then - printn(" " * rank, n.class_name, " \"", n.text.escape_to_c, "\" ", n.location, "\n") - else - printn(" " * rank, n.class_name, " ", n.location, "\n") - end - rank = rank + 1 - n.visit_all(self) - rank = rank - 1 - end -end +import astutil var no_print = false var only_lexer = false var need_help = false var no_file = false var interactive = false +var xml = false while not args.is_empty and args.first.chars.first == '-' do if args.first == "-n" then @@ -49,6 +35,8 @@ while not args.is_empty and args.first.chars.first == '-' do only_lexer = true else if args.first == "-p" then only_lexer = false + else if args.first == "-x" then + xml = true else if args.first == "-e" then no_file = true else if args.first == "-i" then @@ -71,15 +59,16 @@ if (args.is_empty and not interactive) or need_help then print(" -n do not print anything") print(" -l only lexer") print(" -p lexer and parser (default)") + print(" -x instead of a ascii tree, output a XML document") print(" -e instead on files, each argument is a content to parse") print(" -i tree to parse are read interactively") print(" -h print this help") else if interactive then if only_lexer then - print "Error: -l and -i are incompatibles" + print "Error: -l and -i are incompatible" exit 1 else if no_file then - print "Error: -e and -i are incompatibles" + print "Error: -e and -i are incompatible" exit 1 else if not args.is_empty then print "Error: -i works without arguments" @@ -106,7 +95,7 @@ else if interactive then end if not no_print then - (new PrintTreeVisitor).enter_visit(n) + n.dump_tree end end else @@ -138,8 +127,11 @@ else return end - if not no_print then - (new PrintTreeVisitor).enter_visit(tree) + if xml then + tree.parentize_tokens + tree.to_xml.write_to(stdout) + else if not no_print then + tree.dump_tree end end end