Esempio n. 1
0
 public FixedList <PsuedoToken> ToPsuedoTokens()
 {
     return(Tokens.Select(t => PsuedoToken.For(t, File.Code)).ToFixedList());
 }
Esempio n. 2
0
        private static bool SeparateTokens(PsuedoToken t1, PsuedoToken t2)
        {
            switch (t1.Text)
            {
            case ".":
            case "^":
                return(t2.Text == "." || t2.Text == ".." || t2.Text == "..<");

            case "+":
            case ">":
                return(t2.Text == "=" || t2.Text == "==" || t2.Text == "=/=" || t2.Text == "=>");

            case "*":
                return(t2.Text == "=" || t2.Text == "==" || t2.Text == "=/=" || t2.Text == "=>" ||
                       t2.Text == "*=");

            case "<":
                return(t2.Text == "=" || t2.Text == "==" || t2.Text == "=/=" || t2.Text == "=>" ||
                       t2.Text == ":" || t2.Text == "::." ||
                       t2.Text == ".." || t2.Text == "..<" ||
                       t2.Text == "~>");

            case "-":
                return(t2.Text == "=" || t2.Text == "==" || t2.Text == "=/=" || t2.Text == "=>" ||
                       t2.Text == ">" || t2.Text == ">=");

            case "/":
                return(t2.Text == "=" || t2.Text == "==" || t2.Text == "=/=" || t2.Text == "=>" ||
                       t2.Text == "*" || t2.Text == "*=" ||
                       t2.Text == "/" || t2.Text == "/=" ||
                       t2.TokenType == typeof(ICommentToken));

            case "=":
                return(t2.Text == "=" || t2.Text == "==" || t2.Text == "=/=" || t2.Text == "=>" || t2.Text == "/=" ||
                       t2.Text == ">" || t2.Text == ">=");

            case "?":
                return(t2.Text == "." || t2.Text == ".." || t2.Text == "..<" ||
                       t2.Text == "?" || t2.Text == "?." || t2.Text == "??");

            case "..":
            case "<..":
                return(t2.Text == "<" || t2.Text == "<=" || t2.Text == "<:" || t2.Text == "<.." || t2.Text == "<..<" || t2.Text == "<~");

            case "#":
                return(t2.Text == "#" || t2.Text == "##");

            case ":":
                // TODO actually ':',':' is fine. It is really the three token sequence ':',':','.' that is the problem
                return(t2.Text == ":");

            default:
                if (typeof(IKeywordToken).IsAssignableFrom(t1.TokenType) ||
                    typeof(IIdentifierToken).IsAssignableFrom(t1.TokenType))
                {
                    return(typeof(IIdentifierToken).IsAssignableFrom(t2.TokenType) ||
                           typeof(IKeywordToken).IsAssignableFrom(t2.TokenType) ||
                           t2.TokenType == typeof(IIntegerLiteralToken));
                }
                else if (t1.TokenType == typeof(IIntegerLiteralToken))
                {
                    return(t2.TokenType == typeof(IIntegerLiteralToken));
                }
                else if (t1.TokenType == typeof(IWhitespaceToken))
                {
                    return(t2.TokenType == typeof(IWhitespaceToken));
                }
                else
                {
                    return(false);
                }
            }
        }
Esempio n. 3
0
        private static bool SeparateTokens(PsuedoToken t1, PsuedoToken t2)
        {
            switch (t1.Text)
            {
            case ".":
            case "^":
                return(t2.Text == "." || t2.Text == ".." || t2.Text == "..<");

            case "+":
            case "*":
            case ">":
                return(t2.Text == "=" || t2.Text == "==" || t2.Text == "=/=" || t2.Text == "=>");

            case "<":
                return(t2.Text == "=" || t2.Text == "==" || t2.Text == "=/=" || t2.Text == "=>" ||
                       t2.Text == ":" || t2.Text == "::" ||
                       t2.Text == ".." || t2.Text == "..<");

            case "-":
                return(t2.Text == "=" || t2.Text == "==" || t2.Text == "=/=" || t2.Text == "=>" ||
                       t2.Text == ">" || t2.Text == ">=");

            case "/":
                return(t2.Text == "=" || t2.Text == "==" || t2.Text == "=/=" || t2.Text == "=>" ||
                       t2.Text == "*" || t2.Text == "*=" ||
                       t2.Text == "/" || t2.Text == "/=" ||
                       t2.TokenType == typeof(ICommentToken));

            case "=":
                return(t2.Text == "=" || t2.Text == "==" || t2.Text == "=/=" || t2.Text == "=>" || t2.Text == "/=" ||
                       t2.Text == ">" || t2.Text == ">=");

            case "?":
                return(t2.Text == "." || t2.Text == ".." || t2.Text == "..<" ||
                       t2.Text == "?" || t2.Text == "?." || t2.Text == "??");

            case "..":
            case "<..":
                return(t2.Text == "<" || t2.Text == "<=" || t2.Text == "<:" || t2.Text == "<.." || t2.Text == "<..<");

            case "#":
                return(t2.Text == "#" || t2.Text == "##");

            case ":":
                return(t2.Text == ":" || t2.Text == "::");

            default:
                if (typeof(IKeywordToken).IsAssignableFrom(t1.TokenType) ||
                    typeof(IIdentifierToken).IsAssignableFrom(t1.TokenType)
                    )
                {
                    return(typeof(IIdentifierToken).IsAssignableFrom(t2.TokenType) ||
                           typeof(IKeywordToken).IsAssignableFrom(t2.TokenType) ||
                           t2.TokenType == typeof(IIntegerLiteralToken));
                }
                else if (t1.TokenType == typeof(IIntegerLiteralToken))
                {
                    return(t2.TokenType == typeof(IIntegerLiteralToken));
                }
                else if (t1.TokenType == typeof(IWhitespaceToken))
                {
                    return(t2.TokenType == typeof(IWhitespaceToken));
                }
                else
                {
                    return(false);
                }
            }
        }