Exemple #1
0
		public ClassDelegate this[TokenClass c] {
			get {
				return callbacks[(int)c];
			}

			set {
				callbacks[(int)c] = value;
			}
		}
		public RTFException(RTF rtf, string error_message) {
			this.pos = rtf.LinePos;
			this.line = rtf.LineNumber;
			this.token_class = rtf.TokenClass;
			this.major = rtf.Major;
			this.minor = rtf.Minor;
			this.param = rtf.Param;
			this.text = rtf.Text;
			this.error_message = error_message;
		}
		/// <summary>
		/// Gets the <see cref="HighlightColor"/> for the specified class of
		/// token.
		/// </summary>
		/// <param name="p_ttpTokenClass">The token class for which the
		/// <see cref="HighlightColor"/> is to be returned.</param>
		/// <returns>The <see cref="HighlightColor"/> for the specified class of
		/// token.</returns>
		public HighlightColor GetColorFor(TokenClass p_ttpTokenClass)
		{
			switch (p_ttpTokenClass)
			{
				case TokenClass.Operator:
					return new HighlightColor(Color.ForestGreen, false, false);
				case TokenClass.String:
					return new HighlightColor(Color.Maroon, false, false);
				case TokenClass.Keyword:
					return new HighlightColor(Color.Red, false, false);
				case TokenClass.Variable:
					return new HighlightColor(Color.Blue, false, false);
				default:
					return defaultHighlightingStrategy.GetColorFor("DefaultColor");
			}
		}
		public StyleElement(Style s, TokenClass token_class, Major major, Minor minor, int param, string text) {
			this.token_class = token_class;
			this.major = major;
			this.minor = minor;
			this.param = param;
			this.text = text;

			lock (s) {
				if (s.Elements == null) {
					s.Elements = this;
				} else {
					StyleElement se = s.Elements;
					while (se.next != null)
						se = se.next;
					se.next = this;
				}
			}
		}
Exemple #5
0
 public bool Match(TokenClass clazz)
 {
     return PeekToken () != null && PeekToken ().Class == clazz;
 }
Exemple #6
0
 public bool Match(TokenClass clazz1, TokenClass clazz2)
 {
     return PeekToken () != null && PeekToken ().Class == clazz1 &&
         PeekToken (1) != null &&
         PeekToken (1).Class == clazz2;
 }
Exemple #7
0
 public bool Accept(TokenClass clazz, string val)
 {
     if (PeekToken () != null && PeekToken ().Class == clazz && PeekToken ().Value == val) {
         ReadToken ();
         return true;
     }
     return false;
 }
Exemple #8
0
 public Token Expect(TokenClass clazz, string val)
 {
     Token ret = PeekToken ();
     if (Accept (clazz, val)) {
         return ret;
     }
     Token offender = ReadToken ();
     if (offender != null) {
         errorLog.AddError (ErrorType.ParserError, offender.Location,
             "Unexpected '{0}' (Expected '{1}')", offender.ToString (), Token.ClassToString (
             clazz));
     } else {
         errorLog.AddError (ErrorType.ParserError, offender.Location,
             "Unexpected end of file (Expected {0})", Token.ClassToString (clazz));
         throw new Exception ("");
     }
     return new Token (clazz, "", Location);
 }
Exemple #9
0
		private void GetToken2() {
			char	c;
			int	sign;

			this.rtf_class = TokenClass.Unknown;
			this.param = NoParam;

			this.text_buffer.Length = 0;

			if (this.pushed_char != EOF) {
				c = this.pushed_char;
				this.text_buffer.Append(c);
				this.pushed_char = EOF;
			} else if ((c = GetChar()) == EOF) {
				this.rtf_class = TokenClass.EOF;
				return;
			}

			if (c == '{') {
				this.rtf_class = TokenClass.Group;
				this.major = Major.BeginGroup;
				return;
			}

			if (c == '}') {
				this.rtf_class = TokenClass.Group;
				this.major = Major.EndGroup;
				return;
			}

			if (c != '\\') {
				if (c != '\t') {
					this.rtf_class = TokenClass.Text;
					this.major = (Major)c;	// FIXME - typing?
					return;
				} else {
					this.rtf_class = TokenClass.Control;
					this.major = Major.SpecialChar;
					this.minor = Minor.Tab;
					return;
				}
			}

			if ((c = GetChar()) == EOF) {
				// Not so good
				return;
			}

			if (!Char.IsLetter(c)) {
				if (c == '\'') {
					char c2;

					if ((c = GetChar()) == EOF) {
						return;
					}

					if ((c2 = GetChar()) == EOF) {
						return;
					}

					this.rtf_class = TokenClass.Text;
					this.major = (Major)((Char)((Convert.ToByte(c.ToString(), 16) * 16 + Convert.ToByte(c2.ToString(), 16))));
					return;
				}

				// Escaped char
				if (c == ':' || c == '{' || c == '}' || c == '\\') {
					this.rtf_class = TokenClass.Text;
					this.major = (Major)c;
					return;
				}

				Lookup(this.text_buffer.ToString());
				return;
			}

			while (Char.IsLetter(c)) {
				if ((c = GetChar()) == EOF) {
					break;
				}
			}

			if (c != EOF) {
				this.text_buffer.Length--;
			}

			Lookup(this.text_buffer.ToString());

			if (c != EOF) {
				this.text_buffer.Append(c);
			}

			sign = 1;
			if (c == '-') {
				sign = -1;
				c = GetChar();
			}

			if (c != EOF && Char.IsDigit(c)) {
				this.param = 0;
				while (Char.IsDigit(c)) {
					this.param = this.param * 10 + Convert.ToByte(c) - 48;
					if ((c = GetChar()) == EOF) {
						break;
					}
				}
				this.param *= sign;
			}

			if (c != EOF) {
				if (c != ' ') {
					this.pushed_char = c;
				}
				this.text_buffer.Length--;
			}
		}
Exemple #10
0
 public bool Accept(TokenClass clazz, ref Token token)
 {
     if (PeekToken () != null && PeekToken ().Class == clazz) {
         token = ReadToken ();
         return true;
     }
     return false;
 }
Exemple #11
0
 /// <summary>
 /// Converts a TokenClass enum to its string representation
 /// </summary>
 /// <returns>The string representation of the TokenClass enum.</returns>
 /// <param name="clazz">Token class.</param>
 public static string ClassToString(TokenClass clazz)
 {
     switch (clazz) {
     case TokenClass.CloseBrace:
         return "}";
     case TokenClass.OpenBrace:
         return "{";
     case TokenClass.CloseParan:
         return ")";
     case TokenClass.OpenParan:
         return "(";
     case TokenClass.Comma:
         return ",";
     case TokenClass.OpenBracket:
         return "[";
     case TokenClass.CloseBracket:
         return "]";
     case TokenClass.SemiColon:
         return ";";
     case TokenClass.Colon:
         return ":";
     default:
         return clazz.ToString ();
     }
 }
Exemple #12
0
		public void UngetToken() {
			if (this.pushed_class != TokenClass.None) {
				throw new RTFException(this, "Cannot unget more than one token");
			}

			if (this.rtf_class == TokenClass.None) {
				throw new RTFException(this, "No token to unget");
			}

			this.pushed_class = this.rtf_class;
			this.pushed_major = this.major;
			this.pushed_minor = this.minor;
			this.pushed_param = this.param;
			//this.pushed_text_buffer = new StringBuilder(this.text_buffer.ToString());
		}
Exemple #13
0
 public Token(TokenClass clazz, object val, int line)
 {
     this.tokenClass = clazz;
     this.tokenValue = val;
     this.line = line;
 }
Exemple #14
0
 public void CopyFrom(Token t)
 {
     Start = t.Start; End = t.End; Line = t.Line; Column = t.Column; Identation = t.Identation; tokenClass = t.tokenClass; stringClass = t.stringClass; serverTagClass = t.serverTagClass; Value = t.Value;
 }
Exemple #15
0
		public RTF(Stream stream) {
			source = new StreamReader(stream);

			text_buffer = new StringBuilder(1024);
			//pushed_text_buffer = new StringBuilder(1024);

			rtf_class = TokenClass.None;
			pushed_class = TokenClass.None;
			pushed_char = unchecked((char)-1);

			line_num = 0;
			line_pos = 0;
			prev_char = unchecked((char)-1);
			bump_line = false;

			cur_charset = new Charset();

			destination_callbacks = new DestinationCallback();
			class_callbacks = new ClassCallback();

			destination_callbacks [Minor.OptDest] = new DestinationDelegate (HandleOptDest);
			destination_callbacks[Minor.FontTbl] = new DestinationDelegate(ReadFontTbl);
			destination_callbacks[Minor.ColorTbl] = new DestinationDelegate(ReadColorTbl);
			destination_callbacks[Minor.StyleSheet] = new DestinationDelegate(ReadStyleSheet);
			destination_callbacks[Minor.Info] = new DestinationDelegate(ReadInfoGroup);
			destination_callbacks[Minor.Pict] = new DestinationDelegate(ReadPictGroup);
			destination_callbacks[Minor.Object] = new DestinationDelegate(ReadObjGroup);
		}
Exemple #16
0
		public bool CheckCMM(TokenClass rtf_class, Major major, Minor minor) {
			if ((this.rtf_class == rtf_class) && (this.major == major) && (this.minor == minor)) {
				return true;
			}

			return false;
		}
Exemple #17
0
		public void Lookup(string token) {
			Object		obj;
			KeyStruct	key;

			obj = key_table[token.Substring(1)];
			if (obj == null) {
				rtf_class = TokenClass.Unknown;
				major = (Major) -1;
				minor = (Minor) -1;
				return;
			}

			key = (KeyStruct)obj;
			this.rtf_class = TokenClass.Control;
			this.major = key.Major;
			this.minor = key.Minor;
		}
Exemple #18
0
 public bool Match(TokenClass clazz, string val)
 {
     return PeekToken () != null &&
         PeekToken ().Class == clazz &&
         PeekToken ().Value == val;
 }
Exemple #19
0
 public TokenExpression()
 {
     this.token = new TokenClass(this);
 }
Exemple #20
0
 public Token()
     : base()
 {
     Identation = string.Empty; tokenClass = TokenClass.Whitespace; stringClass = Html.StringClass.DoubleQuote; serverTagClass = Html.ServerTagClass.Expression; Value = string.Empty;
     Line = 1; Column = 1; Start = 0; End = 0;
 }
Exemple #21
0
		public void SetToken(TokenClass cl, Major maj, Minor min, int par, string text) {
			this.rtf_class = cl;
			this.major = maj;
			this.minor = min;
			this.param = par;
			if (par == NoParam) {
				this.text_buffer = new StringBuilder(text);
			} else {
				this.text_buffer = new StringBuilder(text + par.ToString());
			}
		}
Exemple #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Iodine.Compiler.Token"/> class.
 /// </summary>
 /// <param name="clazz">Token class.</param>
 /// <param name="value">Value.</param>
 /// <param name="location">Location.</param>
 public Token(TokenClass clazz, string value, Location location)
 {
     this.Class = clazz;
     this.Value = value;
     this.Location = location;
 }
 public void Set(TokenClass tokenClass, string value = "")
 {
     Class = tokenClass;
     Value = value;
 }
Exemple #24
0
 public Token(TokenClass tokenClass)
     : this()
 {
     Class = tokenClass;
 }
Exemple #25
0
		/// <summary>Return the next token in the stream</summary>
		public TokenClass GetToken() {
			if (pushed_class != TokenClass.None) {
				this.rtf_class = this.pushed_class;
				this.major = this.pushed_major;
				this.minor = this.pushed_minor;
				this.param = this.pushed_param;
				this.pushed_class = TokenClass.None;
				return this.rtf_class;
			}

			GetToken2();

			if (this.rtf_class == TokenClass.Text) {
				this.minor = (Minor)this.cur_charset[(int)this.major];
			}

			if (this.cur_charset.Flags == CharsetFlags.None) {
				return this.rtf_class;
			}

			if (((this.cur_charset.Flags & CharsetFlags.Read) != 0) && CheckCM(TokenClass.Control, Major.CharSet)) {
				this.cur_charset.ReadMap();
			} else if (((this.cur_charset.Flags & CharsetFlags.Switch) != 0) && CheckCMM(TokenClass.Control, Major.CharAttr, Minor.FontNum)) {
				Font	fp;

				fp = Font.GetFont(this.font_list, this.param);

				if (fp != null) {
					if (fp.Name.StartsWith("Symbol")) {
						this.cur_charset.ID = CharsetType.Symbol;
					} else {
						this.cur_charset.ID = CharsetType.General;
					}
				} else if (((this.cur_charset.Flags & CharsetFlags.Switch) != 0) && (this.rtf_class == TokenClass.Group)) {
					switch(this.major) {
						case Major.BeginGroup: {
							this.charset_stack.Push(this.cur_charset);
							break;
						}

						case Major.EndGroup: {
							this.cur_charset = (Charset)this.charset_stack.Pop();
							break;
						}
					}
				}
			}

			return this.rtf_class;
		}
Exemple #26
0
		/// <summary>
		/// Initializes a new instance of the <see cref="Iodine.Compiler.Token"/> class.
		/// </summary>
		/// <param name="clazz">Token class.</param>
		/// <param name="value">Value.</param>
		/// <param name="location">Location.</param>
		public Token (TokenClass clazz, string value, SourceLocation location)
		{
			Class = clazz;
			Value = value;
			Location = location;
		}
Exemple #27
0
		/// <summary>Return the next token in the stream</summary>
		public TokenClass GetToken() {
			if (pushed_class != TokenClass.None) {
				this.rtf_class = this.pushed_class;
				this.major = this.pushed_major;
				this.minor = this.pushed_minor;
				this.param = this.pushed_param;
				this.pushed_class = TokenClass.None;
				return this.rtf_class;
			}

			GetToken2();

			if (this.rtf_class == TokenClass.Text) {
				this.minor = (Minor)this.cur_charset[(int)this.major];
				if (encoding == null) {
					encoding = Encoding.GetEncoding (encoding_code_page);
				}
				encoded_text = new String (encoding.GetChars (new byte [] { (byte) this.major }));
			}

			if (this.cur_charset.Flags == CharsetFlags.None) {
				return this.rtf_class;
			}

			if (CheckCMM (TokenClass.Control, Major.Unicode, Minor.UnicodeAnsiCodepage)) {
				encoding_code_page = param;

				// fallback to the default one in case we have an invalid value
				if (encoding_code_page < 0 || encoding_code_page > 65535)
					encoding_code_page = DefaultEncodingCodePage;
			}

			if (((this.cur_charset.Flags & CharsetFlags.Read) != 0) && CheckCM(TokenClass.Control, Major.CharSet)) {
				this.cur_charset.ReadMap();
			} else if (((this.cur_charset.Flags & CharsetFlags.Switch) != 0) && CheckCMM(TokenClass.Control, Major.CharAttr, Minor.FontNum)) {
				Font	fp;

				fp = Font.GetFont(this.font_list, this.param);

				if (fp != null) {
					if (fp.Name.StartsWith("Symbol")) {
						this.cur_charset.ID = CharsetType.Symbol;
					} else {
						this.cur_charset.ID = CharsetType.General;
					}
				} else if (((this.cur_charset.Flags & CharsetFlags.Switch) != 0) && (this.rtf_class == TokenClass.Group)) {
					switch(this.major) {
						case Major.BeginGroup: {
							this.charset_stack.Push(this.cur_charset);
							break;
						}

						case Major.EndGroup: {
							this.cur_charset = (Charset)this.charset_stack.Pop();
							break;
						}
					}
				}
			}

			return this.rtf_class;
		}