Beispiel #1
0
        ///////////////////////
        // Overridden functions

        public override string ToString()
        {
            switch (_type)
            {
            case HqlCompareTokenType.SINGLE:
                return(String.Format("{0} {1} {2}", Token1.ToString(), Compare.Data, Token2.ToString()));

            case HqlCompareTokenType.IN:
            {
                StringBuilder sb = new StringBuilder("IN (");
                for (int i = 0; i < _values.Count; ++i)
                {
                    HqlToken token = (HqlToken)_values[i];
                    if (i > 0)
                    {
                        sb.Append(", ");
                    }
                    sb.Append(token.ToString());
                }
                sb.Append(")");
                return(sb.ToString());
            }

            default:
                throw new NotSupportedException("Unknown type of COMPARETOKEN");
            }
        }
Beispiel #2
0
        private bool IsStartOrEndOfFile(SyntaxTrivia trivia1, SyntaxTrivia trivia2)
        {
            // Below represents the tokens for a file:
            // (None) - It is the start of the file. This means there are no previous tokens.
            // (...) - All the tokens in the compilation unit.
            // (EndOfFileToken) - This is the synthetic end of file token. Should be treated as the end of the file.
            // (None) - It is the end of the file. This means there are no more tokens.

            var isStartOrEndOfFile = (this.Token1.RawKind == 0 || this.Token2.RawKind == 0) && (trivia1.Kind() == 0 || trivia2.Kind() == 0);
            var isAtEndOfFileToken = (Token2.IsKind(SyntaxKind.EndOfFileToken) && trivia2.Kind() == 0);

            return(isStartOrEndOfFile || isAtEndOfFileToken);
        }
Beispiel #3
0
        protected override void SerializeValue <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s)
        {
            bool reading = s.IsReading;

            model.MegaloVariant.SerializeStringTableIndex(s, "stringIndex", ref mStringIndex);

            if (!s.StreamAttributeOpt("tokenCount", ref mTokenCount, Predicates.IsNotZero) &&
                reading)
            {
                TokenCount = 0;
            }

            if (reading)
            {
                ValidateTokenCount();

                int max_tokens = MaxTokens;
                if (max_tokens >= 1)
                {
                    Token0.Nullify();
                }
                if (max_tokens >= 2)
                {
                    Token1.Nullify();
                }
                if (max_tokens >= 3)
                {
                    Token2.Nullify();
                }
            }

            if (TokenCount >= 1)
            {
                using (s.EnterCursorBookmark("Token0")) Token0.Serialize(model, s);
            }
            if (TokenCount >= 2)
            {
                using (s.EnterCursorBookmark("Token1")) Token1.Serialize(model, s);
            }
            if (TokenCount >= 3)
            {
                using (s.EnterCursorBookmark("Token2")) Token2.Serialize(model, s);
            }
        }
Beispiel #4
0
        public override void Serialize(MegaloScriptModel model, IO.BitStream s)
        {
            model.MegaloVariant.StreamStringTableIndexPointer(s, ref mStringIndex);
            s.Stream(ref mTokenCount, ValueType.BitLength);

            if (s.IsReading)
            {
                ValidateTokenCount();

                int max_tokens = MaxTokens;
                if (max_tokens >= 1)
                {
                    Token0.Nullify();
                }
                if (max_tokens >= 2)
                {
                    Token1.Nullify();
                }
                if (max_tokens >= 3)
                {
                    Token2.Nullify();
                }
            }

            if (TokenCount >= 1)
            {
                Token0.Serialize(model, s);
            }
            if (TokenCount >= 2)
            {
                Token1.Serialize(model, s);
            }
            if (TokenCount >= 3)
            {
                Token2.Serialize(model, s);
            }
        }
Beispiel #5
0
	private bool AdvanceInternal (bool throw_on_end)
	{
		char current;
		StringBuilder builder = new StringBuilder ();

	 startagain:

		builder.Length = 0;

		do {
			current = GetNextChar ();
		} while (IsWhiteSpace (current));

		if (current == '/') {
			current = GetNextChar ();
			if (current == '*') { // Found a comment
				// Skip any whitespace
				do {
					current = GetNextChar ();
				} while (IsWhiteSpace (current));

				// Check for a comment property
				if (current == '@') {
					current = GetNextChar ();
					while (true) {
						if (current == char.MinValue)
							throw new Exception ("Unexpected end of code.");
						if (current == '*' && PeekChar (1) == '/')
							break;
						builder.Append (current);
						current = GetNextChar ();
					}
					while (builder.Length > 0 && builder [builder.Length - 1] == ' ')
						builder.Length--;

					if (builder.Length == 0)
						throw new Exception ("Empty comment property.");
				}

				while (true) {
					if (current == char.MinValue)
						throw new Exception ("Unexpected end of code.");
					if (current == '*' && PeekChar (1) == '/')
						break;

					current = GetNextChar ();
				}

				if (current != '*')
					throw new Exception (string.Format ("Expected '*', got '{0}'", current));

				current = GetNextChar ();
				if (current != '/')
					throw new Exception (string.Format ("Expected '/', got '{0}'", current));

				if (builder.Length != 0) {
					string comment = builder.ToString ();
					if (comment == "SkipFile") {
						SkipFile ();
						return AdvanceInternal (throw_on_end);
					}
					current_token = new Token2 (Token2Type.CommentProperty, comment);
					return true;
				}
				// We've skipped the comment, start again
				goto startagain;
			} else if (current == '/') { // Found a comment
				do {
					current = GetNextChar ();
				} while (current != '\r' && current != '\n' && current != char.MinValue);
				if (current == '\r') {
				} else if (current == '\n') {
				} else {
					throw new Exception ("Expected end of line.");
				}
				// We've skipped the comment, start again
				goto startagain;
			} else {
				PutBackChar (current);
				current_token = new Token2 (Token2Type.Punctuation, "/");
				return true;
			}
		}

		if (IsPunctuation (current)) {
			current_token = new Token2 (Token2Type.Punctuation, current);
			return true;
		}

		if (current == '\'') {
			current_token = new Token2 (Token2Type.Punctuation, current);
			return true;
		}

		if (current == '"') {
			do {
				current = GetNextChar ();
				if (current == '\\') {
					current = GetNextChar ();
					builder.Append (current); // We don't care much about special characters like \n, \t, etc.
				} else if (current != '"') {
					builder.Append (current);
				} else if (current == char.MinValue) {
					throw new Exception ("Unexpected end of code in string literal.");
				} else if (current == '"') {
					GetNextChar (); // Skip the "
					break;
				} else {
					throw new Exception (string.Format ("Got unexpected character: {0}", current));
				}
			} while (true);
			current_token = new Token2 (Token2Type.Literal, builder.ToString ());
			return true;
		}

		if (IsPunctuation (current)) {
			current_token = new Token2 (Token2Type.Literal, current);
			return true;
		}

		if (IsIdentifier (current)) {
			builder.Append (current);
			while (IsIdentifier (PeekChar (1))) {
				builder.Append (GetNextChar ());
			}
			current_token = new Token2 (Token2Type.Identifier, builder.ToString ());
			return true;
		}

		if (current == char.MinValue) {
			if (throw_on_end)
				throw new Exception ("Unexpected end of code");
			return false;
		}

		throw new Exception (string.Format ("Unexpected character: {0}", current));
	}
Beispiel #6
0
    private bool AdvanceInternal(bool throw_on_end)
    {
        char          current;
        StringBuilder builder = new StringBuilder();

startagain:

        builder.Length = 0;

        do
        {
            current = GetNextChar();
        } while (IsWhiteSpace(current));

        if (current == '/')
        {
            current = GetNextChar();
            if (current == '*')               // Found a comment
            // Skip any whitespace
            {
                do
                {
                    current = GetNextChar();
                } while (IsWhiteSpace(current));

                // Check for a comment property
                if (current == '@')
                {
                    current = GetNextChar();
                    while (true)
                    {
                        if (current == char.MinValue)
                        {
                            throw new Exception("Unexpected end of code.");
                        }
                        if (current == '*' && PeekChar(1) == '/')
                        {
                            break;
                        }
                        builder.Append(current);
                        current = GetNextChar();
                    }
                    while (builder.Length > 0 && builder [builder.Length - 1] == ' ')
                    {
                        builder.Length--;
                    }

                    if (builder.Length == 0)
                    {
                        throw new Exception("Empty comment property.");
                    }
                }

                while (true)
                {
                    if (current == char.MinValue)
                    {
                        throw new Exception("Unexpected end of code.");
                    }
                    if (current == '*' && PeekChar(1) == '/')
                    {
                        break;
                    }

                    current = GetNextChar();
                }

                if (current != '*')
                {
                    throw new Exception(string.Format("Expected '*', got '{0}'", current));
                }

                current = GetNextChar();
                if (current != '/')
                {
                    throw new Exception(string.Format("Expected '/', got '{0}'", current));
                }

                if (builder.Length != 0)
                {
                    string comment = builder.ToString();
                    if (comment == "SkipFile")
                    {
                        SkipFile();
                        return(AdvanceInternal(throw_on_end));
                    }
                    current_token = new Token2(Token2Type.CommentProperty, comment);
                    return(true);
                }
                // We've skipped the comment, start again
                goto startagain;
            }
            else if (current == '/')                 // Found a comment
            {
                do
                {
                    current = GetNextChar();
                } while (current != '\r' && current != '\n' && current != char.MinValue);
                if (current == '\r')
                {
                }
                else if (current == '\n')
                {
                }
                else
                {
                    throw new Exception("Expected end of line.");
                }
                // We've skipped the comment, start again
                goto startagain;
            }
            else
            {
                PutBackChar(current);
                current_token = new Token2(Token2Type.Punctuation, "/");
                return(true);
            }
        }

        if (IsPunctuation(current))
        {
            current_token = new Token2(Token2Type.Punctuation, current);
            return(true);
        }

        if (current == '\'')
        {
            current_token = new Token2(Token2Type.Punctuation, current);
            return(true);
        }

        if (current == '"')
        {
            do
            {
                current = GetNextChar();
                if (current == '\\')
                {
                    current = GetNextChar();
                    builder.Append(current);                      // We don't care much about special characters like \n, \t, etc.
                }
                else if (current != '"')
                {
                    builder.Append(current);
                }
                else if (current == char.MinValue)
                {
                    throw new Exception("Unexpected end of code in string literal.");
                }
                else if (current == '"')
                {
                    GetNextChar();                      // Skip the "
                    break;
                }
                else
                {
                    throw new Exception(string.Format("Got unexpected character: {0}", current));
                }
            } while (true);
            current_token = new Token2(Token2Type.Literal, builder.ToString());
            return(true);
        }

        if (IsPunctuation(current))
        {
            current_token = new Token2(Token2Type.Literal, current);
            return(true);
        }

        if (IsIdentifier(current))
        {
            builder.Append(current);
            while (IsIdentifier(PeekChar(1)))
            {
                builder.Append(GetNextChar());
            }
            current_token = new Token2(Token2Type.Identifier, builder.ToString());
            return(true);
        }

        if (current == char.MinValue)
        {
            if (throw_on_end)
            {
                throw new Exception("Unexpected end of code");
            }
            return(false);
        }

        throw new Exception(string.Format("Unexpected character: {0}", current));
    }
 // Use this for initialization
 void Start()
 {
     J1 = GameObject.Find("ExampleA").GetComponent <Token>();
     J2 = GameObject.Find("ExampleB").GetComponent <Token2>();
     getQuestion();
 }