Mercurial > hg > Members > kono > PLparser
changeset 6:563bcb96e4fa
pretty printer
author | one |
---|---|
date | Mon, 30 Aug 2010 12:35:23 +0900 |
parents | 29b5497fc942 |
children | 619472ca4742 |
files | src/plparser/ArrayProperty.java src/plparser/BooleanProperty.java src/plparser/DictProperty.java src/plparser/NumberNode.java src/plparser/Property.java src/plparser/PropertyListParser.java src/plparser/PropertyListScanner.java src/plparser/TestParser1.java |
diffstat | 8 files changed, 68 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plparser/ArrayProperty.java Sun Aug 29 20:28:00 2010 +0900 +++ b/src/plparser/ArrayProperty.java Mon Aug 30 12:35:23 2010 +0900 @@ -1,5 +1,6 @@ package plparser; +import java.io.PrintStream; import java.util.LinkedList; public class ArrayProperty extends Property { @@ -19,5 +20,19 @@ s += ")"; return s; } + + public void pp(PrintStream out, int indent, int flag) { + indent(out, indent,flag); + out.print("Array("); + flag = 0; + for(int i = 0;i<list.size();i++) { + list.get(i).pp(out,indent+indent_step,flag); flag = 1; + if (i<list.size()-1) out.println(","); + else { + if (list.size()>1) indent(out,indent,1); + out.print(")"); + } + } + } }
--- a/src/plparser/BooleanProperty.java Sun Aug 29 20:28:00 2010 +0900 +++ b/src/plparser/BooleanProperty.java Mon Aug 30 12:35:23 2010 +0900 @@ -1,5 +1,7 @@ package plparser; +import java.io.PrintStream; + public class BooleanProperty extends Property { boolean b; @@ -8,8 +10,12 @@ } public String toString() { - return b?"True":"Fasel"; + return b?"True":"False"; } + public void pp(PrintStream out, int indent,int flag) { + indent(out, indent,flag); + out.print(toString()); + } }
--- a/src/plparser/DictProperty.java Sun Aug 29 20:28:00 2010 +0900 +++ b/src/plparser/DictProperty.java Mon Aug 30 12:35:23 2010 +0900 @@ -1,7 +1,9 @@ package plparser; +import java.io.PrintStream; import java.util.HashMap; import java.util.LinkedList; +import java.util.Set; public class DictProperty extends Property { HashMap<Property, Property> map; @@ -28,4 +30,21 @@ return s; } + public void pp(PrintStream out, int indent,int flag) { + indent(out, indent,flag); out.print("Dict{"); + int i = 0; int size = map.size(); + flag = 0; + for(Property p:map.keySet()) { + p.pp(out,indent+indent_step,flag);out.print("->"); + flag = 1; + map.get(p).pp(out,indent+indent_step+2,0); + if (i<size-1) out.println(","); + else { + if (size>1) indent(out,indent,1); + out.print("}"); + } + i++; + } + } + }
--- a/src/plparser/NumberNode.java Sun Aug 29 20:28:00 2010 +0900 +++ b/src/plparser/NumberNode.java Mon Aug 30 12:35:23 2010 +0900 @@ -1,14 +1,14 @@ package plparser; public class NumberNode extends Property { - int value; + double value; - public NumberNode(int i) { + public NumberNode(double i) { value = i; } public String toString() { return "Number "+value; } - + }
--- a/src/plparser/Property.java Sun Aug 29 20:28:00 2010 +0900 +++ b/src/plparser/Property.java Mon Aug 30 12:35:23 2010 +0900 @@ -1,7 +1,10 @@ package plparser; +import java.io.PrintStream; + public class Property { String name; + public static int indent_step = 4; public Property() { @@ -15,4 +18,15 @@ return name; } + public void indent(PrintStream out, int indent,int flag) { + if (flag==0) return; + for(int i=0;i<indent;i++) + out.print(' '); + } + + public void pp(PrintStream out, int i,int flag) { + indent(out,i,flag); + out.print(toString()); + } + }
--- a/src/plparser/PropertyListParser.java Sun Aug 29 20:28:00 2010 +0900 +++ b/src/plparser/PropertyListParser.java Mon Aug 30 12:35:23 2010 +0900 @@ -36,6 +36,8 @@ dict.reserve("}",TokenID.CloseCurParen); dict.reserve("true",TokenID.True); dict.reserve("false",TokenID.False); + dict.reserve("True",TokenID.True); + dict.reserve("False",TokenID.False); } public void initialize() {
--- a/src/plparser/PropertyListScanner.java Sun Aug 29 20:28:00 2010 +0900 +++ b/src/plparser/PropertyListScanner.java Mon Aug 30 12:35:23 2010 +0900 @@ -180,8 +180,11 @@ } if (match) { // This won't work in Java 6 - // s = scan.group(1); - s = cb.toString().substring(scan.start(1),scan.end(1)); + //if (true) { + s = scan.group(1); + //} else { + // s = cb.toString().substring(scan.start(1),scan.end(1)); + //} // fix position in CharBuffer // scan.end() is relative position cb.position(cb.position()+scan.end());
--- a/src/plparser/TestParser1.java Sun Aug 29 20:28:00 2010 +0900 +++ b/src/plparser/TestParser1.java Mon Aug 30 12:35:23 2010 +0900 @@ -14,7 +14,9 @@ } for(String file: arg) { n = p.parseFile(file); - if (n!=null) System.out.print(n); System.out.println("."); + // if (n!=null) System.out.print(n); System.out.println("."); + if (n!=null) n.pp(System.out,0,0); + System.out.println("."); } } }