Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

R# or Rebol Sharp on DotNET

 [1/2] from: andrew:martin:colenso:school at: 24-Dec-2003 22:40


Here's what I've got after two or three evenings of work: /* Name: R# Title: "R# (Rebol Sharp)" File: %R#.cs Purpose: "Allows C# to read Rebol and Rebol Sharp data values." Author: "Andrew Martin" Date: 15/October/2003 Version: 0.1.0 */ using System; using System.IO; using System.Windows.Forms; using System.Globalization; using System.Text.RegularExpressions; namespace Aztecnology.Rebol { public class Value { protected String Delimiter; protected String Title; protected Regex Pattern; protected bool IsDebug; public Value () { Delimiter = @"(\s|\[|\]|\z)"; Title = "Value"; Pattern = new Regex (Delimiter); IsDebug = true; } public bool IsValue (String Source, int Index) { return Pattern.IsMatch (Source, Index); } public void Load (String Source, ref int Index) { Match mPattern = Pattern.Match (Source, Index); if (IsDebug) { MessageBox.Show ( Title + ": " + Source.Substring (Index, mPattern.Length), Title ); } Index += mPattern.Length; } } public class White_Space : Value { public White_Space () { Title = "White Space"; Pattern = new Regex (@"\G\s+"); IsDebug = false; } } public class Comment : Value { public Comment () { Title = "Comment"; Pattern = new Regex (@"\G;[^\n]*(\n|\z)"); } } public class Time : Value { public Time () { Title = "Time"; Pattern = new Regex (@"\G\d{1,2}:\d{2}:\d{2}" + Delimiter); } } public class Integer : Value { public Integer () { Title = "Integer"; Pattern = new Regex (@"\G\d{1,3}" + Delimiter); } } public class Signed_Integer : Value { public Signed_Integer () { Title = "Signed Integer"; Pattern = new Regex (@"\G(\+|\-)\d{1,3}" + Delimiter); } } public class Number_Units : Value { public Number_Units () { Title = "Number Units"; Pattern = new Regex (@"\G\d{1,3}[^\s]+" + Delimiter); } } public class Rebol_Sharp { private static string Title = "R#"; private Value vValue = new Value (); private White_Space white_space = new White_Space (); private Comment comment = new Comment (); private Time tTime = new Time (); private Signed_Integer signed_integer = new Signed_Integer (); private Integer iInteger = new Integer (); private Number_Units number_units = new Number_Units (); public void Load (String Source) { int Index = 0; int Length = Source.Length; while (Index < Length) { if (white_space.IsValue (Source, Index)) { white_space.Load (Source, ref Index); continue; } if (comment.IsValue (Source, Index)) { comment.Load (Source, ref Index); continue; } if (tTime.IsValue (Source, Index)) { tTime.Load (Source, ref Index); continue; } if (signed_integer.IsValue (Source, Index)) { signed_integer.Load (Source, ref Index); continue; } if (iInteger.IsValue (Source, Index)) { iInteger.Load (Source, ref Index); continue; } if (number_units.IsValue (Source, Index)) { number_units.Load (Source, ref Index); continue; } Index++; } } public static void Main (string[] args) { Rebol_Sharp r = new Rebol_Sharp (); StreamReader sr = new StreamReader ("Rebol.txt"); r.Load (sr.ReadToEnd ()); MessageBox.Show ("Bye!", Title); } } } /* End. */ And here's the two lines in the .bat (batch) file that I use to compile the above program: csc /target:winexe /out:R#.exe /reference:System.dll /reference:System.Windows.Forms.dll /reference:System.Drawing.dll /win32icon:R#.ico R#.cs pause And here's the contents of %Rebol.txt: +12 -23 123 12:34:56 2:34:56 99% 110% 50Km/H 6' 3" 60MpH 99Meters ; Test. Word :GetWord SetWord: ; Last line. So far, I've gotten the above C# program to recognise signed and unsigned numbers, time, "Number_Units" (I really need a better than for these!), white space and single line comments (ones starting with ";"). After looking further at the Globalisation features in DotNET, I think it would be reasonably easy to provide other currencies for the money datatype, and to use commas for thousand separators with period (full stop) for the decimal point and the reverse (period for thousands separators and comma for decimal point). For a script to be localised, the R# script header could have DotNET "locale" value, which adjusts the R# interpreter to use the appropriate locale's settings for thousand separators and commas. Andrew J Martin Attendance Officer & Grail Jedi. Colenso High School Arnold Street, Napier. Tel: 64-6-8310180 ext 826 Fax: 64-6-8336759 http://colenso.net/scripts/Wiki.r?AJM http://www.colenso.school.nz/ DISCLAIMER: Colenso High School and its Board of Trustees is not responsible (or legally liable) for materials distributed to or acquired from user e-mail accounts. You can report any misuse of an e-mail account to our ICT Manager and the complaint will be investigated. (Misuse can come in many forms, but can be viewed as any material sent/received that indicate or suggest pornography, unethical or illegal solicitation, racism, sexism, inappropriate language and/or other issues described in our Acceptable Use Policy.) All outgoing messages are certified virus-free by McAfee GroupShield Exchange 5.10.285.0 Phone: +64 6 843 5095 or Fax: +64 6 833 6759 or E-mail: [postmaster--colenso--school--nz]

 [2/2] from: andrew::martin::colenso::school::nz at: 24-Dec-2003 22:40


Earlier, I wrote:
> ..."Number_Units" (I really need a better [name] for these!)
Taking a hint from the Core PDF about money data-types, I'm now using Scalar to name values like these: 50Km/H 60MpH 99Meters 12.3cm and so on. Andrew J Martin Attendance Officer & Grail Jedi. Colenso High School Arnold Street, Napier. Tel: 64-6-8310180 ext 826 Fax: 64-6-8336759 http://colenso.net/scripts/Wiki.r?AJM http://www.colenso.school.nz/ DISCLAIMER: Colenso High School and its Board of Trustees is not responsible (or legally liable) for materials distributed to or acquired from user e-mail accounts. You can report any misuse of an e-mail account to our ICT Manager and the complaint will be investigated. (Misuse can come in many forms, but can be viewed as any material sent/received that indicate or suggest pornography, unethical or illegal solicitation, racism, sexism, inappropriate language and/or other issues described in our Acceptable Use Policy.) All outgoing messages are certified virus-free by McAfee GroupShield Exchange 5.10.285.0 Phone: +64 6 843 5095 or Fax: +64 6 833 6759 or E-mail: [postmaster--colenso--school--nz]