Click here to Skip to main content
12,696,920 members (29,059 online)
Click here to Skip to main content

Stats

82.5K views
1.5K downloads
78 bookmarked
Posted

Implement an Autoplay Handler

, 18 Sep 2006 CPOL
Implementing an Autoplay handler in C#.
/********************************************************
 *	Author: Andrew Deren
 *	Date: July, 2004
 *	http://www.adersoftware.com
 * 
 *	StringTokenizer class. You can use this class in any way you want
 *	as long as this header remains in this file.
 * 
 *	Modified by T.Almdal
 *	To add addition tokens
 * 
 **********************************************************/

using System;
using System.Text;

namespace Almdal.RegistryScript {
	public enum TokenKind {
		Unknown,
		Word,
		Number,
		QuotedString,
        String,
		WhiteSpace,
		Symbol,
        StartKey,
        EndKey,
		Assignment,
		EOL,
		EOF
	}

	public class Token {
		int line;
		int column;
		string value;
		TokenKind kind;

		public Token(TokenKind kind, string value, int line, int column) {
			this.kind = kind;
			this.value = value;
			this.line = line;
			this.column = column;
		}

		public int Column {
			get { return this.column; }
		}

		public TokenKind Kind {
			get { return this.kind; }
		}

		public int Line {
			get { return this.line; }
		}

		public string Value {
			get { return this.value; }
		}

		public string ParsePosition {
			get {
				StringBuilder sb = new StringBuilder();
				sb.Append('(').Append(Line).Append(", ").Append(Column).Append(')');
				return sb.ToString();
			}
		}
        public override string ToString() {
            StringBuilder sb = new StringBuilder();
            sb.Append(base.ToString());
            sb.Append("[Kind: ").Append(Kind);
            sb.Append("; Value: ");
            switch (Kind) {
                case TokenKind.WhiteSpace:
                    sb.Append('"').Append(Value).Append('"');
                    break;
                case TokenKind.Unknown:
                case TokenKind.Symbol:
                    sb.Append('\'').Append(Value).Append('\'');
                    break;
                case TokenKind.EOL:
                    sb.Append("New Line");
                    break;
                default:
                    sb.Append(Value);
                    break;
            }
			sb.Append("; Position ").Append(ParsePosition).Append("]");
            return sb.ToString();
        }
	}

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Tim Almdal
Canada Canada
No Biography provided

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170118.1 | Last Updated 18 Sep 2006
Article Copyright 2006 by Tim Almdal
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid