ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hi...@apache.org
Subject svn commit: r1352109 - in /ant/sandbox/antdsl: org.apache.ant.antdsl/src/org/apache/ant/antdsl/ org.apache.ant.antdsl/src/org/apache/ant/antdsl/antlr/ org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/ test/
Date Wed, 20 Jun 2012 14:01:34 GMT
Author: hibou
Date: Wed Jun 20 14:01:34 2012
New Revision: 1352109

URL: http://svn.apache.org/viewvc?rev=1352109&view=rev
Log:
Add support for multiline doc and support proper encoding in the antler parser

Modified:
    ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntDSL.g
    ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/antlr/AntDslAntlrProjectHelper.java
    ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDSL.xtext
    ant/sandbox/antdsl/test/build.ant

Modified: ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntDSL.g
URL: http://svn.apache.org/viewvc/ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntDSL.g?rev=1352109&r1=1352108&r2=1352109&view=diff
==============================================================================
--- ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntDSL.g (original)
+++ ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntDSL.g Wed Jun 20
14:01:34 2012
@@ -57,13 +57,6 @@ import java.util.LinkedHashMap;
     public void setProjectHelper(AntDslAntlrProjectHelper projectHelper) {
         this.projectHelper = projectHelper;
     }
-
-    private String readString(String s) {
-        if (s == null) {
-            return null;
-        }
-        return s.substring(1, s.length() - 1);
-    }
 }
 
 project:
@@ -72,7 +65,7 @@ project:
         ('default' ':' def=NAME)?
         ('basedir' ':' basedir=STRING)?
     )
-    { projectHelper.setupProject(project, context, $name.text, readString($basedir.text),
$def.text); }
+    { projectHelper.setupProject(project, context, $name.text, projectHelper.readString($basedir.text),
$def.text); }
     ( 'namespaces' '{' ( ns=namespace { context.addNamespace(ns.first, ns.second); } )* '}')?
     tl=taskList?
     { for (Task t : tl) { context.getImplicitTarget().addTask(t); } }
@@ -82,7 +75,7 @@ project:
     )*;
 
 namespace returns [Pair<String, String> ns = new Pair<String, String>()]:
-    NAME { ns.first = $NAME.text; } ':' STRING { ns.second = readString($STRING.text); };
+    NAME { ns.first = $NAME.text; } ':' STRING { ns.second = projectHelper.readString($STRING.text);
};
 
 extensionPoint returns [ExtensionPoint ep = new ExtensionPoint()]:
     { context.setCurrentTarget(ep); }
@@ -92,7 +85,7 @@ extensionPoint returns [ExtensionPoint e
     ('extensionOf' eo=targetList ('onMiss' onMiss=STRING )? )?
     ('if' if_=boolExpr { ep.setIf(if_); } )?
     ('unless' unless=boolExpr { ep.setUnless(unless); } )?
-    { projectHelper.mapCommonTarget(ep, project, context, $n.text, $desc.text, d, eo, $onMiss.text);
}
+    { projectHelper.mapCommonTarget(ep, project, context, $n.text, projectHelper.readDoc($desc.text),
d, eo, $onMiss.text); }
     { context.setCurrentTarget(context.getImplicitTarget()); }
     ;
 
@@ -104,7 +97,7 @@ target returns [Target t = new Target()]
     ('extensionOf' eo=targetList ('onMiss' onMiss=STRING)? )?
     ('if' if_=boolExpr { t.setIf(if_); } )?
     ('unless' unless=boolExpr { t.setUnless(unless); } )?
-    { projectHelper.mapCommonTarget(t, project, context, $n.text, $desc.text, d, eo, $onMiss.text);
}
+    { projectHelper.mapCommonTarget(t, project, context, $n.text, projectHelper.readDoc($desc.text),
d, eo, $onMiss.text); }
     tl=taskList?
     { for (Task task : tl) { t.addTask(task); } }
     { context.setCurrentTarget(context.getImplicitTarget()); }
@@ -131,7 +124,7 @@ arguments returns [LinkedHashMap<String,
     (',' arg=argument { args.put(arg.first, arg.second); } )*;
 
 argument returns [Pair<String, String> arg = new Pair<String, String>()]:
-    NAME { arg.first = $NAME.text; } '=' STRING { arg.second = readString($STRING.text);
} ;
+    NAME { arg.first = $NAME.text; } '=' STRING { arg.second = projectHelper.readString($STRING.text);
} ;
 
 innerElements returns [List<InnerElement> ies = new ArrayList<InnerElement>()]:
     '{' (ie=innerElement { ies.add(ie); } )+ '}';
@@ -147,12 +140,12 @@ assignment returns [Task assign]:
 propertyAssignment returns [Property p = new Property()]:
     'prop'
     { projectHelper.mapCommonTask(project, context, p); }
-    NAME { p.setName($NAME.text); } '=' STRING { p.setValue(readString($STRING.text)); }
;
+    NAME { p.setName($NAME.text); } '=' STRING { p.setValue(projectHelper.readString($STRING.text));
} ;
 
 refAssignment returns [RefTask r = new RefTask()]:
     'ref'
     { projectHelper.mapCommonTask(project, context, r); }
-    NAME { r.setName($NAME.text); } '=' STRING { r.setValue(readString($STRING.text)); }
;
+    NAME { r.setName($NAME.text); } '=' STRING { r.setValue(projectHelper.readString($STRING.text));
} ;
 
 branch returns [IfTask if_ = new IfTask()]:
     { projectHelper.mapCommonTask(project, context, if_); }
@@ -222,7 +215,7 @@ boolNotExpr returns [Condition c]:
     };
 
 macrodef returns [MacroDef macroDef = new MacroDef()]:
-    ( DOC { macroDef.setDescription($DOC.text); } )?  
+    ( DOC { macroDef.setDescription(projectHelper.readDoc($DOC.text)); } )?
     'macrodef' NAME { macroDef.setName($NAME.text); }
     '(' ( atts=attributes
           {  for (Object att : atts) {
@@ -273,7 +266,7 @@ elementAttribute returns [TemplateElemen
     NAME { element.setName($NAME.text); };
 
 DOC:
-    '%' ~('\n'|'\r')* '\r'? '\n'
+    ( '%' ~('\n'|'\r')* '\r'? '\n' )+
 ;
 
 PROPERTY:

Modified: ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/antlr/AntDslAntlrProjectHelper.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/antlr/AntDslAntlrProjectHelper.java?rev=1352109&r1=1352108&r2=1352109&view=diff
==============================================================================
--- ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/antlr/AntDslAntlrProjectHelper.java
(original)
+++ ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/antlr/AntDslAntlrProjectHelper.java
Wed Jun 20 14:01:34 2012
@@ -52,4 +52,107 @@ public class AntDslAntlrProjectHelper ex
         }
     }
 
+    public String readString(String s) {
+        if (s == null) {
+            return null;
+        }
+        // first remove the quotes
+        s = s.substring(1, s.length() - 1);
+        // code copied from org.eclipse.xtext.util.Strings.convertFromJavaString(String,
boolean)
+        char[] in = s.toCharArray();
+        int off = 0;
+        int len = s.length();
+        char[] convtBuf = new char[len];
+        char aChar;
+        char[] out = convtBuf;
+        int outLen = 0;
+        int end = off + len;
+
+        while (off < end) {
+            aChar = in[off++];
+            if (aChar == '\\') {
+                aChar = in[off++];
+                if (aChar == 'u') {
+                    // Read the xxxx
+                    int value = 0;
+                    if (off + 4 > end)
+                        throw new IllegalArgumentException("Malformed \\uxxxx encoding.");
+                    for (int i = 0; i < 4; i++) {
+                        aChar = in[off++];
+                        switch (aChar) {
+                            case '0':
+                            case '1':
+                            case '2':
+                            case '3':
+                            case '4':
+                            case '5':
+                            case '6':
+                            case '7':
+                            case '8':
+                            case '9':
+                                value = (value << 4) + aChar - '0';
+                                break;
+                            case 'a':
+                            case 'b':
+                            case 'c':
+                            case 'd':
+                            case 'e':
+                            case 'f':
+                                value = (value << 4) + 10 + aChar - 'a';
+                                break;
+                            case 'A':
+                            case 'B':
+                            case 'C':
+                            case 'D':
+                            case 'E':
+                            case 'F':
+                                value = (value << 4) + 10 + aChar - 'A';
+                                break;
+                            default:
+                                throw new IllegalArgumentException("Malformed \\uxxxx encoding.");
+                        }
+                    }
+                    out[outLen++] = (char) value;
+                } else {
+                    if (aChar == 't') {
+                        aChar = '\t';
+                    } else if (aChar == 'r') {
+                        aChar = '\r';
+                    } else if (aChar == 'n') {
+                        aChar = '\n';
+                    } else if (aChar == 'f') {
+                        aChar = '\f';
+                    } else if (aChar == 'b') {
+                        aChar = '\b';
+                    } else if (aChar == '"') {
+                        aChar = '\"';
+                    } else if (aChar == '\'') {
+                        aChar = '\'';
+                    } else if (aChar == '\\') {
+                        aChar = '\\';
+                    } else {
+                        throw new IllegalArgumentException("Illegal escape character \\"
+ aChar);
+                    }
+                    out[outLen++] = aChar;
+                }
+            } else {
+                out[outLen++] = aChar;
+            }
+        }
+        return new String(out, 0, outLen);
+    }
+
+    public String readDoc(String s) {
+        if (s == null) {
+            return null;
+        }
+        String[] split = s.split("\r?\n");
+        StringBuilder builder = new StringBuilder();
+        for (String line : split) {
+            builder.append(line.substring(1)); // remove the leading %
+            builder.append(' '); // replace the line end by a space
+        }
+        return builder.toString();
+    }
+
 }

Modified: ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDSL.xtext
URL: http://svn.apache.org/viewvc/ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDSL.xtext?rev=1352109&r1=1352108&r2=1352109&view=diff
==============================================================================
--- ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDSL.xtext
(original)
+++ ant/sandbox/antdsl/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDSL.xtext
Wed Jun 20 14:01:34 2012
@@ -128,4 +128,4 @@ terminal PROPERTY:
     '$' NAME;
 
 terminal DOC:
-    '%' !('\n'|'\r')* ('\r'? '\n')?;
\ No newline at end of file
+    ( '%' !('\n'|'\r')* '\r'? '\n' )+;
\ No newline at end of file

Modified: ant/sandbox/antdsl/test/build.ant
URL: http://svn.apache.org/viewvc/ant/sandbox/antdsl/test/build.ant?rev=1352109&r1=1352108&r2=1352109&view=diff
==============================================================================
--- ant/sandbox/antdsl/test/build.ant (original)
+++ ant/sandbox/antdsl/test/build.ant Wed Jun 20 14:01:34 2012
@@ -1,6 +1,10 @@
 name : myproject
 default : build
 
+namespaces {
+    antunit : "antlib:org.apache.ant.antunit"
+}
+
 {
     prop foo = "hello world!"
     echo(message="${foo}")
@@ -30,6 +34,7 @@ target notexecuted
 }
 
 % description of the target
+% which is on a multiline
 target build
     depends dep, notexecuted
 {
@@ -55,4 +60,7 @@ target build
     } else {
         fail(message = "fail !")
     }
+    echo(message = "test encoding\\backslash")
+    echo(message = "test encoding\ttab")
+    echo(message = "test encoding\nline")
 }



Mime
View raw message