Test for the new Colorize processor
just to show the difference to http://fp2.sky.rhein-zeitung.de/moin.fcg/ColorizeTest
unnumbered:
############################################################################# class Parser(ParserBase): . def __init__(self, raw, request, **kw): . ParserBase.__init__(self,raw,request,**kw) self.addRulePair("Comment","/[*]","[*]/") self.addRule("Comment","//.*$") self.addRulePair("String",'"',r'$|[^\\](\\\\)*"') self.addRule("Char",r"'\\.'|'[^\\]'") self.addRule("Number",r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?") self.addRule("ID","[a-zA-Z_][0-9a-zA-Z_]*") self.addRule("SPChar",r"[~!%^&*()+=|\[\]:;,.<>/?{}-]") reserved_words = ['class','interface','enum','import','package', . 'byte','int','long','float','double','char','short','void','boolean', 'static','final','const','private','public','protected', 'new','this','super','abstract','native','synchronized','transient','volatile','strictfp', 'extends','implements','if','else','while','for','do','switch','case','default','instanceof', 'try','catch','finally','throw','throws','return','continue','break'] self.addReserved(reserved_words) constant_words = ['true','false','null'] self.addConstant(constant_words)
numbered with moved start:
from MoinMoin.util.ParserBase import ParserBase ############################################################################# class Parser(ParserBase): def __init__(self, raw, request, **kw): ParserBase.__init__(self,raw,request,**kw) self.addRulePair("Comment","/[*]","[*]/") self.addRule("Comment","//.*$") self.addRulePair("String",'"',r'$|[^\\](\\\\)*"') self.addRule("Char",r"'\\.'|'[^\\]'") self.addRule("Number",r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?") self.addRule("ID","[a-zA-Z_][0-9a-zA-Z_]*") self.addRule("SPChar",r"[~!%^&*()+=|\[\]:;,.<>/?{}-]") reserved_words = ['class','interface','enum','import','package', 'byte','int','long','float','double','char','short','void','boolean', 'static','final','const','private','public','protected', 'new','this','super','abstract','native','synchronized','transient','volatile','strictfp', 'extends','implements','if','else','while','for','do','switch','case','default','instanceof', 'try','catch','finally','throw','throws','return','continue','break'] self.addReserved(reserved_words) constant_words = ['true','false','null'] self.addConstant(constant_words)
import java.util.Date; import java.util.Calendar; public class IntDate { public static Date getDate(String year, String month, String day) { // Date(int, int, int) has been deprecated, so use Calendar to // set the year, month, and day. Calendar c = Calendar.getInstance(); // Convert each argument to int. c.set(Integer.parseInt(year),Integer.parseInt(month),Integer.parseInt(day)); return c.getTime(); } }
#include <stdio.h> #include <Python.h> #include <string.h> #include "jodafulltext.h" static PyObject* joda_open_jodaDB(PyObject *self, PyObject *args) { int h; char *dbname="dummy"; int readonly=0; if (!PyArg_ParseTuple(args,"si:jodaopen",&dbname,&readonly)) return NULL; h=jodaOpen(dbname,readonly); return Py_BuildValue("i",h); }
basic? no pascal!
Unit RegExprO; {$H+} INTERFACE uses RegExpression; type TRegEx = class constructor Create(pattern:string); destructor Destroy; OVERRIDE; function MatchPos(s:string; var index,len:integer):boolean; function Match(const s:string):boolean; PROTECTED rex : TRegExprEngine; end; IMPLEMENTATION constructor TRegEx.Create(pattern:string); begin inherited Create; pattern := pattern + #0; rex := GenerateRegExprEngine(PChar(pattern),[]); end; destructor TRegEx.Destroy; begin DestroyregExprEngine(rex); end; function TRegEx.Match(const s:string):boolean; var l,i : integer; begin result := MatchPos(s,l,i); end; function TRegEx.MatchPos(s:string; var index,len:integer):boolean; begin s := s + #0; result := RegExprPos(rex,PChar(s),index,len); index := index+1; end; end.