Move data files into the Python package.
authorHartmut Goebel <h.goebel@crazy-compilers.com>
Tue, 17 Mar 2020 10:26:38 +0100
changeset 43 fb35b9db9ca1
parent 42 700f4d003349
child 44 4e5f42d51cc4
Move data files into the Python package.

The packe directory is now always searched for include files, after
all other directoreis given in $YML_PATH.
manpage.yml2
standardlib.ysl2
xml2yml.ysl2
yml2/manpage.yml2
yml2/standardlib.ysl2
yml2/xml2yml.ysl2
yml2/yslt.yml2
yml2c
yml2proc
yslt.yml2
--- a/manpage.yml2	Thu Oct 27 12:51:47 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-decl manpage(xmlns="http://docbook.org/ns/docbook", version="5.0", *title) alias article { title *title; content; };
--- a/standardlib.ysl2	Thu Oct 27 12:51:47 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-// YML2 standardlib version 2.5.8
-
-function "yml:hex2dec" {
-    param "hex";
-    param "_result", 0;
-    
-    const "hd", "substring($hex, 1, 1)";
-    const "a", """translate($hd, 'ABCDEFabcdef123456789',
-        '123456123456000000000')""";
-
-    const "d" choose {
-        when "$a>0" value "$a + 9";
-        otherwise value "$hd";
-    }
-
-    choose {
-        when "string-length($hex) = 1"
-            value "$_result * 16 + $d";
-        otherwise call "yml:hex2dec"
-            with "hex", "substring($hex, 2, 8)", 
-            with "_result", "$_result * 16 + $d";
-    }
-}
-
-function "yml:dec2hex" {
-    param "dec";
-    param "bits", !16**7!;
-
-    const "v", "floor($dec div $bits)";
-    value "substring('0123456789abcdef', $v + 1, 1)";
-
-    if "$bits > 1" call "yml:dec2hex"
-        with "dec", "$dec - $bits * $v",
-        with "bits", "$bits div 16";
-}
-
-def "yml:dec2hex" {
-    param "dec";
-    param "digits", 8;
-        
-    result call "yml:dec2hex" with "dec", "$dec", with "bits", "math:power(16, $digits - 1)";
-}
-
-def "yml:hex2dec" {
-    param "hex";
-    result call "yml:hex2dec" with "hex", "$hex";
-}
-
-def "yml:lcase" {
-    param "text", "''";
-    result "translate($text, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')";
-}
-
-def "yml:ucase" {
-    param "text", "''";
-    result "translate($text, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')";
-}
-
-def "yml:mixedCase" {
-    param "text", "''";
-    result "concat(yml:lcase(substring($text,1,1)),substring($text,2))";
-}
-
-def "yml:capit" {
-    param "text", "''";
-    result "concat(yml:ucase(substring($text,1,1)),substring($text,2))";
-}
-
--- a/xml2yml.ysl2	Thu Oct 27 12:51:47 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,87 +0,0 @@
-// xml2yml2.ysl2 version 2.4.4
-
-include yslt.yml2
-
-decl textstylesheet is estylesheet(*output="text") {
-    output *output;
-    const "space", !"'" + " " * 200 + "'"!;
-    param "autoindent", 4;
-    content;
-}, tstylesheet is textstylesheet;
-
-define operator "†" as call "convert" with "tag", "name()";
-
-tstylesheet {
-    function "printNS"
-        for "*/namespace::*[local-name()!='xml']" {
-            > xmlns
-            if "not(local-name()='')"
-                > :«local-name()»
-            > ="«.»"
-            if "position()<last()" > , 
-        }
-    
-    template "/" {
-        if "count(*/namespace::*)>1" {
-            | decl «name(*)»(`call "printNS"`);
-            |
-        }
-        apply "*", 0;
-    }
-
-    template "text()" {
-        param "text", "normalize-space()";
-
-        if "string-length($text)>0" choose {
-            when "contains($text,'\\n')" choose {
-                when "string-length(substring-before($text,'\\n'))<string-length($text)-1" choose {
-                    when "substring($text,string-length($text),1)='\\n'"
-                        > \n||\n«$text»||\n\n
-                    otherwise > > «str:replace($text,'\\n','\\\\n')»\n
-                }
-                otherwise > | «$text»\n
-            }
-            otherwise > > `copy "."`\n
-        }
-    }
-
-    template "*" {
-        0>
-        call "convert" with "tag", "name()";
-        apply "@*";
-
-        choose {
-            when "count(*)=0 and string-length(normalize-space())=0"
-                > ;\n
-            when "count(*)=1 and string-length(normalize-space())=0" {
-                > \n
-                apply "*";
-            }
-            when "count(*)=0 and string-length(normalize-space())>0" {
-                >  
-                apply "text()";
-            }
-            otherwise {
-                >  {\n
-                for "*|text()" {
-                    if "local-name()=''"
-                        if "string-length(normalize-space())>0"
-                            1>
-                    apply ".";
-                }
-                | }
-            }
-        }
-    }
-
-    template "@*" {
-        >  «name()»="«.»"
-        if "position()<last()" > ,
-    }
-
-    function "convert" {
-        param "tag";
-
-        > «translate($tag, '-', '_')»
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yml2/manpage.yml2	Tue Mar 17 10:26:38 2020 +0100
@@ -0,0 +1,1 @@
+decl manpage(xmlns="http://docbook.org/ns/docbook", version="5.0", *title) alias article { title *title; content; };
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yml2/standardlib.ysl2	Tue Mar 17 10:26:38 2020 +0100
@@ -0,0 +1,68 @@
+// YML2 standardlib version 2.5.8
+
+function "yml:hex2dec" {
+    param "hex";
+    param "_result", 0;
+    
+    const "hd", "substring($hex, 1, 1)";
+    const "a", """translate($hd, 'ABCDEFabcdef123456789',
+        '123456123456000000000')""";
+
+    const "d" choose {
+        when "$a>0" value "$a + 9";
+        otherwise value "$hd";
+    }
+
+    choose {
+        when "string-length($hex) = 1"
+            value "$_result * 16 + $d";
+        otherwise call "yml:hex2dec"
+            with "hex", "substring($hex, 2, 8)", 
+            with "_result", "$_result * 16 + $d";
+    }
+}
+
+function "yml:dec2hex" {
+    param "dec";
+    param "bits", !16**7!;
+
+    const "v", "floor($dec div $bits)";
+    value "substring('0123456789abcdef', $v + 1, 1)";
+
+    if "$bits > 1" call "yml:dec2hex"
+        with "dec", "$dec - $bits * $v",
+        with "bits", "$bits div 16";
+}
+
+def "yml:dec2hex" {
+    param "dec";
+    param "digits", 8;
+        
+    result call "yml:dec2hex" with "dec", "$dec", with "bits", "math:power(16, $digits - 1)";
+}
+
+def "yml:hex2dec" {
+    param "hex";
+    result call "yml:hex2dec" with "hex", "$hex";
+}
+
+def "yml:lcase" {
+    param "text", "''";
+    result "translate($text, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')";
+}
+
+def "yml:ucase" {
+    param "text", "''";
+    result "translate($text, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')";
+}
+
+def "yml:mixedCase" {
+    param "text", "''";
+    result "concat(yml:lcase(substring($text,1,1)),substring($text,2))";
+}
+
+def "yml:capit" {
+    param "text", "''";
+    result "concat(yml:ucase(substring($text,1,1)),substring($text,2))";
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yml2/xml2yml.ysl2	Tue Mar 17 10:26:38 2020 +0100
@@ -0,0 +1,87 @@
+// xml2yml2.ysl2 version 2.4.4
+
+include yslt.yml2
+
+decl textstylesheet is estylesheet(*output="text") {
+    output *output;
+    const "space", !"'" + " " * 200 + "'"!;
+    param "autoindent", 4;
+    content;
+}, tstylesheet is textstylesheet;
+
+define operator "†" as call "convert" with "tag", "name()";
+
+tstylesheet {
+    function "printNS"
+        for "*/namespace::*[local-name()!='xml']" {
+            > xmlns
+            if "not(local-name()='')"
+                > :«local-name()»
+            > ="«.»"
+            if "position()<last()" > , 
+        }
+    
+    template "/" {
+        if "count(*/namespace::*)>1" {
+            | decl «name(*)»(`call "printNS"`);
+            |
+        }
+        apply "*", 0;
+    }
+
+    template "text()" {
+        param "text", "normalize-space()";
+
+        if "string-length($text)>0" choose {
+            when "contains($text,'\\n')" choose {
+                when "string-length(substring-before($text,'\\n'))<string-length($text)-1" choose {
+                    when "substring($text,string-length($text),1)='\\n'"
+                        > \n||\n«$text»||\n\n
+                    otherwise > > «str:replace($text,'\\n','\\\\n')»\n
+                }
+                otherwise > | «$text»\n
+            }
+            otherwise > > `copy "."`\n
+        }
+    }
+
+    template "*" {
+        0>
+        call "convert" with "tag", "name()";
+        apply "@*";
+
+        choose {
+            when "count(*)=0 and string-length(normalize-space())=0"
+                > ;\n
+            when "count(*)=1 and string-length(normalize-space())=0" {
+                > \n
+                apply "*";
+            }
+            when "count(*)=0 and string-length(normalize-space())>0" {
+                >  
+                apply "text()";
+            }
+            otherwise {
+                >  {\n
+                for "*|text()" {
+                    if "local-name()=''"
+                        if "string-length(normalize-space())>0"
+                            1>
+                    apply ".";
+                }
+                | }
+            }
+        }
+    }
+
+    template "@*" {
+        >  «name()»="«.»"
+        if "position()<last()" > ,
+    }
+
+    function "convert" {
+        param "tag";
+
+        > «translate($tag, '-', '_')»
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yml2/yslt.yml2	Tue Mar 17 10:26:38 2020 +0100
@@ -0,0 +1,101 @@
+// YSLT version 2.6.2
+
+!!
+def indent(level):
+    return "value 'substring($space, 1, $_indent+" + str(level) + "*$autoindent)';"
+!!
+
+in exsl decl document(href, method) alias document;
+in func decl def(name) alias function, result(select);
+
+decl debug_off(exclude-result-prefixes="yml");
+
+in xsl {
+    decl _trace_param(%text, name="yml:trace", select='yml:debug("* %text")') alias param;
+    decl _trace_with is _trace_param alias with-param;
+
+    decl param(name, select);
+    decl const(name, select) alias variable, variable is const;
+    decl output(method), key(name, match, use);
+    decl value(select) alias value-of, copy(select) alias copy-of;
+
+    decl indent is value(%level, select='substring($space, 1, $_indent + (%level) * $autoindent)');
+
+    decl stylesheet(
+        *output="xml",
+        version="1.0",
+        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    ) {
+        output *output;
+        const "space", !"'" + " " * 200 + "'"!;
+        param "autoindent", 4;
+        content;
+    };
+
+    decl estylesheet is stylesheet (
+        xmlns:exsl='http://exslt.org/common',
+        xmlns:math='http://exslt.org/math',
+        xmlns:func='http://exslt.org/functions',
+        xmlns:str='http://exslt.org/strings',
+        xmlns:dyn='http://exslt.org/dynamic',
+        xmlns:set='http://exslt.org/sets',
+        xmlns:sets='http://exslt.org/sets',
+        xmlns:date='http://exslt.org/dates-and-times',
+        xmlns:yml='http://fdik.org/yml',
+        extension-element-prefixes='exsl func str dyn set sets math date yml'
+    );
+
+    decl textstylesheet is estylesheet(*output="text") {
+        output *output;
+        const "space", !"'" + " " * 200 + "'"!;
+        param "autoindent", 4;
+        xsl:template match="text()";
+        content;
+    }, tstylesheet is textstylesheet;
+
+    decl template(match) {
+        _trace_param *_trace_info;
+        param "_indent", 0;
+        content;
+    };
+
+    decl function(name) alias template {
+        _trace_param *_trace_info;
+        param "_indent", 0;
+        content;
+    };
+   
+    decl call(name) alias call-template {
+        _trace_with *_trace_info;
+        content;
+    };
+
+    decl namespace_alias(stylesheet-prefix, result-prefix);
+    decl text, raw(disable-output-escaping='yes') alias text;
+
+    decl with(name, select) alias with-param;
+    decl withIndent(%level, name="_indent", select='$_indent + (%level) * $autoindent') alias with-param;
+
+    decl apply(select, *indent=1) alias apply-templates {
+        _trace_with *_trace_info;
+        withIndent *indent;
+        content;
+    };
+
+    decl choose, when(test), otherwise;
+    decl if(test);
+    decl for(select) alias for-each, foreach is for;
+    decl element(name, namespace);
+    decl attrib(name, namespace) alias attribute, attrib_set(name) alias attribute-set;
+    decl processing(name) alias processing-instruction;
+    decl comment;
+    decl number(value), sort(select), decimal_format(name, decimal-separator=".", grouping-separator=",");
+    decl import(href), fallback;
+    decl message, error is message(terminate='yes'), warning is message(terminate='no');
+
+    decl debug(%text, select='yml:debug(%text)') alias value-of;
+    decl assert(%test, %msg="''", select='yml:assert(%test,%msg)') alias value-of;
+}
+
+define operator "«(.*?)»" as value "%1";
+
--- a/yml2c	Thu Oct 27 12:51:47 2016 +0200
+++ b/yml2c	Tue Mar 17 10:26:38 2020 +0100
@@ -15,6 +15,8 @@
 from yml2 import ymlCStyle, comment, oldSyntax
 import yml2.backend as backend
 
+YML_DEFAULT_PATH = [os.path.dirname(backend.__file__)]
+
 def printInfo(option, opt_str, value, parser):
     sys.stdout.write(__doc__)
     sys.exit(0)
@@ -58,7 +60,7 @@
     if options.includePathText:
         backend.includePath = options.includePathText.split(':')
 
-    dirs = os.environ.get('YML_PATH', '.').split(':')
+    dirs = os.environ.get('YML_PATH', '.').split(':') + YML_DEFAULT_PATH
     backend.includePath.extend(dirs)
 
     files = fileinput.input(args, mode="rU", openhook=fileinput.hook_encoded(options.encoding))
--- a/yml2proc	Thu Oct 27 12:51:47 2016 +0200
+++ b/yml2proc	Tue Mar 17 10:26:38 2020 +0100
@@ -21,6 +21,8 @@
 from yml2.pyPEG import parse, u
 import yml2.backend as backend
 
+YML_DEFAULT_PATH = [os.path.dirname(backend.__file__)]
+
 def printInfo(option, opt_str, value, parser):
     sys.stdout.write(__doc__)
     sys.exit(0)
@@ -89,7 +91,7 @@
 
 backend.encoding = options.encoding
 
-dirs = os.environ.get('YML_PATH', '.').split(':')
+dirs = os.environ.get('YML_PATH', '.').split(':') + YML_DEFAULT_PATH
 backend.includePath.extend(dirs)
 
 if options.xml2yml:
--- a/yslt.yml2	Thu Oct 27 12:51:47 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,101 +0,0 @@
-// YSLT version 2.6.2
-
-!!
-def indent(level):
-    return "value 'substring($space, 1, $_indent+" + str(level) + "*$autoindent)';"
-!!
-
-in exsl decl document(href, method) alias document;
-in func decl def(name) alias function, result(select);
-
-decl debug_off(exclude-result-prefixes="yml");
-
-in xsl {
-    decl _trace_param(%text, name="yml:trace", select='yml:debug("* %text")') alias param;
-    decl _trace_with is _trace_param alias with-param;
-
-    decl param(name, select);
-    decl const(name, select) alias variable, variable is const;
-    decl output(method), key(name, match, use);
-    decl value(select) alias value-of, copy(select) alias copy-of;
-
-    decl indent is value(%level, select='substring($space, 1, $_indent + (%level) * $autoindent)');
-
-    decl stylesheet(
-        *output="xml",
-        version="1.0",
-        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-    ) {
-        output *output;
-        const "space", !"'" + " " * 200 + "'"!;
-        param "autoindent", 4;
-        content;
-    };
-
-    decl estylesheet is stylesheet (
-        xmlns:exsl='http://exslt.org/common',
-        xmlns:math='http://exslt.org/math',
-        xmlns:func='http://exslt.org/functions',
-        xmlns:str='http://exslt.org/strings',
-        xmlns:dyn='http://exslt.org/dynamic',
-        xmlns:set='http://exslt.org/sets',
-        xmlns:sets='http://exslt.org/sets',
-        xmlns:date='http://exslt.org/dates-and-times',
-        xmlns:yml='http://fdik.org/yml',
-        extension-element-prefixes='exsl func str dyn set sets math date yml'
-    );
-
-    decl textstylesheet is estylesheet(*output="text") {
-        output *output;
-        const "space", !"'" + " " * 200 + "'"!;
-        param "autoindent", 4;
-        xsl:template match="text()";
-        content;
-    }, tstylesheet is textstylesheet;
-
-    decl template(match) {
-        _trace_param *_trace_info;
-        param "_indent", 0;
-        content;
-    };
-
-    decl function(name) alias template {
-        _trace_param *_trace_info;
-        param "_indent", 0;
-        content;
-    };
-   
-    decl call(name) alias call-template {
-        _trace_with *_trace_info;
-        content;
-    };
-
-    decl namespace_alias(stylesheet-prefix, result-prefix);
-    decl text, raw(disable-output-escaping='yes') alias text;
-
-    decl with(name, select) alias with-param;
-    decl withIndent(%level, name="_indent", select='$_indent + (%level) * $autoindent') alias with-param;
-
-    decl apply(select, *indent=1) alias apply-templates {
-        _trace_with *_trace_info;
-        withIndent *indent;
-        content;
-    };
-
-    decl choose, when(test), otherwise;
-    decl if(test);
-    decl for(select) alias for-each, foreach is for;
-    decl element(name, namespace);
-    decl attrib(name, namespace) alias attribute, attrib_set(name) alias attribute-set;
-    decl processing(name) alias processing-instruction;
-    decl comment;
-    decl number(value), sort(select), decimal_format(name, decimal-separator=".", grouping-separator=",");
-    decl import(href), fallback;
-    decl message, error is message(terminate='yes'), warning is message(terminate='no');
-
-    decl debug(%text, select='yml:debug(%text)') alias value-of;
-    decl assert(%test, %msg="''", select='yml:assert(%test,%msg)') alias value-of;
-}
-
-define operator "«(.*?)»" as value "%1";
-