Index: trunk/tools/commonist-java/doc/changes-minibpp.txt |
— | — | @@ -2,4 +2,4 @@ |
3 | 3 | added A.class and A.bsh for use with useModule.bsh |
4 | 4 | |
5 | 5 | 0.0.1 |
6 | | - initial release |
\ No newline at end of file |
| 6 | + initial release |
Index: trunk/tools/commonist-java/doc/changes-libutil.txt |
— | — | @@ -13,4 +13,4 @@ |
14 | 14 | added AppleQuit support class |
15 | 15 | |
16 | 16 | 0.0.1 |
17 | | - initial release |
\ No newline at end of file |
| 17 | + initial release |
Index: trunk/tools/commonist-java/src/net/psammead/functional/README |
— | — | @@ -0,0 +1,2 @@ |
| 2 | +This package (net.psammead.functional) is licensed under LGPL |
| 3 | + |
Index: trunk/tools/commonist-java/src/net/psammead/mwapi/README |
— | — | @@ -0,0 +1,2 @@ |
| 2 | +This package (net.psammead.mwapi) is licensed under LGPL |
| 3 | + |
Index: trunk/tools/commonist-java/src/net/psammead/util/README |
— | — | @@ -0,0 +1,2 @@ |
| 2 | +This package (net.psammead.util) is licensed under LGPL |
| 3 | + |
Index: trunk/tools/commonist-java/src/net/psammead/minibpp/README |
— | — | @@ -0,0 +1,2 @@ |
| 2 | +This package (net.psammead.minibpp) is licensed under LGPL |
| 3 | + |
Index: trunk/tools/commonist-java/build.properties |
— | — | @@ -32,7 +32,7 @@ |
33 | 33 | |
34 | 34 | # webstart |
35 | 35 | ws.jnlp=commonist.jnlp |
36 | | -ws.codebase=http://toolserver.org/~saper/commonist/ws/ |
| 36 | +ws.codebase=http://toolserver.org/~saper/commonist/3/ |
37 | 37 | ws.mainclass=net.psammead.commonist.Commonist |
38 | 38 | ws.homepage=http://commons.wikimedia.org/wiki/Commons:Tools/Commonist |
39 | 39 | ws.title=The Commonist |
— | — | @@ -47,7 +47,7 @@ |
48 | 48 | #sign.dname=CN=... |
49 | 49 | |
50 | 50 | # keystore |
51 | | -sign.keystore=etc/keyStore |
| 51 | +#sign.keystore=etc/keyStore |
52 | 52 | #sign.keypass=*somepassword* |
53 | 53 | |
54 | 54 | # signing key |
Index: trunk/tools/commonist-java/build.xml |
— | — | @@ -28,6 +28,11 @@ |
29 | 29 | <patternset refid="runtime.jars" /> |
30 | 30 | <include name="${project}.jar" /> |
31 | 31 | </patternset> |
| 32 | + |
| 33 | + <path id="build.classpath"> |
| 34 | + <pathelement location="build/classes" /> |
| 35 | + <fileset refid="compile.libraries" /> |
| 36 | + </path> |
32 | 37 | |
33 | 38 | <!-- ==== main ==== --> |
34 | 39 | |
— | — | @@ -56,7 +61,7 @@ |
57 | 62 | target="${java.target}" |
58 | 63 | encoding="${java.encoding}" |
59 | 64 | deprecation="true" |
60 | | - extdirs="lib" |
| 65 | + classpathref="build.classpath" |
61 | 66 | debug="true"> |
62 | 67 | <src path="src" /> |
63 | 68 | <src path="build/src" /> |
— | — | @@ -112,6 +117,9 @@ |
113 | 118 | <zipfileset dir="." prefix="${project}-${version}"> |
114 | 119 | <include name="doc/index.html"/> |
115 | 120 | <include name="doc/changes.txt"/> |
| 121 | + <include name="doc/changes-libutil.txt"/> |
| 122 | + <include name="doc/changes-minibpp.txt"/> |
| 123 | + <include name="doc/changes-mwlib.txt"/> |
116 | 124 | <include name="src/**"/> |
117 | 125 | <include name="etc/**"/> |
118 | 126 | <exclude name="${sign.keystore}"/> |
Index: trunk/tools/commonist/build.xml |
— | — | @@ -28,15 +28,42 @@ |
29 | 29 | <pathelement location="${scala.compiler}"/> |
30 | 30 | </path> |
31 | 31 | |
| 32 | + <path id="scala.source.dirs"> |
| 33 | + <pathelement location="src/scala" /> |
| 34 | + </path> |
| 35 | + |
| 36 | + <path id="java.source.dirs"> |
| 37 | + <pathelement location="src" /> |
| 38 | + <pathelement location="build/src" /> |
| 39 | + </path> |
| 40 | + |
| 41 | + <fileset id="runtime.libraries" dir="lib"> |
| 42 | + <patternset id="runtime.jars"> |
| 43 | + <include name="bsh-2.0b2-fixed.jar" /> |
| 44 | + <include name="commons-httpclient-3.1.jar" /> |
| 45 | + <include name="commons-codec-1.3.jar" /> |
| 46 | + <include name="commons-logging-1.1.jar" /> |
| 47 | + <include name="sanselan-0.97-incubator.jar" /> |
| 48 | + <include name="scala-library.jar" /> |
| 49 | + </patternset> |
| 50 | + </fileset> |
| 51 | + |
| 52 | + <fileset id="compile.libraries" dir="lib"> |
| 53 | + <patternset refid="runtime.jars" /> |
| 54 | + <include name="javacc.jar" /> |
| 55 | + </fileset> |
| 56 | + |
| 57 | + <patternset id="product.jars"> |
| 58 | + <patternset refid="runtime.jars" /> |
| 59 | + <include name="${project}.jar" /> |
| 60 | + </patternset> |
| 61 | + |
32 | 62 | <path id="build.classpath"> |
33 | 63 | <pathelement location="${scala.library}"/> |
34 | | - <fileset dir="lib"/> |
| 64 | + <pathelement location="build/classes" /> |
| 65 | + <fileset refid="compile.libraries" /> |
35 | 66 | </path> |
36 | | - |
37 | | - <!-- project specifics --> |
38 | | - <property name="source.jars" value="minibpp-src.jar"/> |
39 | | - <property name="binary.jars" value="scala-library.jar,bsh-2.0b2-fixed.jar,minibpp.jar,sanselan-0.97-incubator.jar,commons-httpclient-3.1.jar,commons-codec-1.3.jar,commons-logging-1.1.jar"/> |
40 | | - |
| 67 | + |
41 | 68 | <!-- ==== main ==== --> |
42 | 69 | |
43 | 70 | <target name="clean" description="deletes everything that can be rebuilt"> |
— | — | @@ -55,19 +82,39 @@ |
56 | 83 | </replace> |
57 | 84 | </target> |
58 | 85 | --> |
| 86 | + |
| 87 | + <target name="parser" description="create the parser sources"> |
| 88 | + <mkdir dir="build/src/net/psammead/minibpp/parser"/> |
| 89 | + <javacc |
| 90 | + target="src/net/psammead/minibpp/Parser.jj" |
| 91 | + outputdirectory="build/src/net/psammead/minibpp/parser" |
| 92 | + javacchome="lib" |
| 93 | + unicodeinput="true" |
| 94 | + static="false" |
| 95 | + /> |
| 96 | + </target> |
59 | 97 | |
60 | | - <target name="compile" description="compiles scala classes"> |
| 98 | + <target name="compile" depends="parser" description="compiles scala classes"> |
61 | 99 | <mkdir dir="build/classes"/> |
| 100 | + <javac |
| 101 | + destdir="build/classes" |
| 102 | + source="${java.source}" |
| 103 | + target="${java.target}" |
| 104 | + encoding="${java.encoding}" |
| 105 | + deprecation="true" |
| 106 | + classpathref="build.classpath" |
| 107 | + debug="true"> |
| 108 | + <src refid="java.source.dirs" /> |
| 109 | + <include name="**/*.java" /> |
| 110 | + </javac> |
62 | 111 | <scalac |
63 | | - srcdir="src/scala" |
64 | 112 | destdir="build/classes" |
65 | 113 | encoding="${scala.encoding}" |
66 | 114 | classpathref="build.classpath" |
67 | 115 | deprecation="yes" |
68 | | - unchecked="yes" |
69 | | - > |
70 | | - <!-- addparams --> |
71 | | - <include name="**/*.scala"/> |
| 116 | + unchecked="yes"> |
| 117 | + <src refid="scala.source.dirs" /> |
| 118 | + <include name="**/*.scala" /> |
72 | 119 | </scalac> |
73 | 120 | </target> |
74 | 121 | |
— | — | @@ -92,10 +139,8 @@ |
93 | 140 | <attribute name="Creator" value="${author}"/> |
94 | 141 | <attribute name="License" value="${license}"/> |
95 | 142 | |
96 | | - <!-- |
97 | | - TODO: use a property, add binary.jars to classpath (manifestclasspath from ant 1.7.0) |
98 | | - <attribute name="Main-Class" value="net.psammead.commonist.Commonist"/> |
99 | | - --> |
| 143 | + <attribute name="Main-Class" value="commonist.Commonist"/> |
| 144 | + <attribute name="Class-Path" value="bsh-2.0b2-fixed.jar commons-httpclient-3.1.jar commons-codec-1.3.jar commons-logging-1.1.jar sanselan-0.97-incubator.jar scala-library.jar" /> |
100 | 145 | </manifest> |
101 | 146 | </jar> |
102 | 147 | </target> |
— | — | @@ -110,22 +155,24 @@ |
111 | 156 | |
112 | 157 | <!-- ==== full dist ==== --> |
113 | 158 | |
114 | | - <target name="dist" depends="compile" description="create a distribution zip"> |
| 159 | + <target name="dist" depends="jar" description="create a distribution zip"> |
115 | 160 | <mkdir dir="build"/> |
116 | 161 | <zip destfile="build/${project}-${version}.zip"> |
117 | 162 | <zipfileset dir="." prefix="${project}-${version}" filemode="770"> |
118 | 163 | <include name="bin/*"/> |
119 | 164 | </zipfileset> |
| 165 | + <zipfileset dir="build/jar" prefix="${project}-${version}/lib"> |
| 166 | + <include name="commonist.jar" /> |
| 167 | + </zipfileset> |
120 | 168 | <zipfileset dir="." prefix="${project}-${version}"> |
121 | 169 | <include name="doc/index.html"/> |
122 | 170 | <include name="doc/changes.txt"/> |
123 | | - <include name="build.*"/> |
124 | | - <include name="src/scala/**"/> |
| 171 | + <include name="doc/changes-minibpp.txt"/> |
| 172 | + <include name="src/**"/> |
125 | 173 | <include name="etc/**"/> |
126 | 174 | <exclude name="${sign.keystore}"/> |
127 | 175 | <include name="image/**"/> |
128 | 176 | <include name="lib/**"/> |
129 | | - <include name="build/classes/**"/> |
130 | 177 | </zipfileset> |
131 | 178 | </zip> |
132 | 179 | </target> |
— | — | @@ -151,7 +198,9 @@ |
152 | 199 | <zipfileset dir="etc" includes="PkgInfo" prefix="${mac.app}/Contents"/> |
153 | 200 | <zipfileset dir="build/etc" includes="Info.plist" prefix="${mac.app}/Contents"/> |
154 | 201 | <zipfileset dir="image" includes="${mac.bundle.icons}" prefix="${mac.app}/Contents/Resources"/> |
155 | | - <zipfileset dir="lib" includes="${binary.jars}" prefix="${mac.app}/Contents/Resources/Java"/> |
| 202 | + <zipfileset dir="lib" prefix="${mac.app}/Contents/Resources/Java"> |
| 203 | + <fileset refid="runtime.libraries" /> |
| 204 | + </zipfileset> |
156 | 205 | <zipfileset dir="build/jar" includes="${project}.jar" prefix="${mac.app}/Contents/Resources/Java"/> |
157 | 206 | </zip> |
158 | 207 | </target> |
— | — | @@ -168,8 +217,9 @@ |
169 | 218 | <mkdir dir="build/ws"/> |
170 | 219 | <copy toDir="build/ws"> |
171 | 220 | <fileset dir="build/jar"/> |
172 | | - <fileset dir="lib" includes="${binary.jars}"/> |
| 221 | + <fileset refid="runtime.libraries" /> |
173 | 222 | </copy> |
| 223 | + <fail unless="sign.alias" message="Please create private.properties file and include sign.alias, sign.storepass, sign.keypass properties there."/> |
174 | 224 | <signjar |
175 | 225 | alias="${sign.alias}" |
176 | 226 | storepass="${sign.storepass}" |
— | — | @@ -177,7 +227,9 @@ |
178 | 228 | keypass="${sign.keypass}" |
179 | 229 | > |
180 | 230 | <!-- jar="build/signed-jar/${project}.jar" --> |
181 | | - <fileset dir="build/ws" includes="*.jar"/> |
| 231 | + <fileset dir="build/ws"> |
| 232 | + <patternset refid="product.jars" /> |
| 233 | + </fileset> |
182 | 234 | </signjar> |
183 | 235 | </target> |
184 | 236 | |
— | — | @@ -198,7 +250,7 @@ |
199 | 251 | <zip destfile="build/${project}-${version}-ws.zip"> |
200 | 252 | <zipfileset dir="build/ws"> |
201 | 253 | <include name="${ws.jnlp}"/> |
202 | | - <include name="*.jar"/> |
| 254 | + <patternset refid="product.jars" /> |
203 | 255 | </zipfileset> |
204 | 256 | <zipfileset dir="image"> |
205 | 257 | <include name="${ws.icon}"/> |
— | — | @@ -206,23 +258,4 @@ |
207 | 259 | </zipfileset> |
208 | 260 | </zip> |
209 | 261 | </target> |
210 | | - |
211 | | - <!-- ==== export ==== --> |
212 | | - |
213 | | - <target name="import" description="import artefacts from other projects"> |
214 | | - <ant dir="../minibpp" antfile="build.xml" target="export" inheritAll="false"/> |
215 | | - <copy toDir="lib"> |
216 | | - <fileset dir="../minibpp/build/export" includes="minibpp.jar,minibpp-src.jar"/> |
217 | | - </copy> |
218 | | - </target> |
219 | | - |
220 | | - <target name="export" depends="doc,dist,ws-dist" description="create artefacts"> |
221 | | - <property name="export.dir" value="build/export"/> |
222 | | - <mkdir dir="${export.dir}"/> |
223 | | - <copy todir="${export.dir}"> |
224 | | - <fileset dir="build/doc" includes="changes.txt,index.html"/> |
225 | | - <fileset dir="build" includes="${project}-${version}.zip"/> |
226 | | - </copy> |
227 | | - <unzip src="build/${project}-${version}-ws.zip" dest="${export.dir}/ws" overwrite="true"/> |
228 | | - </target> |
229 | 262 | </project> |
Index: trunk/tools/commonist/test/test.bsh |
— | — | @@ -0,0 +1,20 @@ |
| 2 | +//bin/true; exec java -Xmx16m -cp "lib/bsh-2.0b2-fixed.jar" bsh.Interpreter "$0" "$@" |
| 3 | +//============================================================================== |
| 4 | + |
| 5 | +/* |
| 6 | +if (!new File("build/classes").exists()) exec("ant fresh"); |
| 7 | +addClassPath("build/classes"); |
| 8 | +*/ |
| 9 | +if (!new File("build/jar/minibpp.jar").exists()) exec("ant fresh"); |
| 10 | +addClassPath("build/jar/minibpp.jar"); |
| 11 | +import net.psammead.minibpp.Compiler; |
| 12 | + |
| 13 | +var in = new BufferedReader(new InputStreamReader(new FileInputStream("versatz/template.bpp"))); |
| 14 | +var out = new PrintWriter(System.out); |
| 15 | +var f = new Compiler(); |
| 16 | +f.filter(in, out); // BufferedReader in, PrintWriter out |
| 17 | +in.close(); |
| 18 | +out.close(); |
| 19 | + |
| 20 | +//============================================================================== |
| 21 | +//:mode=beanshell:noTabs=false:tabSize=4:indentSize=4:lineSeparator=\n: |
Index: trunk/tools/commonist/doc/changes-minibpp.txt |
— | — | @@ -0,0 +1,8 @@ |
| 2 | +0.0.3 |
| 3 | + |
| 4 | +0.0.2 |
| 5 | + fixed OOME for escaped unicode characters |
| 6 | + added A.class and A.bsh for use with useModule.bsh |
| 7 | + |
| 8 | +0.0.1 |
| 9 | + initial release |
Property changes on: trunk/tools/commonist/doc/changes-minibpp.txt |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 10 | + native |
Index: trunk/tools/commonist/lib/minibpp.jar |
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Index: trunk/tools/commonist/lib/minibpp-src.jar |
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes on: trunk/tools/commonist/lib/commons-codec-1.3.jar |
___________________________________________________________________ |
Modified: svn:mime-type |
2 | 11 | - application/octet-stream |
3 | 12 | + application/java-archive |
Property changes on: trunk/tools/commonist/lib/scala-library.jar |
___________________________________________________________________ |
Modified: svn:mime-type |
4 | 13 | - application/octet-stream |
5 | 14 | + application/java-archive |
Property changes on: trunk/tools/commonist/lib/commons-httpclient-3.1.jar |
___________________________________________________________________ |
Modified: svn:mime-type |
6 | 15 | - application/octet-stream |
7 | 16 | + application/java-archive |
Index: trunk/tools/commonist/lib/javacc.jar |
Cannot display: file marked as a binary type. |
svn:mime-type = application/java-archive |
Property changes on: trunk/tools/commonist/lib/javacc.jar |
___________________________________________________________________ |
Added: svn:mime-type |
8 | 17 | + application/java-archive |
Property changes on: trunk/tools/commonist/lib/bsh-2.0b2-fixed.jar |
___________________________________________________________________ |
Modified: svn:mime-type |
9 | 18 | - application/octet-stream |
10 | 19 | + application/java-archive |
Property changes on: trunk/tools/commonist/lib/commons-logging-1.1.jar |
___________________________________________________________________ |
Modified: svn:mime-type |
11 | 20 | - application/octet-stream |
12 | 21 | + application/java-archive |
Property changes on: trunk/tools/commonist/lib/sanselan-0.97-incubator.jar |
___________________________________________________________________ |
Modified: svn:mime-type |
13 | 22 | - application/octet-stream |
14 | 23 | + application/java-archive |
Index: trunk/tools/commonist/src/scala/scutil/json/JSON.scala |
— | — | @@ -1,131 +0,0 @@ |
2 | | -package scutil.json |
3 | | - |
4 | | -import scala.util.parsing.input._ |
5 | | -import scala.util.parsing.combinator._ |
6 | | -import scala.util.parsing.combinator.syntactical._ |
7 | | -import scala.util.parsing.combinator.lexical._ |
8 | | - |
9 | | -object JSValue { |
10 | | - /** parse a JSON formatted String into a JSValue */ |
11 | | - def parse(s:String):Option[JSValue] = parse(new CharSequenceReader(s)) |
12 | | - def parse(s:Reader[Char]):Option[JSValue] = JSParser.parse(s) |
13 | | - |
14 | | - /** NOTE: don't try to put in Maps with non-String keys! */ |
15 | | - def apply(value:Any):JSValue = value match { |
16 | | - case null => JSNull |
17 | | - case value:JSValue => value |
18 | | - case value:Int => JSNumber(value) |
19 | | - case value:Long => JSNumber(value) |
20 | | - case value:Float => JSNumber(value) |
21 | | - case value:Double => JSNumber(value) |
22 | | - case value:BigInt => JSNumber(value) |
23 | | - case value:BigDecimal => JSNumber(value) |
24 | | - case value:Boolean => JSBoolean(value) |
25 | | - case value:String => JSString(value) |
26 | | - case value:List[_] => JSArray(value map apply) |
27 | | - case value:Map[_,_] => JSObject(Map.empty ++ value.iterator.map { |
28 | | - case (key:String, valu) => (JSString(key), apply(valu)) |
29 | | - case (key,valu) => error("map key is not a String: " + key); |
30 | | - }) |
31 | | - case value:Any => error("not a native json value: " + value) |
32 | | - } |
33 | | - |
34 | | - /** can be used to prepare some value to JSValue standards |
35 | | - def cooker(prepare:(Any=>Any)) = new { |
36 | | - def apply(obj:Any):Any = prepare(obj) match { |
37 | | - case value:Map[_,_] => Map.empty ++ value.elements.map { case (key,value) => (apply(key), apply(value)) } |
38 | | - case value:Seq[_] => value map apply |
39 | | - case value => prepare(value) |
40 | | - } |
41 | | - } |
42 | | - */ |
43 | | -} |
44 | | -sealed trait JSValue { |
45 | | - def toJSON:String |
46 | | -} |
47 | | - |
48 | | -case object JSNull extends JSValue { |
49 | | - def toJSON = "null" |
50 | | -} |
51 | | - |
52 | | -object JSNumber { |
53 | | - def apply(value:Int):JSNumber = JSNumber(BigDecimal(value)) |
54 | | - def apply(value:Long):JSNumber = JSNumber(BigDecimal(value)) |
55 | | - def apply(value:Float):JSNumber = JSNumber(BigDecimal(value)) |
56 | | - def apply(value:Double):JSNumber = JSNumber(BigDecimal(value)) |
57 | | - def apply(value:BigInt):JSNumber = JSNumber(BigDecimal(value)) |
58 | | -} |
59 | | -case class JSNumber(value:BigDecimal) extends JSValue { |
60 | | - def toJSON = value.toString |
61 | | -} |
62 | | - |
63 | | -object JSBoolean { |
64 | | - def apply(value:Boolean) = if (value) JSTrue else JSFalse |
65 | | -} |
66 | | -sealed abstract class JSBoolean extends JSValue |
67 | | - |
68 | | -case object JSTrue extends JSBoolean { |
69 | | - def toJSON = "true" |
70 | | -} |
71 | | - |
72 | | -case object JSFalse extends JSBoolean { |
73 | | - def toJSON = "false" |
74 | | -} |
75 | | - |
76 | | -case class JSString(value:String) extends JSValue { |
77 | | - def toJSON = value map { |
78 | | - _ match { |
79 | | - case '"' => "\\\"" |
80 | | - case '\\' => "\\\\" |
81 | | - // this would be allowed but is ugly |
82 | | - //case '/' => "\\/" |
83 | | - // these are optional |
84 | | - case '\b' => "\\b" |
85 | | - case '\f' => "\\f" |
86 | | - case '\n' => "\\n" |
87 | | - case '\r' => "\\r" |
88 | | - case '\t' => "\\t" |
89 | | - case c |
90 | | - if c < 32 => "\\u%04x".format(c.toInt) |
91 | | - case c => c.toString |
92 | | - } |
93 | | - } mkString("\"","","\"") |
94 | | -} |
95 | | - |
96 | | -case class JSArray(value:Seq[JSValue]) extends JSValue { |
97 | | - def toJSON = value map { _.toJSON } mkString("[", ",", "]") |
98 | | -} |
99 | | - |
100 | | -/* |
101 | | -object JSObject { |
102 | | - def apply(values:Seq[Pair[JSString,JSValue]]):JSObject = JSObject(Map.empty ++ values) |
103 | | -} |
104 | | -*/ |
105 | | -case class JSObject(value:Map[JSString,JSValue]) extends JSValue { |
106 | | - def toJSON = value.iterator map { |
107 | | - case (key,valu) => key.toJSON + ":" + valu.toJSON |
108 | | - } mkString("{", ",", "}") |
109 | | -} |
110 | | - |
111 | | -object JSParser extends StdTokenParsers with ImplicitConversions { |
112 | | - type Tokens = scala.util.parsing.json.Lexer |
113 | | - |
114 | | - val lexical = new Tokens |
115 | | - lexical.reserved ++= List("true", "false", "null") |
116 | | - lexical.delimiters ++= List("{", "}", "[", "]", ":", ",") |
117 | | - |
118 | | - def value:Parser[JSValue] = (obj | arr | str | num | tru | fls | nul) |
119 | | - def arr:Parser[JSArray] = "[" ~> repsep(value, ",") <~ "]" ^^ { x => JSArray(x) } |
120 | | - def obj:Parser[JSObject] = "{" ~> repsep(pair, ",") <~ "}" ^^ { x => JSObject(Map() ++ x) } |
121 | | - def pair:Parser[(JSString,JSValue)] = str ~ (":" ~> value) ^^ { case x ~ y => (x, y) } |
122 | | - def str:Parser[JSString] = accept("string", { case lexical.StringLit(x) => JSString(x) }) |
123 | | - def num:Parser[JSNumber] = accept("number", { case lexical.NumericLit(x) => JSNumber(BigDecimal(x)) }) |
124 | | - def tru:Parser[JSBoolean] = "true" ^^^ JSTrue |
125 | | - def fls:Parser[JSBoolean] = "false" ^^^ JSFalse |
126 | | - def nul:Parser[JSValue] = "null" ^^^ JSNull |
127 | | - |
128 | | - def parse(input:Reader[Char]):Option[JSValue] = phrase(value)(new lexical.Scanner(input)) match { |
129 | | - case Success(result, _) => Some(result) |
130 | | - case _ => None |
131 | | - } |
132 | | -} |
\ No newline at end of file |
Index: trunk/tools/commonist/src/scala/scutil/json/JSObject.scala |
— | — | @@ -0,0 +1,131 @@ |
| 2 | +package scutil.json |
| 3 | + |
| 4 | +import scala.util.parsing.input._ |
| 5 | +import scala.util.parsing.combinator._ |
| 6 | +import scala.util.parsing.combinator.syntactical._ |
| 7 | +import scala.util.parsing.combinator.lexical._ |
| 8 | + |
| 9 | +object JSValue { |
| 10 | + /** parse a JSON formatted String into a JSValue */ |
| 11 | + def parse(s:String):Option[JSValue] = parse(new CharSequenceReader(s)) |
| 12 | + def parse(s:Reader[Char]):Option[JSValue] = JSParser.parse(s) |
| 13 | + |
| 14 | + /** NOTE: don't try to put in Maps with non-String keys! */ |
| 15 | + def apply(value:Any):JSValue = value match { |
| 16 | + case null => JSNull |
| 17 | + case value:JSValue => value |
| 18 | + case value:Int => JSNumber(value) |
| 19 | + case value:Long => JSNumber(value) |
| 20 | + case value:Float => JSNumber(value) |
| 21 | + case value:Double => JSNumber(value) |
| 22 | + case value:BigInt => JSNumber(value) |
| 23 | + case value:BigDecimal => JSNumber(value) |
| 24 | + case value:Boolean => JSBoolean(value) |
| 25 | + case value:String => JSString(value) |
| 26 | + case value:List[_] => JSArray(value map apply) |
| 27 | + case value:Map[_,_] => JSObject(Map.empty ++ value.iterator.map { |
| 28 | + case (key:String, valu) => (JSString(key), apply(valu)) |
| 29 | + case (key,valu) => error("map key is not a String: " + key); |
| 30 | + }) |
| 31 | + case value:Any => error("not a native json value: " + value) |
| 32 | + } |
| 33 | + |
| 34 | + /** can be used to prepare some value to JSValue standards |
| 35 | + def cooker(prepare:(Any=>Any)) = new { |
| 36 | + def apply(obj:Any):Any = prepare(obj) match { |
| 37 | + case value:Map[_,_] => Map.empty ++ value.elements.map { case (key,value) => (apply(key), apply(value)) } |
| 38 | + case value:Seq[_] => value map apply |
| 39 | + case value => prepare(value) |
| 40 | + } |
| 41 | + } |
| 42 | + */ |
| 43 | +} |
| 44 | +sealed trait JSValue { |
| 45 | + def toJSON:String |
| 46 | +} |
| 47 | + |
| 48 | +case object JSNull extends JSValue { |
| 49 | + def toJSON = "null" |
| 50 | +} |
| 51 | + |
| 52 | +object JSNumber { |
| 53 | + def apply(value:Int):JSNumber = JSNumber(BigDecimal(value)) |
| 54 | + def apply(value:Long):JSNumber = JSNumber(BigDecimal(value)) |
| 55 | + def apply(value:Float):JSNumber = JSNumber(BigDecimal(value)) |
| 56 | + def apply(value:Double):JSNumber = JSNumber(BigDecimal(value)) |
| 57 | + def apply(value:BigInt):JSNumber = JSNumber(BigDecimal(value)) |
| 58 | +} |
| 59 | +case class JSNumber(value:BigDecimal) extends JSValue { |
| 60 | + def toJSON = value.toString |
| 61 | +} |
| 62 | + |
| 63 | +object JSBoolean { |
| 64 | + def apply(value:Boolean) = if (value) JSTrue else JSFalse |
| 65 | +} |
| 66 | +sealed abstract class JSBoolean extends JSValue |
| 67 | + |
| 68 | +case object JSTrue extends JSBoolean { |
| 69 | + def toJSON = "true" |
| 70 | +} |
| 71 | + |
| 72 | +case object JSFalse extends JSBoolean { |
| 73 | + def toJSON = "false" |
| 74 | +} |
| 75 | + |
| 76 | +case class JSString(value:String) extends JSValue { |
| 77 | + def toJSON = value map { |
| 78 | + _ match { |
| 79 | + case '"' => "\\\"" |
| 80 | + case '\\' => "\\\\" |
| 81 | + // this would be allowed but is ugly |
| 82 | + //case '/' => "\\/" |
| 83 | + // these are optional |
| 84 | + case '\b' => "\\b" |
| 85 | + case '\f' => "\\f" |
| 86 | + case '\n' => "\\n" |
| 87 | + case '\r' => "\\r" |
| 88 | + case '\t' => "\\t" |
| 89 | + case c |
| 90 | + if c < 32 => "\\u%04x".format(c.toInt) |
| 91 | + case c => c.toString |
| 92 | + } |
| 93 | + } mkString("\"","","\"") |
| 94 | +} |
| 95 | + |
| 96 | +case class JSArray(value:Seq[JSValue]) extends JSValue { |
| 97 | + def toJSON = value map { _.toJSON } mkString("[", ",", "]") |
| 98 | +} |
| 99 | + |
| 100 | +/* |
| 101 | +object JSObject { |
| 102 | + def apply(values:Seq[Pair[JSString,JSValue]]):JSObject = JSObject(Map.empty ++ values) |
| 103 | +} |
| 104 | +*/ |
| 105 | +case class JSObject(value:Map[JSString,JSValue]) extends JSValue { |
| 106 | + def toJSON = value.iterator map { |
| 107 | + case (key,valu) => key.toJSON + ":" + valu.toJSON |
| 108 | + } mkString("{", ",", "}") |
| 109 | +} |
| 110 | + |
| 111 | +object JSParser extends StdTokenParsers with ImplicitConversions { |
| 112 | + type Tokens = scala.util.parsing.json.Lexer |
| 113 | + |
| 114 | + val lexical = new Tokens |
| 115 | + lexical.reserved ++= List("true", "false", "null") |
| 116 | + lexical.delimiters ++= List("{", "}", "[", "]", ":", ",") |
| 117 | + |
| 118 | + def value:Parser[JSValue] = (obj | arr | str | num | tru | fls | nul) |
| 119 | + def arr:Parser[JSArray] = "[" ~> repsep(value, ",") <~ "]" ^^ { x => JSArray(x) } |
| 120 | + def obj:Parser[JSObject] = "{" ~> repsep(pair, ",") <~ "}" ^^ { x => JSObject(Map() ++ x) } |
| 121 | + def pair:Parser[(JSString,JSValue)] = str ~ (":" ~> value) ^^ { case x ~ y => (x, y) } |
| 122 | + def str:Parser[JSString] = accept("string", { case lexical.StringLit(x) => JSString(x) }) |
| 123 | + def num:Parser[JSNumber] = accept("number", { case lexical.NumericLit(x) => JSNumber(BigDecimal(x)) }) |
| 124 | + def tru:Parser[JSBoolean] = "true" ^^^ JSTrue |
| 125 | + def fls:Parser[JSBoolean] = "false" ^^^ JSFalse |
| 126 | + def nul:Parser[JSValue] = "null" ^^^ JSNull |
| 127 | + |
| 128 | + def parse(input:Reader[Char]):Option[JSValue] = phrase(value)(new lexical.Scanner(input)) match { |
| 129 | + case Success(result, _) => Some(result) |
| 130 | + case _ => None |
| 131 | + } |
| 132 | +} |
Index: trunk/tools/commonist/src/scala/commonist/task/upload/TemplateData.scala |
— | — | @@ -1,38 +0,0 @@ |
2 | | -package commonist.task.upload |
3 | | - |
4 | | -import commonist.data._ |
5 | | - |
6 | | -import scala.reflect.BeanProperty |
7 | | - |
8 | | -case class Common( |
9 | | - @BeanProperty description:String, |
10 | | - @BeanProperty date:String, |
11 | | - @BeanProperty source:String, |
12 | | - @BeanProperty author:String, |
13 | | - @BeanProperty licenseTemplate:String, |
14 | | - @BeanProperty licenseDescription:String, |
15 | | - @BeanProperty categories:String |
16 | | -) |
17 | | - |
18 | | -case class Batch( |
19 | | - @BeanProperty uploads:java.util.List[Upload], |
20 | | - @BeanProperty successes:java.util.List[Upload], |
21 | | - @BeanProperty failures:java.util.List[Upload] |
22 | | -) |
23 | | - |
24 | | -case class Upload( |
25 | | - @BeanProperty name:String, // without the File namespace |
26 | | - @BeanProperty title:String, // to be used in a link |
27 | | - @BeanProperty error:String, // null if upload went ok |
28 | | - @BeanProperty previous:String, // null for the first |
29 | | - @BeanProperty next:String, // null for the last |
30 | | - |
31 | | - @BeanProperty description:String, |
32 | | - @BeanProperty date:String, |
33 | | - @BeanProperty permission:String, |
34 | | - @BeanProperty categories:String, |
35 | | - |
36 | | - @BeanProperty coordinates:String, // raw string |
37 | | - @BeanProperty latitude:String, // null if raw string could not be parsed |
38 | | - @BeanProperty longitude:String // null if raw string could not be parsed |
39 | | -) |
Index: trunk/tools/commonist/src/scala/commonist/task/upload/Upload.scala |
— | — | @@ -0,0 +1,38 @@ |
| 2 | +package commonist.task.upload |
| 3 | + |
| 4 | +import commonist.data._ |
| 5 | + |
| 6 | +import scala.reflect.BeanProperty |
| 7 | + |
| 8 | +case class Common( |
| 9 | + @BeanProperty description:String, |
| 10 | + @BeanProperty date:String, |
| 11 | + @BeanProperty source:String, |
| 12 | + @BeanProperty author:String, |
| 13 | + @BeanProperty licenseTemplate:String, |
| 14 | + @BeanProperty licenseDescription:String, |
| 15 | + @BeanProperty categories:String |
| 16 | +) |
| 17 | + |
| 18 | +case class Batch( |
| 19 | + @BeanProperty uploads:java.util.List[Upload], |
| 20 | + @BeanProperty successes:java.util.List[Upload], |
| 21 | + @BeanProperty failures:java.util.List[Upload] |
| 22 | +) |
| 23 | + |
| 24 | +case class Upload( |
| 25 | + @BeanProperty name:String, // without the File namespace |
| 26 | + @BeanProperty title:String, // to be used in a link |
| 27 | + @BeanProperty error:String, // null if upload went ok |
| 28 | + @BeanProperty previous:String, // null for the first |
| 29 | + @BeanProperty next:String, // null for the last |
| 30 | + |
| 31 | + @BeanProperty description:String, |
| 32 | + @BeanProperty date:String, |
| 33 | + @BeanProperty permission:String, |
| 34 | + @BeanProperty categories:String, |
| 35 | + |
| 36 | + @BeanProperty coordinates:String, // raw string |
| 37 | + @BeanProperty latitude:String, // null if raw string could not be parsed |
| 38 | + @BeanProperty longitude:String // null if raw string could not be parsed |
| 39 | +) |
Index: trunk/tools/commonist/src/scala/commonist/api/Web.scala |
— | — | @@ -1,93 +0,0 @@ |
2 | | -package commonist.api |
3 | | - |
4 | | -import java.net.URI |
5 | | - |
6 | | -import scala.collection.JavaConversions._ |
7 | | - |
8 | | -import scutil.ext.AnyRefExt._ |
9 | | - |
10 | | -/* |
11 | | -[scheme:][//authority][path][?query][#fragment] |
12 | | -[user-info@]host[:port] |
13 | | -*/ |
14 | | -object URIData { |
15 | | - def parse(str:String):URIData = parse(new URI(str)) |
16 | | - def parse(uri:URI):URIData = new URIData( |
17 | | - uri.getScheme.nullOption, |
18 | | - uri.getAuthority.nullOption, |
19 | | - uri.getPath.nullOption, |
20 | | - uri.getQuery.nullOption, |
21 | | - uri.getFragment.nullOption, |
22 | | - uri.getUserInfo.nullOption, |
23 | | - uri.getHost.nullOption, |
24 | | - uri.getPort match { case -1 => None; case x => Some(x) } |
25 | | - ) |
26 | | -} |
27 | | -case class URIData( |
28 | | - scheme:Option[String], |
29 | | - authority:Option[String], |
30 | | - path:Option[String], |
31 | | - query:Option[String], |
32 | | - fragment:Option[String], |
33 | | - userInfo:Option[String], |
34 | | - host:Option[String], |
35 | | - port:Option[Int] |
36 | | -) { |
37 | | - def target:Option[Target] = |
38 | | - for { |
39 | | - sch <- scheme |
40 | | - hst <- host |
41 | | - prt <- port orElse defaultPort |
42 | | - } yield { |
43 | | - Target(hst, prt) |
44 | | - } |
45 | | - def cred:Option[Cred] = |
46 | | - userInfo map { it => |
47 | | - it indexOf (':') match { |
48 | | - case -1 => Cred(it, "") |
49 | | - case x => Cred(it.substring(0,x), it.substring(x+1)) |
50 | | - } |
51 | | - } |
52 | | - def defaultPort:Option[Int] = |
53 | | - scheme map { _ match { |
54 | | - case "http" => 80 |
55 | | - case "https" => 443 |
56 | | - case x => error("unexpected scheme: " + x) |
57 | | - } } |
58 | | -} |
59 | | - |
60 | | -case class Target(host:String, port:Int) |
61 | | -case class Cred(user:String, password:String) |
62 | | - |
63 | | -case class Proxy(target:Target, cred:Option[Cred], noproxy:Option[Target=>Boolean]) |
64 | | -object Proxy { |
65 | | - def systemProperties:Option[Proxy] = { |
66 | | - val sysProps:scala.collection.mutable.Map[String,String] = System.getProperties |
67 | | - for { |
68 | | - host <- sysProps get "http.proxyHost" |
69 | | - port <- sysProps get "http.proxyPort" |
70 | | - } |
71 | | - yield { |
72 | | - val target = Target(host, Integer.parseInt(port)) |
73 | | - val noproxy = sysProps get ("http.nonProxyHosts") map NoProxy.sun _ |
74 | | - Proxy(target, None, noproxy) |
75 | | - } |
76 | | - } |
77 | | - |
78 | | - def environmentVariable:Option[Proxy] = |
79 | | - for { |
80 | | - http_proxy <- System.getenv("http_proxy").nullOption |
81 | | - val data = URIData.parse(http_proxy) |
82 | | - target <- data.target |
83 | | - } |
84 | | - yield { |
85 | | - Proxy(target, data.cred, None) |
86 | | - } |
87 | | -} |
88 | | - |
89 | | -object NoProxy { |
90 | | - def all(target:Target):Boolean = false |
91 | | - |
92 | | - /** like suns format, f.e. "*.test.de|localhost" */ |
93 | | - def sun(re:String)(target:Target):Boolean = target.host matches re.replaceAll("\\.", "\\\\.").replaceAll("\\*", ".*?") |
94 | | -} |
Index: trunk/tools/commonist/src/scala/commonist/api/URIData.scala |
— | — | @@ -0,0 +1,93 @@ |
| 2 | +package commonist.api |
| 3 | + |
| 4 | +import java.net.URI |
| 5 | + |
| 6 | +import scala.collection.JavaConversions._ |
| 7 | + |
| 8 | +import scutil.ext.AnyRefExt._ |
| 9 | + |
| 10 | +/* |
| 11 | +[scheme:][//authority][path][?query][#fragment] |
| 12 | +[user-info@]host[:port] |
| 13 | +*/ |
| 14 | +object URIData { |
| 15 | + def parse(str:String):URIData = parse(new URI(str)) |
| 16 | + def parse(uri:URI):URIData = new URIData( |
| 17 | + uri.getScheme.nullOption, |
| 18 | + uri.getAuthority.nullOption, |
| 19 | + uri.getPath.nullOption, |
| 20 | + uri.getQuery.nullOption, |
| 21 | + uri.getFragment.nullOption, |
| 22 | + uri.getUserInfo.nullOption, |
| 23 | + uri.getHost.nullOption, |
| 24 | + uri.getPort match { case -1 => None; case x => Some(x) } |
| 25 | + ) |
| 26 | +} |
| 27 | +case class URIData( |
| 28 | + scheme:Option[String], |
| 29 | + authority:Option[String], |
| 30 | + path:Option[String], |
| 31 | + query:Option[String], |
| 32 | + fragment:Option[String], |
| 33 | + userInfo:Option[String], |
| 34 | + host:Option[String], |
| 35 | + port:Option[Int] |
| 36 | +) { |
| 37 | + def target:Option[Target] = |
| 38 | + for { |
| 39 | + sch <- scheme |
| 40 | + hst <- host |
| 41 | + prt <- port orElse defaultPort |
| 42 | + } yield { |
| 43 | + Target(hst, prt) |
| 44 | + } |
| 45 | + def cred:Option[Cred] = |
| 46 | + userInfo map { it => |
| 47 | + it indexOf (':') match { |
| 48 | + case -1 => Cred(it, "") |
| 49 | + case x => Cred(it.substring(0,x), it.substring(x+1)) |
| 50 | + } |
| 51 | + } |
| 52 | + def defaultPort:Option[Int] = |
| 53 | + scheme map { _ match { |
| 54 | + case "http" => 80 |
| 55 | + case "https" => 443 |
| 56 | + case x => error("unexpected scheme: " + x) |
| 57 | + } } |
| 58 | +} |
| 59 | + |
| 60 | +case class Target(host:String, port:Int) |
| 61 | +case class Cred(user:String, password:String) |
| 62 | + |
| 63 | +case class Proxy(target:Target, cred:Option[Cred], noproxy:Option[Target=>Boolean]) |
| 64 | +object Proxy { |
| 65 | + def systemProperties:Option[Proxy] = { |
| 66 | + val sysProps:scala.collection.mutable.Map[String,String] = System.getProperties |
| 67 | + for { |
| 68 | + host <- sysProps get "http.proxyHost" |
| 69 | + port <- sysProps get "http.proxyPort" |
| 70 | + } |
| 71 | + yield { |
| 72 | + val target = Target(host, Integer.parseInt(port)) |
| 73 | + val noproxy = sysProps get ("http.nonProxyHosts") map NoProxy.sun _ |
| 74 | + Proxy(target, None, noproxy) |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + def environmentVariable:Option[Proxy] = |
| 79 | + for { |
| 80 | + http_proxy <- System.getenv("http_proxy").nullOption |
| 81 | + val data = URIData.parse(http_proxy) |
| 82 | + target <- data.target |
| 83 | + } |
| 84 | + yield { |
| 85 | + Proxy(target, data.cred, None) |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +object NoProxy { |
| 90 | + def all(target:Target):Boolean = false |
| 91 | + |
| 92 | + /** like suns format, f.e. "*.test.de|localhost" */ |
| 93 | + def sun(re:String)(target:Target):Boolean = target.host matches re.replaceAll("\\.", "\\\\.").replaceAll("\\*", ".*?") |
| 94 | +} |
Index: trunk/tools/commonist/src/net/psammead/minibpp/Parser.jj |
— | — | @@ -0,0 +1,135 @@ |
| 2 | +options { UNICODE_INPUT=true; STATIC=false; } |
| 3 | + |
| 4 | +PARSER_BEGIN(Parser) |
| 5 | + package net.psammead.minibpp.parser; |
| 6 | + |
| 7 | + import java.io.*; |
| 8 | + import net.psammead.minibpp.Context; |
| 9 | + |
| 10 | + public class Parser { |
| 11 | + Context pp; |
| 12 | + public static void parse(Reader r, Context _pp) throws ParseException, IOException { |
| 13 | + Parser p = new Parser(r); |
| 14 | + p.pp=_pp; |
| 15 | + p.Line(); |
| 16 | + p.pp.done(); |
| 17 | + } |
| 18 | + } |
| 19 | + |
| 20 | +PARSER_END(Parser) |
| 21 | + |
| 22 | +TOKEN_MGR_DECLS : |
| 23 | +{ |
| 24 | + static int pcount; |
| 25 | +} |
| 26 | + |
| 27 | +<DEFAULT> TOKEN: { < PLAIN : (~[]) > } |
| 28 | +<DEFAULT> TOKEN: { < PLAIN_DOLLAR : "$$" > { |
| 29 | + matchedToken.image="$"; matchedToken.kind=PLAIN; |
| 30 | +} } |
| 31 | +<DEFAULT> TOKEN: { < LPAREN : "$(" > { matchedToken.image="("; pcount=1; } : JAVA } |
| 32 | +<DEFAULT> TOKEN : { |
| 33 | + < IDENTIFIER: "$" <LETTER> (<LETTER>|<DIGIT>)* > |
| 34 | +| |
| 35 | + < #LETTER: |
| 36 | + [ |
| 37 | + "\u0041"-"\u005a", |
| 38 | + "\u005f", |
| 39 | + "\u0061"-"\u007a", |
| 40 | + "\u00c0"-"\u00d6", |
| 41 | + "\u00d8"-"\u00f6", |
| 42 | + "\u00f8"-"\u00ff", |
| 43 | + "\u0100"-"\u1fff", |
| 44 | + "\u3040"-"\u318f", |
| 45 | + "\u3300"-"\u337f", |
| 46 | + "\u3400"-"\u3d2d", |
| 47 | + "\u4e00"-"\u9fff", |
| 48 | + "\uf900"-"\ufaff" |
| 49 | + ] |
| 50 | + > |
| 51 | +| |
| 52 | + < #DIGIT: |
| 53 | + [ |
| 54 | + "\u0030"-"\u0039", |
| 55 | + "\u0660"-"\u0669", |
| 56 | + "\u06f0"-"\u06f9", |
| 57 | + "\u0966"-"\u096f", |
| 58 | + "\u09e6"-"\u09ef", |
| 59 | + "\u0a66"-"\u0a6f", |
| 60 | + "\u0ae6"-"\u0aef", |
| 61 | + "\u0b66"-"\u0b6f", |
| 62 | + "\u0be7"-"\u0bef", |
| 63 | + "\u0c66"-"\u0c6f", |
| 64 | + "\u0ce6"-"\u0cef", |
| 65 | + "\u0d66"-"\u0d6f", |
| 66 | + "\u0e50"-"\u0e59", |
| 67 | + "\u0ed0"-"\u0ed9", |
| 68 | + "\u1040"-"\u1049" |
| 69 | + ] |
| 70 | + > |
| 71 | +} |
| 72 | + |
| 73 | +<NOWHERE> TOKEN: { < RPAREN: ")" > } |
| 74 | +<JAVA> TOKEN: { < JLPAREN : "(" > { ++pcount; matchedToken.kind=JPLAIN; } } |
| 75 | +<JAVA> TOKEN: { < JRPAREN : ")" > { |
| 76 | + --pcount; |
| 77 | + if (pcount == 0) { |
| 78 | + SwitchTo(DEFAULT); |
| 79 | + matchedToken.kind=RPAREN; |
| 80 | + } else { |
| 81 | + matchedToken.kind=JPLAIN; |
| 82 | + } |
| 83 | +} } |
| 84 | + |
| 85 | +<JAVA> TOKEN : { < JPLAIN : (~["\"","\'","\n","\r","(",")"])+ > } |
| 86 | +<JAVA> TOKEN : { < JCHAR : |
| 87 | + "'" |
| 88 | + ( (~["'","\\","\n","\r"]) |
| 89 | + | ("\\" |
| 90 | + ( ["n","t","b","r","f","\\","'","\""] |
| 91 | + | ["0"-"7"] ( ["0"-"7"] )? |
| 92 | + | ["0"-"3"] ["0"-"7"] ["0"-"7"] |
| 93 | + ) |
| 94 | + ) |
| 95 | + ) |
| 96 | + "'" |
| 97 | +> { matchedToken.kind=JPLAIN; } } |
| 98 | +<JAVA> TOKEN : { < JSTRING : |
| 99 | + "\"" |
| 100 | + ( (~["\"","\\","\n","\r"]) |
| 101 | + | ("\\" |
| 102 | + ( ["n","t","b","r","f","\\","'","\""] |
| 103 | + | ["0"-"7"] ( ["0"-"7"] )? |
| 104 | + | ["0"-"3"] ["0"-"7"] ["0"-"7"] |
| 105 | + ) |
| 106 | + ) |
| 107 | + )* |
| 108 | + "\"" |
| 109 | +> { matchedToken.kind=JPLAIN; } } |
| 110 | + |
| 111 | +void Line() throws IOException : |
| 112 | +{ StringBuffer sb=new StringBuffer(); Token t; StringBuffer m; } |
| 113 | +{ |
| 114 | + ( |
| 115 | + t=<PLAIN> { sb.append(t.image);} |
| 116 | + | |
| 117 | + m=Magic() { |
| 118 | +// if (m.length()==0) { sb.append("$"); } |
| 119 | +// else { |
| 120 | + if (sb.length()>0) { pp.literal(sb.toString()); sb=new StringBuffer(); } |
| 121 | + pp.magic(m.toString()); |
| 122 | +// } |
| 123 | + } |
| 124 | + ) * <EOF> |
| 125 | + { if (sb.length() > 0) pp.literal(sb.toString()); } |
| 126 | +} |
| 127 | + |
| 128 | +StringBuffer Magic() throws IOException : |
| 129 | +{ StringBuffer sb=new StringBuffer(); Token t; } |
| 130 | +{ |
| 131 | + t=<IDENTIFIER> { sb.append(t.image.substring(1)); return sb; } |
| 132 | +| |
| 133 | + ( t=<LPAREN> |
| 134 | + ( t=<JPLAIN> { sb.append(t.image); } ) * |
| 135 | + t=<RPAREN> { return sb; } ) |
| 136 | +} |
Index: trunk/tools/commonist/src/net/psammead/minibpp/A.java |
— | — | @@ -0,0 +1,4 @@ |
| 2 | +package net.psammead.minibpp; |
| 3 | + |
| 4 | +/** Anchor class used to find our scripts */ |
| 5 | +public final class A {} |
Property changes on: trunk/tools/commonist/src/net/psammead/minibpp/A.java |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 6 | + native |
Index: trunk/tools/commonist/src/net/psammead/minibpp/Context.java |
— | — | @@ -0,0 +1,57 @@ |
| 2 | +package net.psammead.minibpp; |
| 3 | + |
| 4 | +import java.io.*; |
| 5 | + |
| 6 | +/** |
| 7 | + * Context for the parser generated by JavaCC<br> |
| 8 | + * Internal bridge between a Compiler and a Parser |
| 9 | + */ |
| 10 | +public final class Context { |
| 11 | + private PrintWriter out; |
| 12 | + private String content; |
| 13 | + private boolean bol; |
| 14 | + |
| 15 | + public Context(PrintWriter out) { |
| 16 | + this.out = out; |
| 17 | + content = null; |
| 18 | + bol = true; |
| 19 | + } |
| 20 | + |
| 21 | + public void magic(String s) { |
| 22 | + emit(); |
| 23 | + content = s; |
| 24 | + } |
| 25 | + |
| 26 | + public void literal(String s) { |
| 27 | + emit(); |
| 28 | + content = Compiler.literal(s); |
| 29 | + } |
| 30 | + |
| 31 | + public void done() { |
| 32 | + out.print("out.println("); |
| 33 | + if (content != null) { |
| 34 | + out.print(content); |
| 35 | + } |
| 36 | + if (bol) { |
| 37 | + out.println(");"); |
| 38 | + } |
| 39 | + else { |
| 40 | + out.println(");}"); |
| 41 | + } |
| 42 | + content = null; |
| 43 | + bol = true; |
| 44 | + } |
| 45 | + |
| 46 | + private void emit() { |
| 47 | + if (bol) { |
| 48 | + out.print("{"); |
| 49 | + bol = false; |
| 50 | + } |
| 51 | + if (content != null) { |
| 52 | + out.print("out.print("); |
| 53 | + out.print(content); |
| 54 | + out.print(");"); |
| 55 | + content = null; |
| 56 | + } |
| 57 | + } |
| 58 | +} |
Property changes on: trunk/tools/commonist/src/net/psammead/minibpp/Context.java |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 59 | + native |
Index: trunk/tools/commonist/src/net/psammead/minibpp/MiniBPP.bsh |
— | — | @@ -0,0 +1,26 @@ |
| 2 | +/** compile a template file into a String */ |
| 3 | +String template(var file, String charSet) { |
| 4 | + var in = new BufferedReader(new InputStreamReader(new FileInputStream(file), charSet)); |
| 5 | + var tmpl = new net.psammead.minibpp.Compiler().compile(in); |
| 6 | + in.close(); return tmpl; |
| 7 | +} |
| 8 | + |
| 9 | +/** compile a template into a String */ |
| 10 | +private String templateRelative(var file, String charSet) { |
| 11 | + // see sourceRelative command |
| 12 | + var file = pathToFile(dirname(getSourceFileInfo()) + File.separator + file); |
| 13 | + return new net.psammead.minibpp.Compiler().compile(file, charSet); |
| 14 | +} |
| 15 | + |
| 16 | +// und die bpp_redirect dinger w�ren hier praktisch |
| 17 | + |
| 18 | +/* |
| 19 | +evalTemplate( |
| 20 | + |
| 21 | +Object eval( String expression ) { |
| 22 | + return this.interpreter.eval( expression, this.caller.namespace ); |
| 23 | +} |
| 24 | + |
| 25 | +// compile and source template |
| 26 | +eval(templateRelative("template.bpp", "ISO-8859-1")); |
| 27 | +*/ |
Index: trunk/tools/commonist/src/net/psammead/minibpp/Compiler.java |
— | — | @@ -0,0 +1,189 @@ |
| 2 | +package net.psammead.minibpp; |
| 3 | + |
| 4 | +import java.io.*; |
| 5 | +import net.psammead.minibpp.parser.Parser; |
| 6 | +import net.psammead.minibpp.parser.ParseException; |
| 7 | + |
| 8 | +/** compiles one level of BeanShellPP syntax */ |
| 9 | +public class Compiler { |
| 10 | + /** compiles from stdin to stdout with the system default encoding */ |
| 11 | + public static void main(String[] args) throws ParseException, IOException { |
| 12 | + // no error handling necessary ;) |
| 13 | + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); |
| 14 | + PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); |
| 15 | + Compiler c = new Compiler(); |
| 16 | + c.filter(in, out); |
| 17 | + in.close(); |
| 18 | + out.close(); |
| 19 | + } |
| 20 | + |
| 21 | + //------------------------------------------------------------------------------ |
| 22 | + |
| 23 | + private int depth; |
| 24 | + private int lineNumber; |
| 25 | + |
| 26 | + private char echoChar = '#'; |
| 27 | + private char exactCmd = '\''; |
| 28 | + private char magicCmd = '\"'; |
| 29 | + private char defaultCmd = '\"'; |
| 30 | + private char magicIdentifier = '$'; |
| 31 | + |
| 32 | + //------------------------------------------------------------------------------ |
| 33 | + |
| 34 | + /** default constructor with depth 1 */ |
| 35 | + public Compiler() { |
| 36 | + this(1); |
| 37 | + } |
| 38 | + |
| 39 | + /** no idea what depth means. 0 does nothing, 1 compiles one level of # */ |
| 40 | + public Compiler(int depth) { |
| 41 | + this.depth = depth; |
| 42 | + lineNumber = 0; |
| 43 | + } |
| 44 | + |
| 45 | + /** compile a Template from a Reader into a String. the reader will not be closed! */ |
| 46 | + public String compile(Reader in) throws ParseException, IOException { |
| 47 | + BufferedReader br = new BufferedReader(in); |
| 48 | + StringWriter sw = new StringWriter(); |
| 49 | + PrintWriter pw = new PrintWriter(sw); |
| 50 | + filter(br, pw); |
| 51 | + pw.close(); |
| 52 | + return sw.toString(); |
| 53 | + } |
| 54 | + |
| 55 | + /** compiles a template in String form */ |
| 56 | + public String compile(String template) throws ParseException, IOException { |
| 57 | + Reader in = new StringReader(template); |
| 58 | + String out = compile(in); |
| 59 | + in.close(); return out; |
| 60 | + } |
| 61 | + |
| 62 | + /** compile a Template from a File into a String. */ |
| 63 | + public String compile(File file, String charSet) throws ParseException, IOException { |
| 64 | + Reader in = new InputStreamReader(new FileInputStream(file), charSet); |
| 65 | + String out = compile(in); |
| 66 | + in.close(); return out; |
| 67 | + } |
| 68 | + |
| 69 | + /** compile a Template file */ |
| 70 | + public void compile(File input, File output, String charSet) throws ParseException, IOException { |
| 71 | + BufferedReader in = null; |
| 72 | + PrintWriter out = null; |
| 73 | + try { |
| 74 | + in = new BufferedReader(new InputStreamReader(new FileInputStream(input), charSet)); |
| 75 | + out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(output), charSet)); |
| 76 | + filter(in, out); |
| 77 | + } |
| 78 | + finally { |
| 79 | + if (in != null) try { in.close(); } catch (Exception e) {} |
| 80 | + if (out != null) try { out.close(); } catch (Exception e) {} |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + //------------------------------------------------------------------------------ |
| 85 | + |
| 86 | + /** compiles what it gets line by line from the Reader into the Writer */ |
| 87 | + public void filter(BufferedReader in, PrintWriter out) throws ParseException, IOException { |
| 88 | + for (;;) { |
| 89 | + String line = in.readLine(); |
| 90 | + if (line == null) break; |
| 91 | + decorate(line, out); |
| 92 | + } |
| 93 | + //out.flush(); |
| 94 | + } |
| 95 | + |
| 96 | + /** returns the current line number */ |
| 97 | + public int getLine() { |
| 98 | + return lineNumber; |
| 99 | + } |
| 100 | + |
| 101 | + //------------------------------------------------------------------------------ |
| 102 | + |
| 103 | + /** compiles a single line */ |
| 104 | + private void decorate(String line, PrintWriter out) throws ParseException, IOException { |
| 105 | + int count = 0; |
| 106 | + while (count < line.length() && line.charAt(count) == echoChar) { |
| 107 | + ++count; |
| 108 | + } |
| 109 | + if (count >= depth) { |
| 110 | + echo(line, out); |
| 111 | + return; |
| 112 | + } |
| 113 | + char cmd; |
| 114 | + String data; |
| 115 | + if (count == depth - 1 && line.length() > count) { |
| 116 | + cmd = line.charAt(count); |
| 117 | + if (cmd == exactCmd || cmd == magicCmd) { |
| 118 | + data = line.substring(0, count) + line.substring(count + 1); |
| 119 | + } |
| 120 | + else { |
| 121 | + if ((defaultCmd == magicCmd) && hasMagic(line)) { |
| 122 | + cmd = magicCmd; |
| 123 | + } |
| 124 | + else { |
| 125 | + cmd = exactCmd; |
| 126 | + } |
| 127 | + data = line; |
| 128 | + } |
| 129 | + } |
| 130 | + else { |
| 131 | + cmd = exactCmd; |
| 132 | + data = line; |
| 133 | + } |
| 134 | + if (cmd == exactCmd || !hasMagic(data)) { |
| 135 | + exact(data, out); |
| 136 | + } |
| 137 | + else { |
| 138 | + magic(data, out); |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + private void exact(String line, PrintWriter out) throws IOException { |
| 143 | + out.print("out.println("); |
| 144 | + out.print(literal(line)); |
| 145 | + out.println(");"); |
| 146 | + } |
| 147 | + |
| 148 | + private void magic(String line, PrintWriter out) throws ParseException, IOException { |
| 149 | + Context context = new Context(out); |
| 150 | + Parser.parse(new StringReader(line), context); |
| 151 | + } |
| 152 | + |
| 153 | + private void echo(String line, PrintWriter out) throws IOException { |
| 154 | + String output = line.substring(depth); |
| 155 | + out.println(output); |
| 156 | + } |
| 157 | + |
| 158 | + private boolean hasMagic(String line) { |
| 159 | + return line.indexOf(magicIdentifier) >= 0; |
| 160 | + } |
| 161 | + |
| 162 | + /** format String as a java literal */ |
| 163 | + static String literal(String s) { |
| 164 | + StringBuffer out = new StringBuffer(); |
| 165 | + out.append('\"'); |
| 166 | + for (int i = 0; i < s.length(); ++i) { |
| 167 | + char x = s.charAt(i); |
| 168 | + // encodeTo(s.charAt(i), out); |
| 169 | + switch (x) { |
| 170 | + case '\'': out.append("\\\'"); break; |
| 171 | + case '\"': out.append("\\\""); break; |
| 172 | + case '\\': out.append("\\\\"); break; |
| 173 | + case '\t': out.append("\\t"); break; |
| 174 | + case '\n': out.append("\\n"); break; |
| 175 | + case '\r': out.append("\\r"); break; |
| 176 | + case '\f': out.append("\\f"); break; |
| 177 | + default: |
| 178 | + if (x >= 32 && x < 127) out.append(x); |
| 179 | + else { |
| 180 | + out.append("\\u"); |
| 181 | + String hex = Integer.toHexString(x); |
| 182 | + for (int j=hex.length(); j<4; j++) out.append('0'); |
| 183 | + out.append(hex); |
| 184 | + } |
| 185 | + } |
| 186 | + } |
| 187 | + out.append('\"'); |
| 188 | + return out.toString(); |
| 189 | + } |
| 190 | +} |
Property changes on: trunk/tools/commonist/src/net/psammead/minibpp/Compiler.java |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 191 | + native |
Index: trunk/tools/commonist/src/net/psammead/minibpp/A.bsh |
— | — | @@ -0,0 +1,9 @@ |
| 2 | +/* |
| 3 | +import net.psammead.minibpp.*; |
| 4 | +*/ |
| 5 | + |
| 6 | +//require("commons-logging.jar"); |
| 7 | + |
| 8 | +encoding("ISO-8859-1"); |
| 9 | + |
| 10 | +export("MiniBPP.bsh"); |
Index: trunk/tools/commonist/src/net/psammead/minibpp/README |
— | — | @@ -0,0 +1,2 @@ |
| 2 | +This package (net.psammead.minibpp) is licensed under LGPL |
| 3 | + |
Index: trunk/tools/commonist/bin/commonist |
— | — | @@ -1,4 +1,4 @@ |
2 | | -#!/bin/bash |
| 2 | +#!/bin/sh |
3 | 3 | |
4 | 4 | # change into this script's directory |
5 | 5 | if which realpath >/dev/null; then |
— | — | @@ -19,9 +19,6 @@ |
20 | 20 | # go up into the project directory |
21 | 21 | cd .. |
22 | 22 | |
23 | | -# hack for development |
24 | | -[ ! -d "build/classes" ] && ant compile |
25 | | - |
26 | 23 | # change these if you want to use a specific JDK |
27 | 24 | #export JAVA_HOME=/opt/java/jdk1.6.0_20 |
28 | 25 | #export PATH=$JAVA_HOME/bin:$PATH |
— | — | @@ -33,7 +30,7 @@ |
34 | 31 | options=-Xmx192m |
35 | 32 | |
36 | 33 | # classpath |
37 | | -classpath=build/classes:lib/scala-library.jar:lib/bsh-2.0b2-fixed.jar:lib/minibpp.jar:lib/sanselan-0.97-incubator.jar:lib/commons-httpclient-3.1.jar:lib/commons-logging-1.1.jar:lib/commons-codec-1.3.jar |
| 34 | +classpath=lib/commonist.jar:lib/scala-library.jar:lib/bsh-2.0b2-fixed.jar:lib/sanselan-0.97-incubator.jar:lib/commons-httpclient-3.1.jar:lib/commons-logging-1.1.jar:lib/commons-codec-1.3.jar |
38 | 35 | |
39 | 36 | # run VM |
40 | 37 | exec java $options -cp $classpath commonist.Commonist "$@" |
Index: trunk/tools/commonist/build.properties |
— | — | @@ -14,8 +14,9 @@ |
15 | 15 | kind=application-scala |
16 | 16 | #library= |
17 | 17 | |
18 | | -depends=minibpp |
19 | | - |
| 18 | +java.source=1.5 |
| 19 | +java.target=1.5 |
| 20 | +java.encoding=ISO-8859-1 |
20 | 21 | scala.encoding=ISO-8859-1 |
21 | 22 | |
22 | 23 | #------------------------------------------------------------------------------- |
Index: trunk/tools/commonist/etc/commonist.jnlp |
— | — | @@ -18,7 +18,6 @@ |
19 | 19 | <jar href="commonist.jar" main="true"/> |
20 | 20 | <jar href="scala-library.jar"/> |
21 | 21 | <jar href="bsh-2.0b2-fixed.jar"/> |
22 | | - <jar href="minibpp.jar"/> |
23 | 22 | <jar href="sanselan-0.97-incubator.jar"/> |
24 | 23 | <jar href="commons-logging-1.1.jar"/> |
25 | 24 | <jar href="commons-codec-1.3.jar"/> |
Property changes on: trunk/tools/commonist |
___________________________________________________________________ |
Modified: svn:ignore |
26 | 25 | - build private.properties |
27 | 26 | + build |
private.properties |