http://www.mediawiki.org/wiki/Special:Code/MediaWiki/72837

Revision: 72837
Author:   saper
Date:     2010-09-12 02:59:32 +0000 (Sun, 12 Sep 2010)

Log Message:
-----------
Update Commonist build infrasctructure

- Unpack minibpp library, provide license information (it's LGPL)
- Add missing license information in the pure Java version
- Always create a .jar file that is ready to run standalone
- Rename three Scala source files to avoid recompiling them every time
- Introduce private.properties in the Scale version

Modified Paths:
--------------
    trunk/tools/commonist/bin/commonist
    trunk/tools/commonist/build.properties
    trunk/tools/commonist/build.xml
    trunk/tools/commonist/etc/commonist.jnlp
    trunk/tools/commonist-java/build.properties
    trunk/tools/commonist-java/build.xml
    trunk/tools/commonist-java/doc/changes-libutil.txt
    trunk/tools/commonist-java/doc/changes-minibpp.txt

Added Paths:
-----------
    trunk/tools/commonist/doc/changes-minibpp.txt
    trunk/tools/commonist/lib/javacc.jar
    trunk/tools/commonist/src/net/
    trunk/tools/commonist/src/net/psammead/
    trunk/tools/commonist/src/net/psammead/minibpp/
    trunk/tools/commonist/src/net/psammead/minibpp/A.bsh
    trunk/tools/commonist/src/net/psammead/minibpp/A.java
    trunk/tools/commonist/src/net/psammead/minibpp/Compiler.java
    trunk/tools/commonist/src/net/psammead/minibpp/Context.java
    trunk/tools/commonist/src/net/psammead/minibpp/MiniBPP.bsh
    trunk/tools/commonist/src/net/psammead/minibpp/Parser.jj
    trunk/tools/commonist/src/net/psammead/minibpp/README
    trunk/tools/commonist/src/scala/commonist/api/URIData.scala
    trunk/tools/commonist/src/scala/commonist/task/upload/Upload.scala
    trunk/tools/commonist/src/scala/scutil/json/JSObject.scala
    trunk/tools/commonist/test/
    trunk/tools/commonist/test/test.bsh
    trunk/tools/commonist-java/src/net/psammead/functional/README
    trunk/tools/commonist-java/src/net/psammead/minibpp/README
    trunk/tools/commonist-java/src/net/psammead/mwapi/README
    trunk/tools/commonist-java/src/net/psammead/util/README

Removed Paths:
-------------
    trunk/tools/commonist/lib/minibpp-src.jar
    trunk/tools/commonist/lib/minibpp.jar
    trunk/tools/commonist/src/scala/commonist/api/Web.scala
    trunk/tools/commonist/src/scala/commonist/task/upload/TemplateData.scala
    trunk/tools/commonist/src/scala/scutil/json/JSON.scala

Property Changed:
----------------
    trunk/tools/commonist/
    trunk/tools/commonist/lib/bsh-2.0b2-fixed.jar
    trunk/tools/commonist/lib/commons-codec-1.3.jar
    trunk/tools/commonist/lib/commons-httpclient-3.1.jar
    trunk/tools/commonist/lib/commons-logging-1.1.jar
    trunk/tools/commonist/lib/sanselan-0.97-incubator.jar
    trunk/tools/commonist/lib/scala-library.jar


Property changes on: trunk/tools/commonist
___________________________________________________________________
Modified: svn:ignore
   - build private.properties

   + build
private.properties


Modified: trunk/tools/commonist/bin/commonist
===================================================================
--- trunk/tools/commonist/bin/commonist 2010-09-11 22:04:43 UTC (rev 72836)
+++ trunk/tools/commonist/bin/commonist 2010-09-12 02:59:32 UTC (rev 72837)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # change into this script's directory
 if which realpath >/dev/null; then
@@ -19,9 +19,6 @@
 # go up into the project directory
 cd ..
 
-# hack for development
-[ ! -d "build/classes" ] && ant compile 
-
 # change these if you want to use a specific JDK
 #export JAVA_HOME=/opt/java/jdk1.6.0_20
 #export PATH=$JAVA_HOME/bin:$PATH
@@ -33,7 +30,7 @@
 options=-Xmx192m
 
 # classpath
-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
+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
 
 # run VM
 exec java $options -cp $classpath commonist.Commonist "$@"

Modified: trunk/tools/commonist/build.properties
===================================================================
--- trunk/tools/commonist/build.properties      2010-09-11 22:04:43 UTC (rev 
72836)
+++ trunk/tools/commonist/build.properties      2010-09-12 02:59:32 UTC (rev 
72837)
@@ -14,8 +14,9 @@
 kind=application-scala
 #library=
 
-depends=minibpp
-
+java.source=1.5
+java.target=1.5
+java.encoding=ISO-8859-1
 scala.encoding=ISO-8859-1
 
 
#-------------------------------------------------------------------------------

Modified: trunk/tools/commonist/build.xml
===================================================================
--- trunk/tools/commonist/build.xml     2010-09-11 22:04:43 UTC (rev 72836)
+++ trunk/tools/commonist/build.xml     2010-09-12 02:59:32 UTC (rev 72837)
@@ -28,15 +28,42 @@
                <pathelement location="${scala.compiler}"/>
        </path>
        
+       <path id="scala.source.dirs">
+               <pathelement location="src/scala" />
+       </path>
+
+       <path id="java.source.dirs">
+               <pathelement location="src" />
+               <pathelement location="build/src" />
+       </path>
+
+       <fileset id="runtime.libraries" dir="lib">
+               <patternset id="runtime.jars">
+                       <include name="bsh-2.0b2-fixed.jar" />
+                       <include name="commons-httpclient-3.1.jar" />
+                       <include name="commons-codec-1.3.jar" />
+                       <include name="commons-logging-1.1.jar" />
+                       <include name="sanselan-0.97-incubator.jar" />
+                       <include name="scala-library.jar" />
+               </patternset>
+       </fileset>
+
+       <fileset id="compile.libraries" dir="lib">
+               <patternset refid="runtime.jars" />
+               <include name="javacc.jar" />
+       </fileset>
+
+       <patternset id="product.jars">
+               <patternset refid="runtime.jars" />
+               <include name="${project}.jar" />
+       </patternset>
+
        <path id="build.classpath">
                <pathelement location="${scala.library}"/>
-               <fileset dir="lib"/>
+               <pathelement location="build/classes" />
+               <fileset refid="compile.libraries" />
        </path>
-       
-       <!-- project specifics -->
-       <property name="source.jars"    value="minibpp-src.jar"/>
-       <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"/>
-         
+
        <!-- ==== main  ==== -->
        
        <target name="clean" description="deletes everything that can be 
rebuilt">
@@ -55,19 +82,39 @@
                </replace>
        </target>
        -->
+
+       <target name="parser" description="create the parser sources">
+               <mkdir dir="build/src/net/psammead/minibpp/parser"/>
+               <javacc
+                       target="src/net/psammead/minibpp/Parser.jj"
+                       outputdirectory="build/src/net/psammead/minibpp/parser"
+                       javacchome="lib"
+                       unicodeinput="true"
+                       static="false"
+               />
+       </target>
        
-       <target name="compile" description="compiles scala classes">
+       <target name="compile" depends="parser" description="compiles scala 
classes">
                <mkdir dir="build/classes"/>
+               <javac
+                       destdir="build/classes"
+                       source="${java.source}"
+                       target="${java.target}"
+                       encoding="${java.encoding}"
+                       deprecation="true"
+                       classpathref="build.classpath"
+                       debug="true">
+                               <src refid="java.source.dirs" />
+                               <include name="**/*.java" />
+               </javac>
                <scalac 
-                       srcdir="src/scala" 
                        destdir="build/classes" 
                        encoding="${scala.encoding}" 
                        classpathref="build.classpath"
                        deprecation="yes"
-                       unchecked="yes"
-               >
-                       <!-- addparams -->
-                       <include name="**/*.scala"/>
+                       unchecked="yes">
+                               <src refid="scala.source.dirs" />
+                               <include name="**/*.scala" />
                </scalac>
        </target>
        
@@ -92,10 +139,8 @@
                                <attribute name="Creator"               
value="${author}"/>
                                <attribute name="License"               
value="${license}"/>
                                
-                               <!-- 
-                               TODO: use a property, add binary.jars to 
classpath (manifestclasspath from ant 1.7.0)
-                               <attribute name="Main-Class"    
value="net.psammead.commonist.Commonist"/>
-                               -->
+                               <attribute name="Main-Class"    
value="commonist.Commonist"/>
+                               <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" />
                        </manifest>
                </jar>
        </target>
@@ -110,22 +155,24 @@
        
        <!-- ==== full dist ==== -->
        
-       <target name="dist" depends="compile" description="create a 
distribution zip">
+       <target name="dist" depends="jar" description="create a distribution 
zip">
                <mkdir dir="build"/>
                <zip destfile="build/${project}-${version}.zip">
                        <zipfileset dir="." prefix="${project}-${version}" 
filemode="770">
                                <include name="bin/*"/> 
                        </zipfileset>
+                       <zipfileset dir="build/jar" 
prefix="${project}-${version}/lib">
+                               <include name="commonist.jar" />
+                       </zipfileset>
                        <zipfileset dir="." prefix="${project}-${version}">
                                <include name="doc/index.html"/>
                                <include name="doc/changes.txt"/>
-                               <include name="build.*"/>
-                               <include name="src/scala/**"/>
+                               <include name="doc/changes-minibpp.txt"/>
+                               <include name="src/**"/>
                                <include name="etc/**"/>
                                <exclude name="${sign.keystore}"/>
                                <include name="image/**"/>
                                <include name="lib/**"/>
-                               <include name="build/classes/**"/>
                        </zipfileset>
                </zip>
        </target>
@@ -151,7 +198,9 @@
                        <zipfileset dir="etc"           includes="PkgInfo"      
                        prefix="${mac.app}/Contents"/>
                        <zipfileset dir="build/etc"     includes="Info.plist"   
                prefix="${mac.app}/Contents"/>
                        <zipfileset dir="image"         
includes="${mac.bundle.icons}"  prefix="${mac.app}/Contents/Resources"/>
-                       <zipfileset dir="lib"           
includes="${binary.jars}"               
prefix="${mac.app}/Contents/Resources/Java"/>
+                       <zipfileset dir="lib" 
prefix="${mac.app}/Contents/Resources/Java">
+                               <fileset refid="runtime.libraries" />
+                       </zipfileset>
                        <zipfileset dir="build/jar"     
includes="${project}.jar"               
prefix="${mac.app}/Contents/Resources/Java"/>
                </zip>
        </target>
@@ -168,8 +217,9 @@
                <mkdir dir="build/ws"/>
                <copy toDir="build/ws">
                        <fileset dir="build/jar"/>
-                       <fileset dir="lib" includes="${binary.jars}"/>
+                       <fileset refid="runtime.libraries" />
                </copy>
+               <fail unless="sign.alias" message="Please create 
private.properties file and include sign.alias, sign.storepass, sign.keypass 
properties there."/>
                <signjar 
                        alias="${sign.alias}"
                        storepass="${sign.storepass}"
@@ -177,7 +227,9 @@
                        keypass="${sign.keypass}"
                >
                        <!-- jar="build/signed-jar/${project}.jar" -->
-                       <fileset dir="build/ws" includes="*.jar"/>
+                       <fileset dir="build/ws">
+                               <patternset refid="product.jars" />
+                       </fileset>
                </signjar>
        </target>
        
@@ -198,7 +250,7 @@
                <zip destfile="build/${project}-${version}-ws.zip">
                        <zipfileset dir="build/ws">
                                <include name="${ws.jnlp}"/>
-                               <include name="*.jar"/>
+                               <patternset refid="product.jars" />
                        </zipfileset>
                        <zipfileset dir="image">
                                <include name="${ws.icon}"/>
@@ -206,23 +258,4 @@
                        </zipfileset>
                </zip>
        </target>
-       
-       <!-- ==== export ==== -->
-
-       <target name="import" description="import artefacts from other 
projects">
-               <ant dir="../minibpp" antfile="build.xml" target="export" 
inheritAll="false"/>
-               <copy toDir="lib">
-                       <fileset dir="../minibpp/build/export" 
includes="minibpp.jar,minibpp-src.jar"/>
-               </copy>
-       </target>
-       
-       <target name="export" depends="doc,dist,ws-dist" description="create 
artefacts">
-               <property name="export.dir" value="build/export"/>
-               <mkdir dir="${export.dir}"/>
-               <copy todir="${export.dir}">
-                       <fileset dir="build/doc"        
includes="changes.txt,index.html"/>
-                       <fileset dir="build"            
includes="${project}-${version}.zip"/>
-               </copy>
-               <unzip src="build/${project}-${version}-ws.zip" 
dest="${export.dir}/ws" overwrite="true"/>
-       </target>
 </project>

Added: trunk/tools/commonist/doc/changes-minibpp.txt
===================================================================
--- trunk/tools/commonist/doc/changes-minibpp.txt                               
(rev 0)
+++ trunk/tools/commonist/doc/changes-minibpp.txt       2010-09-12 02:59:32 UTC 
(rev 72837)
@@ -0,0 +1,8 @@
+0.0.3
+
+0.0.2
+       fixed OOME for escaped unicode characters
+       added A.class and A.bsh for use with useModule.bsh
+
+0.0.1  
+       initial release


Property changes on: trunk/tools/commonist/doc/changes-minibpp.txt
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: trunk/tools/commonist/etc/commonist.jnlp
===================================================================
--- trunk/tools/commonist/etc/commonist.jnlp    2010-09-11 22:04:43 UTC (rev 
72836)
+++ trunk/tools/commonist/etc/commonist.jnlp    2010-09-12 02:59:32 UTC (rev 
72837)
@@ -18,7 +18,6 @@
                <jar href="commonist.jar" main="true"/>
                <jar href="scala-library.jar"/>
                <jar href="bsh-2.0b2-fixed.jar"/>
-               <jar href="minibpp.jar"/>
                <jar href="sanselan-0.97-incubator.jar"/>
                <jar href="commons-logging-1.1.jar"/>
                <jar href="commons-codec-1.3.jar"/>


Property changes on: trunk/tools/commonist/lib/bsh-2.0b2-fixed.jar
___________________________________________________________________
Modified: svn:mime-type
   - application/octet-stream
   + application/java-archive


Property changes on: trunk/tools/commonist/lib/commons-codec-1.3.jar
___________________________________________________________________
Modified: svn:mime-type
   - application/octet-stream
   + application/java-archive


Property changes on: trunk/tools/commonist/lib/commons-httpclient-3.1.jar
___________________________________________________________________
Modified: svn:mime-type
   - application/octet-stream
   + application/java-archive


Property changes on: trunk/tools/commonist/lib/commons-logging-1.1.jar
___________________________________________________________________
Modified: svn:mime-type
   - application/octet-stream
   + application/java-archive

Added: trunk/tools/commonist/lib/javacc.jar
===================================================================
(Binary files differ)


Property changes on: trunk/tools/commonist/lib/javacc.jar
___________________________________________________________________
Added: svn:mime-type
   + application/java-archive

Deleted: trunk/tools/commonist/lib/minibpp-src.jar
===================================================================
(Binary files differ)

Deleted: trunk/tools/commonist/lib/minibpp.jar
===================================================================
(Binary files differ)


Property changes on: trunk/tools/commonist/lib/sanselan-0.97-incubator.jar
___________________________________________________________________
Modified: svn:mime-type
   - application/octet-stream
   + application/java-archive


Property changes on: trunk/tools/commonist/lib/scala-library.jar
___________________________________________________________________
Modified: svn:mime-type
   - application/octet-stream
   + application/java-archive

Added: trunk/tools/commonist/src/net/psammead/minibpp/A.bsh
===================================================================
--- trunk/tools/commonist/src/net/psammead/minibpp/A.bsh                        
        (rev 0)
+++ trunk/tools/commonist/src/net/psammead/minibpp/A.bsh        2010-09-12 
02:59:32 UTC (rev 72837)
@@ -0,0 +1,9 @@
+/*
+import net.psammead.minibpp.*;
+*/
+
+//require("commons-logging.jar");
+
+encoding("ISO-8859-1");
+
+export("MiniBPP.bsh");

Added: trunk/tools/commonist/src/net/psammead/minibpp/A.java
===================================================================
--- trunk/tools/commonist/src/net/psammead/minibpp/A.java                       
        (rev 0)
+++ trunk/tools/commonist/src/net/psammead/minibpp/A.java       2010-09-12 
02:59:32 UTC (rev 72837)
@@ -0,0 +1,4 @@
+package net.psammead.minibpp;
+
+/** Anchor class used to find our scripts */
+public final class A {}


Property changes on: trunk/tools/commonist/src/net/psammead/minibpp/A.java
___________________________________________________________________
Added: svn:eol-style
   + native

Added: trunk/tools/commonist/src/net/psammead/minibpp/Compiler.java
===================================================================
--- trunk/tools/commonist/src/net/psammead/minibpp/Compiler.java                
                (rev 0)
+++ trunk/tools/commonist/src/net/psammead/minibpp/Compiler.java        
2010-09-12 02:59:32 UTC (rev 72837)
@@ -0,0 +1,189 @@
+package net.psammead.minibpp;
+
+import java.io.*;
+import net.psammead.minibpp.parser.Parser;
+import net.psammead.minibpp.parser.ParseException;
+
+/** compiles one level of BeanShellPP syntax */
+public class Compiler {
+       /** compiles from stdin to stdout with the system default encoding */
+       public static void main(String[] args) throws ParseException, 
IOException {
+               // no error handling necessary ;)
+               BufferedReader  in      = new BufferedReader(new 
InputStreamReader(System.in));
+               PrintWriter             out     = new PrintWriter(new 
OutputStreamWriter(System.out));
+               Compiler                c       = new Compiler();
+               c.filter(in, out);
+               in.close();
+               out.close();
+       }
+        
+       
//------------------------------------------------------------------------------
+       
+       private int             depth;
+       private int             lineNumber;
+
+       private char    echoChar                = '#';
+       private char    exactCmd                = '\'';
+       private char    magicCmd                = '\"';
+       private char    defaultCmd              = '\"';
+       private char    magicIdentifier = '$';
+
+       
//------------------------------------------------------------------------------
+       
+       /** default constructor with depth 1 */
+       public Compiler() {
+               this(1);
+       }
+
+       /** no idea what depth means. 0 does nothing, 1 compiles one level of # 
*/
+       public Compiler(int depth) {
+               this.depth      = depth;
+               lineNumber      = 0;
+       }
+       
+       /** compile a Template from a Reader into a String. the reader will not 
be closed! */
+       public String compile(Reader in) throws ParseException, IOException {
+               BufferedReader  br      = new BufferedReader(in);
+               StringWriter    sw      = new StringWriter();
+               PrintWriter             pw      = new PrintWriter(sw);
+               filter(br, pw);
+               pw.close();
+               return sw.toString();
+       }
+       
+       /** compiles a template in String form */
+       public String compile(String template) throws ParseException, 
IOException {
+               Reader  in      = new StringReader(template);
+               String  out     = compile(in);
+               in.close();     return out;
+       }
+       
+       /** compile a Template from a File into a String. */
+       public String compile(File file, String charSet) throws ParseException, 
IOException {
+               Reader  in      = new InputStreamReader(new 
FileInputStream(file), charSet);
+               String  out     = compile(in);
+               in.close();     return out;
+       }
+       
+       /** compile a Template file */
+       public void compile(File input, File output, String charSet) throws 
ParseException, IOException {
+               BufferedReader  in      = null;
+               PrintWriter             out     = null;
+               try {
+                       in      = new BufferedReader(new InputStreamReader(new 
FileInputStream(input), charSet));
+                       out     = new PrintWriter(new OutputStreamWriter(new 
FileOutputStream(output), charSet));
+                       filter(in, out);
+               }
+               finally {
+                       if (in  != null)        try { in.close(); }             
catch (Exception e) {}
+                       if (out != null)        try { out.close(); }    catch 
(Exception e) {}
+               }
+       }
+
+       
//------------------------------------------------------------------------------
+       
+       /** compiles what it gets line by line from the Reader into the Writer 
*/
+       public void filter(BufferedReader in, PrintWriter out) throws 
ParseException, IOException {
+               for (;;) {
+                       String line = in.readLine();
+                       if (line == null)       break;
+                       decorate(line, out);
+               }
+               //out.flush();
+       }
+
+       /** returns the current line number */
+       public int getLine() {
+               return lineNumber;
+       }
+
+       
//------------------------------------------------------------------------------
+       
+       /** compiles a single line */
+       private void decorate(String line, PrintWriter out) throws 
ParseException, IOException {
+               int count = 0;
+               while (count < line.length() && line.charAt(count) == echoChar) 
{
+                       ++count;
+               }
+               if (count >= depth) {
+                       echo(line, out);
+                       return;
+               }
+               char    cmd;
+               String  data;
+               if (count == depth - 1 && line.length() > count) {
+                       cmd = line.charAt(count);
+                       if (cmd == exactCmd || cmd == magicCmd) {
+                               data    = line.substring(0, count) + 
line.substring(count + 1);
+                       }
+                       else {
+                               if ((defaultCmd == magicCmd) && hasMagic(line)) 
{
+                                       cmd     = magicCmd;
+                               }
+                               else {
+                                       cmd     = exactCmd;
+                               }
+                               data = line;
+                       }
+               }
+               else {
+                       cmd             = exactCmd;
+                       data    = line;
+               }
+               if (cmd == exactCmd || !hasMagic(data)) {
+                       exact(data, out);
+               }
+               else {
+                       magic(data, out);
+               }
+       }
+
+       private void exact(String line, PrintWriter out) throws IOException {
+               out.print("out.println(");
+               out.print(literal(line));
+               out.println(");");
+       }
+
+       private void magic(String line, PrintWriter out) throws ParseException, 
IOException {
+               Context context = new Context(out);
+               Parser.parse(new StringReader(line), context);
+       }
+
+       private void echo(String line, PrintWriter out) throws IOException {
+               String output = line.substring(depth);
+               out.println(output);
+       }
+
+       private boolean hasMagic(String line) {
+               return line.indexOf(magicIdentifier) >= 0;
+       }
+       
+       /** format String as a java literal */
+       static String literal(String s) {
+               StringBuffer out = new StringBuffer();
+               out.append('\"');
+               for (int i = 0; i < s.length(); ++i) {
+                       char    x       = s.charAt(i);
+                       // encodeTo(s.charAt(i), out);
+                       switch (x) {
+                               case '\'':      out.append("\\\'");     break;
+                               case '\"':      out.append("\\\"");     break;
+                               case '\\':      out.append("\\\\");     break;
+                               case '\t':      out.append("\\t");      break;
+                               case '\n':      out.append("\\n");      break;
+                               case '\r':      out.append("\\r");      break;
+                               case '\f':      out.append("\\f");      break;
+                               default:
+                                       if (x >= 32 && x < 127) out.append(x);
+                                       else {
+                                               out.append("\\u");
+                                               String  hex     = 
Integer.toHexString(x);
+                                               for (int j=hex.length(); j<4; 
j++)      out.append('0');
+                                               out.append(hex);
+                                       }
+                       }
+               }
+               out.append('\"');
+               return out.toString();
+       }
+}


Property changes on: 
trunk/tools/commonist/src/net/psammead/minibpp/Compiler.java
___________________________________________________________________
Added: svn:eol-style
   + native

Added: trunk/tools/commonist/src/net/psammead/minibpp/Context.java
===================================================================
--- trunk/tools/commonist/src/net/psammead/minibpp/Context.java                 
        (rev 0)
+++ trunk/tools/commonist/src/net/psammead/minibpp/Context.java 2010-09-12 
02:59:32 UTC (rev 72837)
@@ -0,0 +1,57 @@
+package net.psammead.minibpp;
+
+import java.io.*;
+
+/** 
+  * Context for the parser generated by JavaCC<br>
+  * Internal bridge between a Compiler and a Parser
+  */
+public final class Context {
+       private PrintWriter     out;
+       private String          content;
+       private boolean         bol;
+       
+       public Context(PrintWriter out) {
+               this.out        = out;
+               content         = null;
+               bol                     = true;
+       }
+
+       public void magic(String s) {
+               emit();
+               content = s;
+       }
+
+       public void literal(String s) {
+               emit();
+               content = Compiler.literal(s);
+       }
+
+       public void done() {
+               out.print("out.println(");
+               if (content != null) {
+                       out.print(content);
+               }
+               if (bol) {
+                       out.println(");");
+               }
+               else {
+                       out.println(");}");
+               }
+               content = null;
+               bol             = true;
+       }
+
+       private void emit() {
+               if (bol) {
+                       out.print("{");
+                       bol     = false;
+               }
+               if (content != null) {
+                       out.print("out.print(");
+                       out.print(content);
+                       out.print(");");
+                       content = null;
+               }
+       }
+}


Property changes on: trunk/tools/commonist/src/net/psammead/minibpp/Context.java
___________________________________________________________________
Added: svn:eol-style
   + native

Added: trunk/tools/commonist/src/net/psammead/minibpp/MiniBPP.bsh
===================================================================
--- trunk/tools/commonist/src/net/psammead/minibpp/MiniBPP.bsh                  
        (rev 0)
+++ trunk/tools/commonist/src/net/psammead/minibpp/MiniBPP.bsh  2010-09-12 
02:59:32 UTC (rev 72837)
@@ -0,0 +1,26 @@
+/** compile a template file into a String */
+String template(var file, String charSet) {
+       var     in              = new BufferedReader(new InputStreamReader(new 
FileInputStream(file), charSet));
+       var     tmpl    = new net.psammead.minibpp.Compiler().compile(in);
+       in.close();     return tmpl;
+}
+
+/** compile a template into a String */
+private String templateRelative(var file, String charSet) {
+       // see sourceRelative command
+       var     file    = pathToFile(dirname(getSourceFileInfo()) + 
File.separator + file);
+       return new net.psammead.minibpp.Compiler().compile(file, charSet);
+}
+
+// und die bpp_redirect dinger w\xE4ren hier praktisch
+
+/*
+evalTemplate( 
+
+Object eval( String expression ) {
+    return this.interpreter.eval( expression, this.caller.namespace );
+}
+
+// compile and source template
+eval(templateRelative("template.bpp", "ISO-8859-1"));
+*/

Added: trunk/tools/commonist/src/net/psammead/minibpp/Parser.jj
===================================================================
--- trunk/tools/commonist/src/net/psammead/minibpp/Parser.jj                    
        (rev 0)
+++ trunk/tools/commonist/src/net/psammead/minibpp/Parser.jj    2010-09-12 
02:59:32 UTC (rev 72837)
@@ -0,0 +1,135 @@
+options { UNICODE_INPUT=true; STATIC=false; }
+
+PARSER_BEGIN(Parser)
+    package net.psammead.minibpp.parser;
+
+    import java.io.*;
+       import net.psammead.minibpp.Context;
+       
+    public class Parser {
+        Context pp;
+       public static void parse(Reader r, Context _pp) throws ParseException, 
IOException {
+         Parser p = new Parser(r);
+         p.pp=_pp;
+          p.Line();
+          p.pp.done();
+       }
+    }  
+
+PARSER_END(Parser)
+
+TOKEN_MGR_DECLS :
+{
+  static int pcount;
+}
+
+<DEFAULT> TOKEN: { < PLAIN : (~[])  > }
+<DEFAULT> TOKEN: { < PLAIN_DOLLAR : "$$" > { 
+       matchedToken.image="$"; matchedToken.kind=PLAIN; 
+} }
+<DEFAULT> TOKEN: { < LPAREN : "$(" > { matchedToken.image="("; pcount=1; } : 
JAVA }
+<DEFAULT> TOKEN : { 
+  < IDENTIFIER: "$" <LETTER> (<LETTER>|<DIGIT>)* > 
+|
+  < #LETTER:
+      [
+       "\u0041"-"\u005a",
+       "\u005f",
+       "\u0061"-"\u007a",
+       "\u00c0"-"\u00d6",
+       "\u00d8"-"\u00f6",
+       "\u00f8"-"\u00ff",
+       "\u0100"-"\u1fff",
+       "\u3040"-"\u318f",
+       "\u3300"-"\u337f",
+       "\u3400"-"\u3d2d",
+       "\u4e00"-"\u9fff",
+       "\uf900"-"\ufaff"
+      ]
+  >
+|
+  < #DIGIT:
+      [
+       "\u0030"-"\u0039",
+       "\u0660"-"\u0669",
+       "\u06f0"-"\u06f9",
+       "\u0966"-"\u096f",
+       "\u09e6"-"\u09ef",
+       "\u0a66"-"\u0a6f",
+       "\u0ae6"-"\u0aef",
+       "\u0b66"-"\u0b6f",
+       "\u0be7"-"\u0bef",
+       "\u0c66"-"\u0c6f",
+       "\u0ce6"-"\u0cef",
+       "\u0d66"-"\u0d6f",
+       "\u0e50"-"\u0e59",
+       "\u0ed0"-"\u0ed9",
+       "\u1040"-"\u1049"
+      ]
+  >
+}
+
+<NOWHERE> TOKEN: { < RPAREN: ")" > }
+<JAVA> TOKEN: { < JLPAREN : "(" > { ++pcount; matchedToken.kind=JPLAIN; } }
+<JAVA> TOKEN: { < JRPAREN : ")" > { 
+  --pcount; 
+  if (pcount == 0) {
+    SwitchTo(DEFAULT);
+    matchedToken.kind=RPAREN;
+  } else {
+    matchedToken.kind=JPLAIN;
+  }
+} }
+
+<JAVA> TOKEN : { < JPLAIN : (~["\"","\'","\n","\r","(",")"])+ > }
+<JAVA> TOKEN : { < JCHAR : 
+      "'"
+      (   (~["'","\\","\n","\r"])
+        | ("\\"
+            ( ["n","t","b","r","f","\\","'","\""]
+            | ["0"-"7"] ( ["0"-"7"] )?
+            | ["0"-"3"] ["0"-"7"] ["0"-"7"]
+            )
+          )
+      )
+      "'"
+> { matchedToken.kind=JPLAIN; } }
+<JAVA> TOKEN : { < JSTRING : 
+      "\""
+      (   (~["\"","\\","\n","\r"])
+        | ("\\"
+            ( ["n","t","b","r","f","\\","'","\""]
+            | ["0"-"7"] ( ["0"-"7"] )?
+            | ["0"-"3"] ["0"-"7"] ["0"-"7"]
+            )
+          )
+      )*
+      "\""
+> { matchedToken.kind=JPLAIN; } }
+
+void Line() throws IOException :
+{ StringBuffer sb=new StringBuffer(); Token t; StringBuffer m; }
+{
+  ( 
+    t=<PLAIN> { sb.append(t.image);} 
+  | 
+    m=Magic() { 
+//      if (m.length()==0) { sb.append("$"); }
+//      else {
+        if (sb.length()>0) { pp.literal(sb.toString()); sb=new StringBuffer(); 
}
+       pp.magic(m.toString());
+//      }
+    }
+  ) * <EOF>
+  { if (sb.length() > 0) pp.literal(sb.toString()); }
+}
+
+StringBuffer Magic() throws IOException :
+{ StringBuffer sb=new StringBuffer(); Token t; }
+{
+  t=<IDENTIFIER> { sb.append(t.image.substring(1)); return sb; }
+| 
+  ( t=<LPAREN> 
+    ( t=<JPLAIN> { sb.append(t.image); } ) * 
+    t=<RPAREN> { return sb; } )
+} 

Added: trunk/tools/commonist/src/net/psammead/minibpp/README
===================================================================
--- trunk/tools/commonist/src/net/psammead/minibpp/README                       
        (rev 0)
+++ trunk/tools/commonist/src/net/psammead/minibpp/README       2010-09-12 
02:59:32 UTC (rev 72837)
@@ -0,0 +1,2 @@
+This package (net.psammead.minibpp) is licensed under LGPL
+

Copied: trunk/tools/commonist/src/scala/commonist/api/URIData.scala (from rev 
72836, trunk/tools/commonist/src/scala/commonist/api/Web.scala)
===================================================================
--- trunk/tools/commonist/src/scala/commonist/api/URIData.scala                 
        (rev 0)
+++ trunk/tools/commonist/src/scala/commonist/api/URIData.scala 2010-09-12 
02:59:32 UTC (rev 72837)
@@ -0,0 +1,93 @@
+package commonist.api
+
+import java.net.URI
+
+import scala.collection.JavaConversions._
+
+import scutil.ext.AnyRefExt._
+
+/*
+[scheme:][//authority][path][?query][#fragment] 
+[user-i...@]host[:port] 
+*/
+object URIData {
+       def parse(str:String):URIData = parse(new URI(str))
+       def parse(uri:URI):URIData = new URIData(
+               uri.getScheme.nullOption,
+               uri.getAuthority.nullOption,
+               uri.getPath.nullOption,
+               uri.getQuery.nullOption,
+               uri.getFragment.nullOption,
+               uri.getUserInfo.nullOption,
+               uri.getHost.nullOption,
+               uri.getPort match { case -1 => None; case x => Some(x) }
+       )
+}
+case class URIData(
+       scheme:Option[String],
+       authority:Option[String],
+       path:Option[String],
+       query:Option[String],
+       fragment:Option[String],
+       userInfo:Option[String],
+       host:Option[String],
+       port:Option[Int]
+) {
+       def target:Option[Target]       =
+                       for {
+                               sch     <- scheme
+                               hst     <- host
+                               prt     <- port orElse defaultPort
+                       } yield {
+                               Target(hst, prt)
+                       }
+       def cred:Option[Cred]   =
+                       userInfo map { it =>
+                               it indexOf (':') match {
+                                       case -1 => Cred(it, "")
+                                       case x  => Cred(it.substring(0,x), 
it.substring(x+1))
+                               }
+                       }
+       def defaultPort:Option[Int] = 
+                       scheme map { _ match { 
+                               case "http"             => 80   
+                               case "https"    => 443
+                               case x                  => error("unexpected 
scheme: " + x)
+                       } }
+}
+
+case class Target(host:String, port:Int)       
+case class Cred(user:String, password:String)
+
+case class Proxy(target:Target, cred:Option[Cred], 
noproxy:Option[Target=>Boolean])
+object Proxy {
+       def systemProperties:Option[Proxy] = {
+               val     sysProps:scala.collection.mutable.Map[String,String]    
= System.getProperties
+               for {
+                       host    <- sysProps get "http.proxyHost"
+                       port    <- sysProps get "http.proxyPort"
+               }
+               yield {
+                       val     target  = Target(host, Integer.parseInt(port))
+                       val noproxy     = sysProps get ("http.nonProxyHosts") 
map NoProxy.sun _
+                       Proxy(target, None, noproxy)
+               }
+       }
+       
+       def environmentVariable:Option[Proxy] =
+                       for {
+                               http_proxy      <- 
System.getenv("http_proxy").nullOption
+                               val data        = URIData.parse(http_proxy)
+                               target          <- data.target
+                       } 
+                       yield {
+                               Proxy(target, data.cred, None)
+                       }
+}
+
+object NoProxy {
+       def all(target:Target):Boolean  = false
+       
+       /** like suns format, f.e. "*.test.de|localhost" */
+       def sun(re:String)(target:Target):Boolean       =  target.host matches 
re.replaceAll("\\.", "\\\\.").replaceAll("\\*", ".*?")
+}

Deleted: trunk/tools/commonist/src/scala/commonist/api/Web.scala
===================================================================
--- trunk/tools/commonist/src/scala/commonist/api/Web.scala     2010-09-11 
22:04:43 UTC (rev 72836)
+++ trunk/tools/commonist/src/scala/commonist/api/Web.scala     2010-09-12 
02:59:32 UTC (rev 72837)
@@ -1,93 +0,0 @@
-package commonist.api
-
-import java.net.URI
-
-import scala.collection.JavaConversions._
-
-import scutil.ext.AnyRefExt._
-
-/*
-[scheme:][//authority][path][?query][#fragment] 
-[user-i...@]host[:port] 
-*/
-object URIData {
-       def parse(str:String):URIData = parse(new URI(str))
-       def parse(uri:URI):URIData = new URIData(
-               uri.getScheme.nullOption,
-               uri.getAuthority.nullOption,
-               uri.getPath.nullOption,
-               uri.getQuery.nullOption,
-               uri.getFragment.nullOption,
-               uri.getUserInfo.nullOption,
-               uri.getHost.nullOption,
-               uri.getPort match { case -1 => None; case x => Some(x) }
-       )
-}
-case class URIData(
-       scheme:Option[String],
-       authority:Option[String],
-       path:Option[String],
-       query:Option[String],
-       fragment:Option[String],
-       userInfo:Option[String],
-       host:Option[String],
-       port:Option[Int]
-) {
-       def target:Option[Target]       =
-                       for {
-                               sch     <- scheme
-                               hst     <- host
-                               prt     <- port orElse defaultPort
-                       } yield {
-                               Target(hst, prt)
-                       }
-       def cred:Option[Cred]   =
-                       userInfo map { it =>
-                               it indexOf (':') match {
-                                       case -1 => Cred(it, "")
-                                       case x  => Cred(it.substring(0,x), 
it.substring(x+1))
-                               }
-                       }
-       def defaultPort:Option[Int] = 
-                       scheme map { _ match { 
-                               case "http"             => 80   
-                               case "https"    => 443
-                               case x                  => error("unexpected 
scheme: " + x)
-                       } }
-}
-
-case class Target(host:String, port:Int)       
-case class Cred(user:String, password:String)
-
-case class Proxy(target:Target, cred:Option[Cred], 
noproxy:Option[Target=>Boolean])
-object Proxy {
-       def systemProperties:Option[Proxy] = {
-               val     sysProps:scala.collection.mutable.Map[String,String]    
= System.getProperties
-               for {
-                       host    <- sysProps get "http.proxyHost"
-                       port    <- sysProps get "http.proxyPort"
-               }
-               yield {
-                       val     target  = Target(host, Integer.parseInt(port))
-                       val noproxy     = sysProps get ("http.nonProxyHosts") 
map NoProxy.sun _
-                       Proxy(target, None, noproxy)
-               }
-       }
-       
-       def environmentVariable:Option[Proxy] =
-                       for {
-                               http_proxy      <- 
System.getenv("http_proxy").nullOption
-                               val data        = URIData.parse(http_proxy)
-                               target          <- data.target
-                       } 
-                       yield {
-                               Proxy(target, data.cred, None)
-                       }
-}
-
-object NoProxy {
-       def all(target:Target):Boolean  = false
-       
-       /** like suns format, f.e. "*.test.de|localhost" */
-       def sun(re:String)(target:Target):Boolean       =  target.host matches 
re.replaceAll("\\.", "\\\\.").replaceAll("\\*", ".*?")
-}

Deleted: 
trunk/tools/commonist/src/scala/commonist/task/upload/TemplateData.scala
===================================================================
--- trunk/tools/commonist/src/scala/commonist/task/upload/TemplateData.scala    
2010-09-11 22:04:43 UTC (rev 72836)
+++ trunk/tools/commonist/src/scala/commonist/task/upload/TemplateData.scala    
2010-09-12 02:59:32 UTC (rev 72837)
@@ -1,38 +0,0 @@
-package commonist.task.upload
-
-import commonist.data._
-
-import scala.reflect.BeanProperty
-
-case class Common(
-       @BeanProperty description:String,
-       @BeanProperty date:String,
-       @BeanProperty source:String,
-       @BeanProperty author:String,
-       @BeanProperty licenseTemplate:String,
-       @BeanProperty licenseDescription:String,
-       @BeanProperty categories:String
-)
-
-case class Batch(
-       @BeanProperty uploads:java.util.List[Upload],
-       @BeanProperty successes:java.util.List[Upload],
-       @BeanProperty failures:java.util.List[Upload]
-) 
-
-case class Upload(
-       @BeanProperty name:String,                      // without the File 
namespace
-       @BeanProperty title:String,                     // to be used in a link
-       @BeanProperty error:String,                     // null if upload went 
ok
-       @BeanProperty previous:String,          // null for the first
-       @BeanProperty next:String,                      // null for the last
-       
-       @BeanProperty description:String,
-       @BeanProperty date:String,
-       @BeanProperty permission:String,
-       @BeanProperty categories:String,
-       
-       @BeanProperty coordinates:String,       // raw string
-       @BeanProperty latitude:String,          // null if raw string could not 
be parsed
-       @BeanProperty longitude:String          // null if raw string could not 
be parsed
-)

Copied: trunk/tools/commonist/src/scala/commonist/task/upload/Upload.scala 
(from rev 72836, 
trunk/tools/commonist/src/scala/commonist/task/upload/TemplateData.scala)
===================================================================
--- trunk/tools/commonist/src/scala/commonist/task/upload/Upload.scala          
                (rev 0)
+++ trunk/tools/commonist/src/scala/commonist/task/upload/Upload.scala  
2010-09-12 02:59:32 UTC (rev 72837)
@@ -0,0 +1,38 @@
+package commonist.task.upload
+
+import commonist.data._
+
+import scala.reflect.BeanProperty
+
+case class Common(
+       @BeanProperty description:String,
+       @BeanProperty date:String,
+       @BeanProperty source:String,
+       @BeanProperty author:String,
+       @BeanProperty licenseTemplate:String,
+       @BeanProperty licenseDescription:String,
+       @BeanProperty categories:String
+)
+
+case class Batch(
+       @BeanProperty uploads:java.util.List[Upload],
+       @BeanProperty successes:java.util.List[Upload],
+       @BeanProperty failures:java.util.List[Upload]
+) 
+
+case class Upload(
+       @BeanProperty name:String,                      // without the File 
namespace
+       @BeanProperty title:String,                     // to be used in a link
+       @BeanProperty error:String,                     // null if upload went 
ok
+       @BeanProperty previous:String,          // null for the first
+       @BeanProperty next:String,                      // null for the last
+       
+       @BeanProperty description:String,
+       @BeanProperty date:String,
+       @BeanProperty permission:String,
+       @BeanProperty categories:String,
+       
+       @BeanProperty coordinates:String,       // raw string
+       @BeanProperty latitude:String,          // null if raw string could not 
be parsed
+       @BeanProperty longitude:String          // null if raw string could not 
be parsed
+)

Deleted: trunk/tools/commonist/src/scala/scutil/json/JSON.scala
===================================================================
--- trunk/tools/commonist/src/scala/scutil/json/JSON.scala      2010-09-11 
22:04:43 UTC (rev 72836)
+++ trunk/tools/commonist/src/scala/scutil/json/JSON.scala      2010-09-12 
02:59:32 UTC (rev 72837)
@@ -1,131 +0,0 @@
-package scutil.json
-
-import scala.util.parsing.input._
-import scala.util.parsing.combinator._
-import scala.util.parsing.combinator.syntactical._
-import scala.util.parsing.combinator.lexical._
-       
-object JSValue {
-       /** parse a JSON formatted String into a JSValue */
-       def parse(s:String):Option[JSValue]                     = parse(new 
CharSequenceReader(s))
-       def parse(s:Reader[Char]):Option[JSValue]       = JSParser.parse(s)
-       
-       /** NOTE: don't try to put in Maps with non-String keys! */
-       def apply(value:Any):JSValue = value match {
-               case null                               => JSNull
-               case value:JSValue              => value
-               case value:Int                  => JSNumber(value)
-               case value:Long                 => JSNumber(value)
-               case value:Float                => JSNumber(value)
-               case value:Double               => JSNumber(value)
-               case value:BigInt               => JSNumber(value)       
-               case value:BigDecimal   => JSNumber(value)
-               case value:Boolean              => JSBoolean(value)
-               case value:String               => JSString(value)
-               case value:List[_]              => JSArray(value map apply)
-               case value:Map[_,_]             => JSObject(Map.empty ++ 
value.iterator.map {
-                       case (key:String, valu) => (JSString(key), apply(valu))
-                       case (key,valu)                 => error("map key is 
not a String: " + key);
-               })
-               case value:Any                  => error("not a native json 
value: " + value)
-       }
-       
-       /** can be used to prepare some value to JSValue standards
-       def cooker(prepare:(Any=>Any)) = new {
-               def apply(obj:Any):Any = prepare(obj) match {
-                       case value:Map[_,_]     => Map.empty ++ 
value.elements.map { case (key,value) => (apply(key), apply(value)) }
-                       case value:Seq[_]       => value map apply
-                       case value                      => prepare(value)
-               }
-       } 
-       */
-}
-sealed trait JSValue {
-       def     toJSON:String
-}
-
-case object JSNull extends JSValue { 
-       def toJSON = "null"
-}
-
-object JSNumber {
-       def apply(value:Int):JSNumber   = JSNumber(BigDecimal(value))
-       def apply(value:Long):JSNumber  = JSNumber(BigDecimal(value))
-       def apply(value:Float):JSNumber = JSNumber(BigDecimal(value))
-       def apply(value:Double):JSNumber        = JSNumber(BigDecimal(value))
-       def apply(value:BigInt):JSNumber        = JSNumber(BigDecimal(value))
-}
-case class JSNumber(value:BigDecimal) extends JSValue { 
-       def toJSON = value.toString
-}
-
-object JSBoolean {
-       def apply(value:Boolean)        = if (value) JSTrue else JSFalse
-}
-sealed abstract class JSBoolean extends JSValue
-
-case object JSTrue extends JSBoolean {
-       def toJSON = "true"
-}
-
-case object JSFalse extends JSBoolean {
-       def toJSON = "false"
-}
-
-case class JSString(value:String) extends JSValue { 
-       def toJSON = value map {
-               _ match {
-                       case '"'        => "\\\""
-                       case '\\'       =>      "\\\\"
-                       // this would be allowed but is ugly
-                       //case '/'      => "\\/"
-                       // these are optional
-                       case '\b'       => "\\b"
-                       case '\f'       => "\\f"
-                       case '\n'       => "\\n"
-                       case '\r'       => "\\r"
-                       case '\t'       => "\\t"
-                       case c 
-                       if c < 32       => "\\u%04x".format(c.toInt)
-                       case c          => c.toString
-               }
-       } mkString("\"","","\"") 
-}
-
-case class JSArray(value:Seq[JSValue]) extends JSValue { 
-       def toJSON = value map { _.toJSON } mkString("[", ",", "]")
-}
-
-/*
-object JSObject {
-       def apply(values:Seq[Pair[JSString,JSValue]]):JSObject  = 
JSObject(Map.empty ++ values)
-}
-*/
-case class JSObject(value:Map[JSString,JSValue]) extends JSValue {
-       def toJSON = value.iterator map { 
-               case (key,valu) => key.toJSON + ":" + valu.toJSON 
-       } mkString("{", ",", "}")
-}
-
-object JSParser extends StdTokenParsers with ImplicitConversions {
-       type Tokens     = scala.util.parsing.json.Lexer
-       
-       val lexical     = new Tokens
-       lexical.reserved        ++= List("true", "false", "null")
-       lexical.delimiters      ++= List("{", "}", "[", "]", ":", ",")
-       
-       def value:Parser[JSValue]                       = (obj | arr | str | 
num | tru | fls | nul)
-       def arr:Parser[JSArray]                         = "[" ~> repsep(value, 
",") <~ "]"      ^^ { x => JSArray(x) }
-       def obj:Parser[JSObject]                        = "{" ~> repsep(pair, 
",") <~ "}"       ^^ { x => JSObject(Map() ++ x) }
-       def pair:Parser[(JSString,JSValue)]     = str ~ (":" ~> value)          
                ^^ { case x ~ y => (x, y) }
-       def str:Parser[JSString]                        = accept("string", { 
case lexical.StringLit(x)  => JSString(x) })
-       def num:Parser[JSNumber]                        = accept("number", { 
case lexical.NumericLit(x) => JSNumber(BigDecimal(x)) })
-       def tru:Parser[JSBoolean]                       = "true"  ^^^ JSTrue
-       def fls:Parser[JSBoolean]                       = "false" ^^^ JSFalse
-       def nul:Parser[JSValue]                         = "null"  ^^^ JSNull
-       
-       def parse(input:Reader[Char]):Option[JSValue] = phrase(value)(new 
lexical.Scanner(input)) match {
-               case Success(result, _) => Some(result)
-               case _                                  => None
-       }
-}
\ No newline at end of file

Copied: trunk/tools/commonist/src/scala/scutil/json/JSObject.scala (from rev 
72836, trunk/tools/commonist/src/scala/scutil/json/JSON.scala)
===================================================================
--- trunk/tools/commonist/src/scala/scutil/json/JSObject.scala                  
        (rev 0)
+++ trunk/tools/commonist/src/scala/scutil/json/JSObject.scala  2010-09-12 
02:59:32 UTC (rev 72837)
@@ -0,0 +1,131 @@
+package scutil.json
+
+import scala.util.parsing.input._
+import scala.util.parsing.combinator._
+import scala.util.parsing.combinator.syntactical._
+import scala.util.parsing.combinator.lexical._
+       
+object JSValue {
+       /** parse a JSON formatted String into a JSValue */
+       def parse(s:String):Option[JSValue]                     = parse(new 
CharSequenceReader(s))
+       def parse(s:Reader[Char]):Option[JSValue]       = JSParser.parse(s)
+       
+       /** NOTE: don't try to put in Maps with non-String keys! */
+       def apply(value:Any):JSValue = value match {
+               case null                               => JSNull
+               case value:JSValue              => value
+               case value:Int                  => JSNumber(value)
+               case value:Long                 => JSNumber(value)
+               case value:Float                => JSNumber(value)
+               case value:Double               => JSNumber(value)
+               case value:BigInt               => JSNumber(value)       
+               case value:BigDecimal   => JSNumber(value)
+               case value:Boolean              => JSBoolean(value)
+               case value:String               => JSString(value)
+               case value:List[_]              => JSArray(value map apply)
+               case value:Map[_,_]             => JSObject(Map.empty ++ 
value.iterator.map {
+                       case (key:String, valu) => (JSString(key), apply(valu))
+                       case (key,valu)                 => error("map key is 
not a String: " + key);
+               })
+               case value:Any                  => error("not a native json 
value: " + value)
+       }
+       
+       /** can be used to prepare some value to JSValue standards
+       def cooker(prepare:(Any=>Any)) = new {
+               def apply(obj:Any):Any = prepare(obj) match {
+                       case value:Map[_,_]     => Map.empty ++ 
value.elements.map { case (key,value) => (apply(key), apply(value)) }
+                       case value:Seq[_]       => value map apply
+                       case value                      => prepare(value)
+               }
+       } 
+       */
+}
+sealed trait JSValue {
+       def     toJSON:String
+}
+
+case object JSNull extends JSValue { 
+       def toJSON = "null"
+}
+
+object JSNumber {
+       def apply(value:Int):JSNumber   = JSNumber(BigDecimal(value))
+       def apply(value:Long):JSNumber  = JSNumber(BigDecimal(value))
+       def apply(value:Float):JSNumber = JSNumber(BigDecimal(value))
+       def apply(value:Double):JSNumber        = JSNumber(BigDecimal(value))
+       def apply(value:BigInt):JSNumber        = JSNumber(BigDecimal(value))
+}
+case class JSNumber(value:BigDecimal) extends JSValue { 
+       def toJSON = value.toString
+}
+
+object JSBoolean {
+       def apply(value:Boolean)        = if (value) JSTrue else JSFalse
+}
+sealed abstract class JSBoolean extends JSValue
+
+case object JSTrue extends JSBoolean {
+       def toJSON = "true"
+}
+
+case object JSFalse extends JSBoolean {
+       def toJSON = "false"
+}
+
+case class JSString(value:String) extends JSValue { 
+       def toJSON = value map {
+               _ match {
+                       case '"'        => "\\\""
+                       case '\\'       =>      "\\\\"
+                       // this would be allowed but is ugly
+                       //case '/'      => "\\/"
+                       // these are optional
+                       case '\b'       => "\\b"
+                       case '\f'       => "\\f"
+                       case '\n'       => "\\n"
+                       case '\r'       => "\\r"
+                       case '\t'       => "\\t"
+                       case c 
+                       if c < 32       => "\\u%04x".format(c.toInt)
+                       case c          => c.toString
+               }
+       } mkString("\"","","\"") 
+}
+
+case class JSArray(value:Seq[JSValue]) extends JSValue { 
+       def toJSON = value map { _.toJSON } mkString("[", ",", "]")
+}
+
+/*
+object JSObject {
+       def apply(values:Seq[Pair[JSString,JSValue]]):JSObject  = 
JSObject(Map.empty ++ values)
+}
+*/
+case class JSObject(value:Map[JSString,JSValue]) extends JSValue {
+       def toJSON = value.iterator map { 
+               case (key,valu) => key.toJSON + ":" + valu.toJSON 
+       } mkString("{", ",", "}")
+}
+
+object JSParser extends StdTokenParsers with ImplicitConversions {
+       type Tokens     = scala.util.parsing.json.Lexer
+       
+       val lexical     = new Tokens
+       lexical.reserved        ++= List("true", "false", "null")
+       lexical.delimiters      ++= List("{", "}", "[", "]", ":", ",")
+       
+       def value:Parser[JSValue]                       = (obj | arr | str | 
num | tru | fls | nul)
+       def arr:Parser[JSArray]                         = "[" ~> repsep(value, 
",") <~ "]"      ^^ { x => JSArray(x) }
+       def obj:Parser[JSObject]                        = "{" ~> repsep(pair, 
",") <~ "}"       ^^ { x => JSObject(Map() ++ x) }
+       def pair:Parser[(JSString,JSValue)]     = str ~ (":" ~> value)          
                ^^ { case x ~ y => (x, y) }
+       def str:Parser[JSString]                        = accept("string", { 
case lexical.StringLit(x)  => JSString(x) })
+       def num:Parser[JSNumber]                        = accept("number", { 
case lexical.NumericLit(x) => JSNumber(BigDecimal(x)) })
+       def tru:Parser[JSBoolean]                       = "true"  ^^^ JSTrue
+       def fls:Parser[JSBoolean]                       = "false" ^^^ JSFalse
+       def nul:Parser[JSValue]                         = "null"  ^^^ JSNull
+       
+       def parse(input:Reader[Char]):Option[JSValue] = phrase(value)(new 
lexical.Scanner(input)) match {
+               case Success(result, _) => Some(result)
+               case _                                  => None
+       }
+}

Added: trunk/tools/commonist/test/test.bsh
===================================================================
--- trunk/tools/commonist/test/test.bsh                         (rev 0)
+++ trunk/tools/commonist/test/test.bsh 2010-09-12 02:59:32 UTC (rev 72837)
@@ -0,0 +1,20 @@
+//bin/true; exec java -Xmx16m -cp "lib/bsh-2.0b2-fixed.jar" bsh.Interpreter 
"$0" "$@" 
+//==============================================================================
+
+/*
+if (!new File("build/classes").exists())       exec("ant fresh");
+addClassPath("build/classes");
+*/
+if (!new File("build/jar/minibpp.jar").exists())       exec("ant fresh");
+addClassPath("build/jar/minibpp.jar");
+import net.psammead.minibpp.Compiler;
+
+var    in      = new BufferedReader(new InputStreamReader(new 
FileInputStream("versatz/template.bpp")));
+var    out     = new PrintWriter(System.out);
+var f  = new Compiler();
+f.filter(in, out);                     // BufferedReader in, PrintWriter out
+in.close();
+out.close();
+
+//==============================================================================
+//:mode=beanshell:noTabs=false:tabSize=4:indentSize=4:lineSeparator=\n:

Modified: trunk/tools/commonist-java/build.properties
===================================================================
--- trunk/tools/commonist-java/build.properties 2010-09-11 22:04:43 UTC (rev 
72836)
+++ trunk/tools/commonist-java/build.properties 2010-09-12 02:59:32 UTC (rev 
72837)
@@ -32,7 +32,7 @@
 
 # webstart
 ws.jnlp=commonist.jnlp
-ws.codebase=http://toolserver.org/~saper/commonist/ws/
+ws.codebase=http://toolserver.org/~saper/commonist/3/
 ws.mainclass=net.psammead.commonist.Commonist
 ws.homepage=http://commons.wikimedia.org/wiki/Commons:Tools/Commonist
 ws.title=The Commonist
@@ -47,7 +47,7 @@
 #sign.dname=CN=...
 
 # keystore
-sign.keystore=etc/keyStore
+#sign.keystore=etc/keyStore
 #sign.keypass=*somepassword*
 
 # signing key

Modified: trunk/tools/commonist-java/build.xml
===================================================================
--- trunk/tools/commonist-java/build.xml        2010-09-11 22:04:43 UTC (rev 
72836)
+++ trunk/tools/commonist-java/build.xml        2010-09-12 02:59:32 UTC (rev 
72837)
@@ -28,6 +28,11 @@
                <patternset refid="runtime.jars" />
                <include name="${project}.jar" />
        </patternset>
+
+       <path id="build.classpath">
+               <pathelement location="build/classes" />
+               <fileset refid="compile.libraries" />
+       </path>
        
        <!-- ==== main ==== -->
        
@@ -56,7 +61,7 @@
                        target="${java.target}"
                        encoding="${java.encoding}"
                        deprecation="true"
-                       extdirs="lib"
+                       classpathref="build.classpath"
                        debug="true">
                                        <src path="src" />
                                        <src path="build/src" />
@@ -112,6 +117,9 @@
                        <zipfileset dir="." prefix="${project}-${version}">
                                <include name="doc/index.html"/>
                                <include name="doc/changes.txt"/>
+                               <include name="doc/changes-libutil.txt"/>
+                               <include name="doc/changes-minibpp.txt"/>
+                               <include name="doc/changes-mwlib.txt"/>
                                <include name="src/**"/>
                                <include name="etc/**"/>
                                <exclude name="${sign.keystore}"/>

Modified: trunk/tools/commonist-java/doc/changes-libutil.txt
===================================================================
--- trunk/tools/commonist-java/doc/changes-libutil.txt  2010-09-11 22:04:43 UTC 
(rev 72836)
+++ trunk/tools/commonist-java/doc/changes-libutil.txt  2010-09-12 02:59:32 UTC 
(rev 72837)
@@ -13,4 +13,4 @@
        added AppleQuit support class
 
 0.0.1
-       initial release
\ No newline at end of file
+       initial release

Modified: trunk/tools/commonist-java/doc/changes-minibpp.txt
===================================================================
--- trunk/tools/commonist-java/doc/changes-minibpp.txt  2010-09-11 22:04:43 UTC 
(rev 72836)
+++ trunk/tools/commonist-java/doc/changes-minibpp.txt  2010-09-12 02:59:32 UTC 
(rev 72837)
@@ -2,4 +2,4 @@
        added A.class and A.bsh for use with useModule.bsh
 
 0.0.1  
-       initial release
\ No newline at end of file
+       initial release

Added: trunk/tools/commonist-java/src/net/psammead/functional/README
===================================================================
--- trunk/tools/commonist-java/src/net/psammead/functional/README               
                (rev 0)
+++ trunk/tools/commonist-java/src/net/psammead/functional/README       
2010-09-12 02:59:32 UTC (rev 72837)
@@ -0,0 +1,2 @@
+This package (net.psammead.functional) is licensed under LGPL
+

Added: trunk/tools/commonist-java/src/net/psammead/minibpp/README
===================================================================
--- trunk/tools/commonist-java/src/net/psammead/minibpp/README                  
        (rev 0)
+++ trunk/tools/commonist-java/src/net/psammead/minibpp/README  2010-09-12 
02:59:32 UTC (rev 72837)
@@ -0,0 +1,2 @@
+This package (net.psammead.minibpp) is licensed under LGPL
+

Added: trunk/tools/commonist-java/src/net/psammead/mwapi/README
===================================================================
--- trunk/tools/commonist-java/src/net/psammead/mwapi/README                    
        (rev 0)
+++ trunk/tools/commonist-java/src/net/psammead/mwapi/README    2010-09-12 
02:59:32 UTC (rev 72837)
@@ -0,0 +1,2 @@
+This package (net.psammead.mwapi) is licensed under LGPL
+

Added: trunk/tools/commonist-java/src/net/psammead/util/README
===================================================================
--- trunk/tools/commonist-java/src/net/psammead/util/README                     
        (rev 0)
+++ trunk/tools/commonist-java/src/net/psammead/util/README     2010-09-12 
02:59:32 UTC (rev 72837)
@@ -0,0 +1,2 @@
+This package (net.psammead.util) is licensed under LGPL
+



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to