March 17, 2005
Brad Anderson wrote:
> Justin,
> 
> We should talk.  The tutorial section of dsource.org could be a plugin/module of Trac.  I.E. each project could have a tutorial section, along with forums, tickets, downloads, news, etc.

I think we already discussed some of this. I managed to install Trac onto my local machine, and I saw how syntax highlighing could be handled by writing a Python function. I just haven't gotten around to porting d2html to Python yet. It shouldn't be a problem to use Trac wiki pages (with syntax highlighing) for the tutorial examples. I'd rather have wiki pages to track changes than lock most people out (like we're currently doing).

> Then we could have a project at dsource that is kind of like the "D Language" project.  People could add their PEP-like requests, have tickets to track bugs, and all the tutorials for the language in general, and not a specific project, could be in this "D Language" project.

That sounds fine to me.

> I'm bringing it up, because if we want to integrate with Trac, you'd have to rewrite in Python and use ClearSilver templates, instead of PHP.  Obviously, we'd convert the current ones to the new system...  Let's discuss, either here, on the site forum at dsource.org, or offline.

Will the new server still have PHP? I think it's a good idea to make use of Trac for the tutorials in the near future, but I doubt I'll be ready before you're ready to go live with "dsource 2.0". ;)

-- 
Justin (a/k/a jcc7)
http://jcc_7.tripod.com/d/
March 17, 2005
Joey Peters wrote:
>  I'm interested in writing some tutorials, just to review my current D skills. I've been using D for a few months now, I should be able to write a few beginner tutorials.

Great! I know that there's a lot more we could do to explain D to newcomers. Many of the same questions seem to always come up with someone who is new to D.

> "J C Calvarese" <jcc7@cox.net> schreef in bericht news:d1aob8$2kq9$1@digitaldaemon.com...
> 
>>Before someone has a chance to ask, I figured I'd provide some helpful links...
>>
>>
>>*The nexus of D tutorials*
>>http://www.prowiki.org/wiki4d/wiki.cgi?D__Tutorial

-- 
Justin (a/k/a jcc7)
http://jcc_7.tripod.com/d/
March 17, 2005
AEon wrote:
> "J C Calvarese" <jcc7@cox.net>,
> 
> Just had a quick look at teh turorials. Very nice.
> 
> in 
> 
> http://www.dsource.org/tutorials/index.php?show_example=26
> 
> I was a bit surprised that
> 
> <code>
> void main()
> { printf("Hi");
> }
> </code>
> 
> actually works with dmd. I would have guessed it requires

Yes, it's magic. :)

I'm one of those who is trying to lobby Walter to remove the public import of std.c.stdio from object.d, but until he does so it is legal code.

-- 
Justin (a/k/a jcc7)
http://jcc_7.tripod.com/d/
March 19, 2005
J C Calvarese wrote:
> Brad Anderson wrote:
> 
>> Justin,
>>
>> We should talk.  The tutorial section of dsource.org could be a plugin/module of Trac.  I.E. each project could have a tutorial section, along with forums, tickets, downloads, news, etc.

...

> Will the new server still have PHP? I think it's a good idea to make use of Trac for the tutorials in the near future, but I doubt I'll be ready before you're ready to go live with "dsource 2.0". ;)

Sometimes, I'm my own harshest critic.

It wasn't nearly as hard to convert the PHP to Python as I was thinking it might be. I'm not saying it's perfect, but I think it's already nearly as good as the PHP version. It seems to work great on the Trac system I have running locally.

You should place the attached file in \pythonXX\lib\site-packages\trac\wikimacros\ where "pythonXX" is your Python directory.

Here's some wiki code to test the D processor:

{{{
#!d
int main(char[] args)
{
   printf("Hello World\n");
   return 0;
}
}}}

If it's working, the keywords (int, char, and return) will turn blue, etc.

For more information about how this works: http://projects.edgewall.com/trac/wiki/WikiProcessors


-- 
Justin (a/k/a jcc7)
http://jcc_7.tripod.com/d/


March 19, 2005
Looks great.  I'll check it out tomorrow.  Thanks!!

Did you think about integrating with the 3rd party tools here:
http://projects.edgewall.com/trac/wiki/TracSyntaxColoring

This would extend the syntax highlighting to the source-code browser instead of just Wiki pages.  Although it would need to be in Scintilla for SilverCity.  That's C++ (ick) instead of Python...

Still, it's cool progress, and I need a jump-start.

BA


J C Calvarese wrote:
> J C Calvarese wrote:
> 
>> Brad Anderson wrote:
>>
>>> Justin,
>>>
>>> We should talk.  The tutorial section of dsource.org could be a plugin/module of Trac.  I.E. each project could have a tutorial section, along with forums, tickets, downloads, news, etc.
> 
> 
> ...
> 
>> Will the new server still have PHP? I think it's a good idea to make use of Trac for the tutorials in the near future, but I doubt I'll be ready before you're ready to go live with "dsource 2.0". ;)
> 
> 
> Sometimes, I'm my own harshest critic.
> 
> It wasn't nearly as hard to convert the PHP to Python as I was thinking it might be. I'm not saying it's perfect, but I think it's already nearly as good as the PHP version. It seems to work great on the Trac system I have running locally.
> 
> You should place the attached file in \pythonXX\lib\site-packages\trac\wikimacros\ where "pythonXX" is your Python directory.
> 
> Here's some wiki code to test the D processor:
> 
> {{{
> #!d
> int main(char[] args)
> {
>   printf("Hello World\n");
>   return 0;
> }
> }}}
> 
> If it's working, the keywords (int, char, and return) will turn blue, etc.
> 
> For more information about how this works: http://projects.edgewall.com/trac/wiki/WikiProcessors
> 
> 
> 
> ------------------------------------------------------------------------
> 
> # d.py
> #Place in \pythonXX\lib\site-packages\trac\wikimacros\
> 
> 
> import re
> 
> 
> # D keywords # from http://www.digitalmars.com/d/lex.html#keyword
> # list checked 2005/03/18
> 
> keywords = ['abstract', 'alias', 'align', 'asm', 'assert', 'auto',
>     'bit', 'body', 'break', 'byte',
>     'case', 'cast', 'catch', 'cdouble', 'cent', 'cfloat', 'char', 'class', 'const', 'continue', 'creal',     'dchar', 'debug', 'default', 'delegate', 'delete', 'deprecated', 'do', 'double',
>     'else', 'enum', 'export', 'extern',
>     'false', 'final', 'finally', 'float', 'for', 'foreach', 'function',     'goto',      'idouble', 'if', 'ifloat', 'import', 'in', 'inout', 'int', 'interface', 'invariant', 'ireal', 'is',      'long',
>     'mixin', 'module',
>     'new', 'null',
>     'out', 'override',
>     'package', 'pragma', 'private', 'protected', 'public',
>     'real', 'return',
>     'short', 'static', 'struct', 'super', 'switch', 'synchronized',
>     'template', 'this', 'throw', 'true', 'try', 'typedef', 'typeid', 'typeof',
>     'ubyte', 'ucent', 'uint', 'ulong', 'union', 'unittest', 'ushort',     'version', 'void', 'volatile',
>     'wchar', 'while', 'with']
> 
> 
> 
> # Regex Links
> 
> # http://www.amk.ca/python/howto/regex/regex.html#SECTION000310000000000000000
> # http://docs.python.org/lib/matching-searching.html
> 
> 
> 
> def dIsAlpha(c):
> #    /* true if c is a letter or an underscore, false otherwise */
> 
>     return c.isalpha() or (c == '_')
> 
> 
> def dIsDigit(c):
> #    /* true if c is a number or an underscore, false otherwise */
> 
>     return c.isdigit() or (c == '_')
> 
> 
> def ishexdigit(c):
> #    /* true if c is a hexadecimal digit, false otherwise */
> 
>     return re.compile("^[0-9A-F_]+$").match(c)
> 
> 
> def isoctdigit(c):
> #    /* true if c is an octal digit, false otherwise */
> 
>     return re.compile("^[0-7_]+$").match(c)
> 
> 
> def issymbol(c):
>     # /* true if c is legal D symbol, false otherwise */
> 
>     # /* "-" also needs to be escaped (in addition to the list at http://www.amk.ca/python/howto/regex/)? */
>     return re.compile(r"^[?~:|!%{}\\\(\)\[\]\.,;=<>\+\-\*/&\^]+$").match(c)
> 
> 
> def iskeyword(token): #, keywords):
> #/* true if token is a D keyword, false otherwise */
>     for x in keywords: #(i = 0; i < count(keywords.length; $i++)  /* keywords.length*/         if (x == token):
>             return True
>     return False
> 
> 
> 
> class Stream: 
> 
>     # /* This somewhat emulates Phobos's Stream class, so I didn't have to completely rewrite d2html. */
> 
>     pos = 0
>     src = ""
>          def position(self):
>         return self.pos
>         def read(self):
>         self.pos = self.pos + 1
>         if(self.pos < len(self.src) + 1):
>             return self.src[self.pos - 1 : self.pos]
>         else:
>             return " "
> 
>     def write(self, c):
>         self.src = self.src + c
> 
>     def writeString(self, c):
>         self.src = self.src + c
> 
>     def writeLine(self, c):
>         self.src = self.src + c + "\n" # /* append with a newline */
> 
>     def __init__(self, s):
>         self.src = s
>         self.pos = 0
> 
> 
> 
> def execute(hdf, text, env):
>     """
>     This function is called when code is embedded in a trac wiki page:
> 
>     {{{
>     #!d
>     int main(char[] args)
>     {
>       printf("Hello World\n");
>       return 0;
>     }
>     }}}
> 
>     The "d" indicates to use the D processor that this file contains.
> 
>     For more information, see http://projects.edgewall.com/trac/wiki/WikiProcessors.
>         """
> 
>     # hdf is an HDFObjectType (and can't be concatenated with a string)
>     # env is an instance (and can't be concatenated with a string)
> 
>     return d2html(text)
> 
> 
> 
> def d2html(raw_code):
> 
>     # * Copyright (c) 2001
>     # * Pavel "EvilOne" Minayev
>     # *
>     # * Permission to use, copy, modify, distribute and sell this software
>     # * and its documentation for any purpose is hereby granted without fee,
>     # * provided that the above copyright notice appear in all copies and
>     # * that both that copyright notice and this permission notice appear
>     # * in supporting documentation.  Author makes no representations about
>     # * the suitability of this software for any purpose. It is provided
>     # * "as is" without express or implied warranty.
>          # * Updated by J C Calvarese, http://jcc_7.tripod.com/d/, 2003/12/18
>     # * Ported to Python by J C Calvarese, 2005/03
> 
> 
>     # ### Porting Tips ###
> 
>     #    Concatenation:
>     #    D:    ~
>     #    PHP:  .
>     #    Python: +
> 
> 
>     # PHP do-while                   Python equivalent
>     # ------------                   -----------------
>     #                                doIt = True
>     # do {                           while(doIt):
>     #     ...                            ...
>     #                                    if not(condition):
>     # } while (condition)                    doIt = False
> 
>     # PHP for                        Python equivalent
>     # -------                        -----------------
>     # for (i = 0; i < spaces; i++)   for i in range(spaces):
> 
> 
>     # By the way, string methods come in handy when doing text processing:
>     # http://docs.python.org/lib/string-methods.html
> 
> 
>     code = raw_code
> 
> 
>     #/* Remove trailing CR and/or LF (doesn't seem to work, but doesn't seem to hurt either). */
> 
>     done = False
> 
>     while done == False:
>         iLen = len(code)
>         code = code.rstrip()
>         if iLen == len(code):
>             done = True
> 
>     tabsize = 4  #/* number of spaces in tab */
>     lineNumber = 0
>     spaces = 0
> 
>         #/* Colors for syntax highlighting, default values are
>     #   Pavel Minayev's preferences in Microsoft Visual Studio editor   */
> 
>     Colors_keyword = "0000FF"
>     Colors_number  = "008000"
>     Colors_string  = "000080"
>     Colors_comment = "808080"
>         #useStyleSheet = True
>     useStyleSheet = False
> 
>     xhtmlFormat = True         linestart = 0  #/* for tabs */
>     c = ""
>     c2 = ""
>         src = Stream(code)
>     dst = Stream("")
> 
>     c = src.read()
>     while src.position() < len(code):
>         if (c.isspace()):     #/* whitespace */
> 
>             doIt = True
>             while(doIt):                 if c == "\t": #/* tab character */
>                     #/* expand tabs to spaces */
>                     spaces = tabsize - (src.position() - linestart) % tabsize
>                     for i in range(spaces):
>                         dst.writeString(" ")
>                     linestart = src.position() - tabsize + 1
>                                         elif c == "\n": #//10: /* linefeed */
>                     linestart = src.position() + 1 #/* reset line start on newline */
>                     dst.write(c)
>                                         elif c == "\r": #//13: /* control return */
>                     linestart = src.position() + 1 #/* reset line start on newline */
>                                             if(c2 != "\n"): #//10)
>                             dst.write(c)
>                                         else: #/* space is left, anything else? */
>                     dst.write(c)
>                                 c2 = c
>                 c = src.read()
>                             if not c.isspace():
>                     doIt = False
> 
>         elif (dIsAlpha(c)):    #/* keyword or identifier */
>             token = ""
>             doIt = True
>             while(doIt):
>                 token = token + c
>                 c = src.read()
>                 if not(dIsAlpha(c) or dIsDigit(c)):
>                     doIt = False
>                         if(iskeyword(token)):  #/* keyword */
>                 if(useStyleSheet):
>                     dst.writeString('<span class="keyword">' + token + "</span>")
>                 else:
>                     dst.writeString("<font color='#" + Colors_keyword +
>                       "'>" + token + "</font>")
>             else:  # /* simple identifier */
>                 dst.writeString(token)
>                         elif (c == '0'):  #/* binary, octal or hexadecimal number */
>             if useStyleSheet:
>                 dst.writeString('<span class="number">')
>             else:
>                 dst.writeString("<font color='#" + Colors_number + "'>")
>             dst.write(c)
>             c = src.read()
>             if c == 'X' or c == 'x':   #/* hexadecimal */
>                 dst.write(c)
>                 c = src.read()
>                 while ishexdigit(c):
>                     dst.write(c)
>                     c = src.read()
> 
>                 # /* TODO: add support for hexadecimal floats */
>             elif (c == 'B' or c == 'b'):  #/* binary */
>                 dst.write(c)
>                 c = src.read()
>                 while c == '0' or c == '1' or c == '_':
>                     dst.write(c)
>                     c = src.read()
>             else:    #/* octal */
> 
>                 doIt = True
>                 while (doIt):
>                     dst.write(c)
>                     c = src.read()
>                     if not(isoctdigit(c)):
>                         doIt = False
>                 dst.write(c)
>                 c = src.read()
> 
>             if useStyleSheet:
>                 dst.writeString("</span>")
>             else:
>                 dst.writeString("</font>")
> 
>         elif dIsDigit(c):    #/* decimal number */
>             if(useStyleSheet):
>                 dst.writeString('<span class="number">')
>             else:
>                 dst.writeString("<font color='#" + Colors_number + "'>")
>             #/* integral part */
>             doIt = True
>             while(doIt):
>                 dst.write(c)
>                 c = src.read()
>                 if not(dIsDigit(c)):
>                     doIt = False
>                         #/* fractional part */
>             if c == '.':
>                 dst.write(c)
>                 c = src.read()
>                 while dIsDigit(c):
>                     dst.write(c)
>                     c = src.read()
> 
>             #/* scientific notation */
>             if c == 'E' or c == 'e':
>                 dst.write(c)
>                 c = src.read()
>                 if c == '+' or c == '-':
>                     dst.write(c)
>                     c = src.read()
>                 while dIsDigit(c):
>                     dst.write(c)
>                     c = src.read()
> 
>             #/* suffixes */
>             while c == 'U' or c == 'u' or c == 'L' or c == 'l' or c == 'F' or c == 'f':
>                 dst.write(c)
>                 c = src.read()
> 
>             if useStyleSheet:
>                 dst.writeString("</span>")
>             else:
>                 dst.writeString("</font>")
> 
>         elif c == "\\":   #/* naked escape sequence (\) */
>             if(useStyleSheet):
>                 dst.writeString("<span class=\"string\">")
>             else:                    dst.writeString("<font color='#" + Colors_string + "'>")
>             dst.write(c)
>             prev = c
>             c = src.read()
>             dst.write(c)
>             c = src.read()
>                 if useStyleSheet:
>                 dst.writeString("</span>")
>             else:
>                 dst.writeString("</font>")
> 
>         elif c == "\"":  #/* string (") with escape sequences  */
> 
>             if(useStyleSheet):
>                 dst.writeString('<span class="string">')
>             else:                    dst.writeString("<font color='#" + Colors_string + "'>")
>             doIt = True
>             while(doIt):
>                 if c == '<':   #/* special symbol in HTML */
>                     dst.writeString("&lt;")
>                 else:
>                     dst.write(c)
>                                 prev = c
>                 if ((prev == '\\' and c == '"') or (prev == '\\' and c == '\\') and not isEscape):                     isEscape = True
>                 else:
>                     isEscape = False
>                                 c = src.read()
>                 if not(isEscape or c != '"'):
>                     doIt = False
>                         dst.write(c)
>             c = src.read()
> 
>             if useStyleSheet:                            dst.writeString("</span>")
>             else:
>                 dst.writeString("</font>")
>                     elif c == "'":   #/* character (') with escape sequences  */
>             if useStyleSheet:
>                 dst.writeString('<span class="string">')
>             else:
>                 dst.writeString("<font color='#" + Colors_string + "'>")
>             doIt = True
>             while(doIt):
>                 if c == '<':   #/* special symbol in HTML */
>                     dst.writeString("&lt;")
>                 else:
>                     dst.write(c)
>                                     prev = c
>                                 if (prev == "\\" and c == "'") or (prev == "\\" and c == "\\") and not isEscape:
>                     isEscape = True
>                 else:
>                     isEscape = False
>                                 c = src.read()
>                 if not(isEscape or c != '\''):
>                     doIt = False
>                         dst.write(c)
>             c = src.read()
> 
>             if useStyleSheet:                            dst.writeString("</span>")
>             else:
>                 dst.writeString("</font>")
> 
>         elif c == '`':  #/* character (`) with no escape sequences */
>             if useStyleSheet:
>                 dst.writeString('<span class="string">')
>             else:                    dst.writeString("<font color='#" + Colors_string + "'>")
>             doIt = True
>             while(doIt):
>                 if (c == '<'):   #/* special symbol in HTML */
>                     dst.writeString("&lt;")
>                 else:
>                     dst.write(c)
>                 c = src.read()
>                 if c == "`": #/* 96 */
>                     doIt = False
>             dst.write(c)
>             c = src.read()
> 
>             if useStyleSheet:
>                 dst.writeString("</span>")
>             else:
>                 dst.writeString("</font>")
> 
>         elif issymbol(c):   #/* either operator or comment */
> 
>             if c == '<':   #/* special symbol in HTML */
>                 dst.writeString("&lt;")
>                 c = src.read()
> 
>             elif c == '/':  #/* could be a comment... */
>                 c = src.read()
>                 if c == '/':   #/* single-line one */
>                     if useStyleSheet:
>                         dst.writeString("<span class=\"comment\">/")
>                     else:
>                         dst.writeString("<font color='#" + Colors_comment + "'>/")
>                     while c != "\n" and c != "\r": #//10 and $c != 13:
> 
>                         if c == '<':   #/* special symbol in HTML */
>                             dst.writeString("&lt;")
>                         elif c == "\t": #// 9
>                             #/* expand tabs */
>                             spaces = tabsize - (src.position() - linestart) % tabsize
>                             for i in range(spaces):
>                                 dst.writeString(" ")
>                             linestart = src.position() - tabsize + 1
> 
>                         else:
>                             dst.write(c)
>                         c2 = c
>                         c = src.read()
> 
>                     if useStyleSheet:
>                         dst.writeString("</span>")
>                     else:
>                         dst.writeString("</font>")
> 
>                 elif (c == '*'):  #/* multi-line one */
>                     prevprev = ""
>                     prev = '/'
>                                                             if useStyleSheet:
>                         dst.writeString('<span class="comment">/');
>                     else:                                                dst.writeString("<font color='#" + Colors_comment + "'>/")
>                     doIt = True
>                     while(doIt):
>                         if c == '<':   #/* special symbol in HTML */
>                             dst.writeString("&lt;")
>                         elif (c == "\t"): #//9)
>                             #/* expand tabs */
>                             spaces = tabsize - (src.position() - linestart) % tabsize
>                             for i in range(spaces):
>                                 dst.writeString(" ")
>                             linestart = src.position() - tabsize + 1
>                         else:
>                             if(c == "\n" or c == "\r"): #//c == 10 || c == 13)
>                                 linestart = src.position() + 1 #/* reset line start on newline */                                                        dst.write(c)
>                         prevprev = prev
>                         prev = c
>                         c = src.read()
>                         if prevprev != '/' and prev == '*' and c == '/':
>                             doIt = False
>                     dst.write(c)
> 
>                     if useStyleSheet:                                            dst.writeString("</span>")
>                     else:
>                         dst.writeString("</font>")
>                                         c = src.read()
> 
>                 elif (c == '+'):  #/* nestable multi-line comment */
> 
>                     prevprev = '/'
>                     prev = '+'
>                     level = 0                                                            if useStyleSheet:
>                         dst.writeString("<span class=\"comment\">/")
>                     else:
>                         dst.writeString("<font color='#" + Colors_comment + "'>/")
>                     doIt = True
>                     while(doIt):
>                         if (c == '<'):   #/* special symbol in HTML */
>                             dst.writeString("&lt;")
>                         elif (c == "\t"): #//9)
> 
>                             #/* expand tabs */
>                             spaces = tabsize - (src.position() - linestart) % tabsize
>                             for i in range(spaces):
>                                 dst.writeString(" ")
>                             linestart = src.position() - tabsize + 1
> 
>                         else:
>                             #/* reset line start on newline */
>                             if (c == "\n" or c == "\r"): #//10 || $c == 13)
>                                 linestart = src.position() + 1
>                             dst.write(c)
>                                                         if (prev == '/' and c == '+'):
>                                 level = level + 1
>                                                         if (prevprev != '/' and prev == '+' and c == '/'):
>                                 level = level - 1
>                         prevprev = prev
>                         prev = c
>                         c = src.read()
>                         if prev == '+' and c == '/' and level == 0:
>                             doIt = False
>                     dst.write(c)
>                     if useStyleSheet:
>                         dst.writeString("</span>")
>                     else:
>                         dst.writeString("</font>")
>                     c = src.read()
>                 else:    #/* just an operator */
>                     dst.write('/')
> 
>             else:    #/* just an operator */
>                 dst.write(c)
>                 c = src.read()
>         else:
>             #/* whatever it is, it doesn't seem to be valid */
>             dst.write("{error!}")
> 
>     dst.write(c)
>     strippedSrc = dst.src.strip
>     if(strippedSrc != ""): #/* make sure there's actual content */
>         return "<pre class=\"code-block\"><code>" + dst.src + "</code></pre>"
>         #  class=\"example\"
>     return ""
March 19, 2005
Brad Anderson wrote:
> Looks great.  I'll check it out tomorrow.  Thanks!!

I hope it works for you too. ;)

> 
> Did you think about integrating with the 3rd party tools here:
> http://projects.edgewall.com/trac/wiki/TracSyntaxColoring

Yeah, I've heard of that. I'd be more somewhat more interested if I could write it in D, PHP, Python, BASIC, or Java.

> This would extend the syntax highlighting to the source-code browser instead of just Wiki pages.  Although it would need to be in Scintilla for SilverCity.  That's C++ (ick) instead of Python...

"Ick" is right. I don't really know C++, and I'm not particularly interested in learning it right now. Maybe next year. ;)

I don't really know much Python either, but I think that scripting languages make trial-and-error a lot safer (and more effective) than the raw power of (non-garbage-collected) C and C++ would.

I remember reading that someone was interested in writing a Scintilla lexer. More power to him if someone wants to do that, but personally I'd prefer to tweak the Python code that we have now than start programming in C++.

> 
> Still, it's cool progress, and I need a jump-start.

It ended up being easy to port. When I was working on it back in August, I lost interest when I discovered that Python doesn't have a do-while construct. (Not that I really expected that to be a major problem.) I just felt like shelving the project at that point. Then when I picked it up again the other day, I quickly realized that it was going to be easy to complete it. So I went ahead and finished off the conversion while I was still in a good mood about it. :)

-- 
Justin (a/k/a jcc7)
http://jcc_7.tripod.com/d/
1 2
Next ›   Last »