Exemplo n.º 1
0
Arquivo: main.cs Projeto: RenolY2/ssc
		// error preview
		static string GetErrorPreview(sunSourceLocation location) {
			Stream file;
			try {
				file = File.OpenRead(location.ScriptName);
			}
			catch {
				// simply don't do a preview if opening a file fails
				return "";
			}
			using (var reader = new StreamReader(file)) {
				// skip to line
				for (var line = 1; line < location.Line; ++line) {
					reader.ReadLine();
				}
				// generate column string
				var sb = new StringBuilder();
				var preview = reader.ReadLine();
				sb.AppendLine(preview);
				for (var column = 1; column < location.Column; ++column) {
					var c = preview[column - 1];
					if (IsFullWidth(c)) {
						sb.Append("  "); // full-width hack
					}
					else if (c == '\t') {
						sb.Append('\t');
					}
					else {
						sb.Append(" ");
					}
				}
				sb.Append("^");
				sb.Append("\n");
				return sb.ToString();
			}
		}
Exemplo n.º 2
0
 public sunIdentifier(sunSourceLocation location, string identifier)
     : base(location)
 {
     // make sure it is a valid identifier name (i.e. not a keyword)
     if (sunParser.IsKeyword(identifier))
     {
         throw new sunIdentifierException(this);
     }
     Value = identifier;
 }
Exemplo n.º 3
0
    class sunHexLiteral : sunIntLiteral {     // base-16 integer
        public sunHexLiteral(sunSourceLocation location, string literal)
            : base(location)
        {
            // because .NET's hex parsing is gay and doesn't support
            // leading signs, manually detect negative literals
            var neg    = (literal[0] == '-');
            var trim   = neg ? 3 : 2;
            var digits = literal.Substring(trim);             // trim the '0x' prefix before parsing

            Value = Int32.Parse(literal.Substring(2), NumberStyles.AllowHexSpecifier);
            if (neg)
            {
                Value = -Value;
            }
        }
Exemplo n.º 4
0
 protected sunAugment(sunSourceLocation location)
     : base(location)
 {
 }
Exemplo n.º 5
0
 public sunTernaryOperator(sunSourceLocation location)
     : base(location)
 {
 }
Exemplo n.º 6
0
 public sunOperand(sunSourceLocation location)
     : base(location)
 {
 }
Exemplo n.º 7
0
 public sunFunctionCall(sunSourceLocation location)
     : base(location)
 {
 }
Exemplo n.º 8
0
 public sunBuiltinDeclaration(sunSourceLocation location)
     : base(location)
 {
 }
Exemplo n.º 9
0
 public sunParameterList(sunSourceLocation location)
     : base(location)
 {
 }
Exemplo n.º 10
0
 public sunForCondition(sunSourceLocation location)
     : base(location)
 {
 }
Exemplo n.º 11
0
 public sunForDeclaration(sunSourceLocation location)
     : base(location)
 {
 }
Exemplo n.º 12
0
 public sunIf(sunSourceLocation location)
     : base(location)
 {
 }
Exemplo n.º 13
0
 public sunStringLiteral(sunSourceLocation location, string literal)
     : base(location)
 {
     Value = UnescapeString(literal.Substring(1, literal.Length - 2));             // remove enclosing quotes
 }
Exemplo n.º 14
0
 public sunAddressLiteral(sunSourceLocation location, string literal)
     : base(location)
 {
     Value = UInt32.Parse(literal.Substring(1), NumberStyles.AllowHexSpecifier);
 }
Exemplo n.º 15
0
 class sunIntLiteral : sunToken <int>, sunTerm {    // base-10 integer
     public sunIntLiteral(sunSourceLocation location, string literal)
         : base(location)
     {
         Value = Int32.Parse(literal);
     }
Exemplo n.º 16
0
 protected sunToken(sunSourceLocation location)
     : base(location)
 {
 }
Exemplo n.º 17
0
        sunNode ConvertNode(Node node)
        {
            var id       = GetId(node);
            var parent   = GetId(node.Parent);
            var location = new sunSourceLocation(mFile.Name, mFile.Id, node.StartLine, node.StartColumn);
            var token    = "";

            if (node is Token)
            {
                token = (node as Token).Image;
            }

            // statements
            switch (id)
            {
            case __sunConstants.SCRIPT: return(new sunNode(location));

            case __sunConstants.ROOT_STATEMENT: return(new sunNode(location));

            case __sunConstants.STATEMENT: return(new sunNode(location));

            case __sunConstants.STATEMENT_BLOCK: return(new sunStatementBlock(location));

            case __sunConstants.COMPOUND_STATEMENT: return(new sunCompoundStatement(location));

            case __sunConstants.COMPOUND_STATEMENT_ITEM: return(new sunNode(location));

            case __sunConstants.IMPORT_STATEMENT: return(new sunImport(location));

            case __sunConstants.NAME_LABEL: return(new sunNameLabel(location));

            case __sunConstants.YIELD_STATEMENT: return(new sunYield(location));

            case __sunConstants.EXIT_STATEMENT: return(new sunExit(location));

            case __sunConstants.LOCK_STATEMENT: return(new sunLock(location));

            case __sunConstants.UNLOCK_STATEMENT: return(new sunUnlock(location));
            }

            // literals
            switch (id)
            {
            case __sunConstants.INTEGER_LITERAL: return(new sunIntLiteral(location, token));

            case __sunConstants.HEX_LITERAL: return(new sunHexLiteral(location, token));

            case __sunConstants.FLOAT_LITERAL: return(new sunFloatLiteral(location, token));

            case __sunConstants.ADDRESS_LITERAL: return(new sunAddressLiteral(location, token));

            case __sunConstants.STRING_LITERAL: return(new sunStringLiteral(location, token));

            case __sunConstants.IDENTIFIER: return(new sunIdentifier(location, token));

            case __sunConstants.ELLIPSIS: return(new sunEllipsis(location));

            case __sunConstants.TRUE: return(new sunTrue(location));

            case __sunConstants.FALSE: return(new sunFalse(location));
            }

            // operators
            switch (id)
            {
            case __sunConstants.ADD: return(new sunAddOperator(location));

            case __sunConstants.SUB: {
                if (parent == __sunConstants.UNARY_OPERATOR)
                {
                    return(new sunNegateOperator(location));
                }
                return(new sunSubtractOperator(location));
            }

            case __sunConstants.MUL: return(new sunMultiplyOperator(location));

            case __sunConstants.DIV: return(new sunDivideOperator(location));

            case __sunConstants.MOD: return(new sunModuloOperator(location));

            case __sunConstants.BAND: return(new sunBitwiseAndOperator(location));

            case __sunConstants.BOR: return(new sunBitwiseOrOperator(location));

            case __sunConstants.LSH: return(new sunShiftLeftOperator(location));

            case __sunConstants.RSH: return(new sunShiftRightOperator(location));

            case __sunConstants.AND: return(new sunLogicalAndOperator(location));

            case __sunConstants.OR: return(new sunLogicalOrOperator(location));

            case __sunConstants.NOT: return(new sunLogicalNotOperator(location));

            case __sunConstants.EQ: return(new sunEqualOperator(location));

            case __sunConstants.NE: return(new sunNotEqualOperator(location));

            case __sunConstants.LT: return(new sunLessThanOperator(location));

            case __sunConstants.GT: return(new sunGreaterThanOperator(location));

            case __sunConstants.LE: return(new sunLessEqualOperator(location));

            case __sunConstants.GE: return(new sunGreaterEqualOperator(location));

            case __sunConstants.ASSIGN: return(new sunAssignOperator(location));

            case __sunConstants.ASSIGN_ADD: return(new sunAssignAddOperator(location));

            case __sunConstants.ASSIGN_SUB: return(new sunAssignSubtractOperator(location));

            case __sunConstants.ASSIGN_MUL: return(new sunAssignMultiplyOperator(location));

            case __sunConstants.ASSIGN_DIV: return(new sunAssignDivideOperator(location));

            case __sunConstants.ASSIGN_MOD: return(new sunAssignModuloOperator(location));

            case __sunConstants.ASSIGN_BAND: return(new sunAssignBitwiseAndOperator(location));

            case __sunConstants.ASSIGN_BOR: return(new sunAssignBitwiseOrOperator(location));

            case __sunConstants.ASSIGN_LSH: return(new sunAssignShiftLeftOperator(location));

            case __sunConstants.ASSIGN_RSH: return(new sunAssignShiftRightOperator(location));

            case __sunConstants.INCREMENT: return(new sunIncrement(location));

            case __sunConstants.DECREMENT: return(new sunDecrement(location));

            case __sunConstants.ASSIGNMENT_OPERATOR: return(new sunNode(location));

            case __sunConstants.TERNARY_OPERATOR: return(new sunTernaryOperator(location));

            case __sunConstants.BINARY_OPERATOR: return(new sunNode(location));

            case __sunConstants.UNARY_OPERATOR: return(new sunNode(location));

            case __sunConstants.AUGMENT_OPERATOR: return(new sunNode(location));
            }

            // expressions
            switch (id)
            {
            case __sunConstants.EXPRESSION: return(new sunExpression(location));

            case __sunConstants.OPERAND: return(new sunOperand(location));

            case __sunConstants.TERM: return(new sunNode(location));

            case __sunConstants.UNARY_OPERATOR_LIST: return(new sunUnaryOperatorList(location));

            case __sunConstants.PREFIX_AUGMENT: return(new sunPrefixAugment(location));

            case __sunConstants.POSTFIX_AUGMENT: return(new sunPostfixAugment(location));
            }

            // builtins
            switch (id)
            {
            case __sunConstants.BUILTIN_DECLARATION: return(new sunBuiltinDeclaration(location));

            case __sunConstants.BUILTIN_MODIFIERS: return(new sunNode(location));
            }

            // functions
            switch (id)
            {
            case __sunConstants.FUNCTION_DEFINITION: return(new sunFunctionDefinition(location));

            case __sunConstants.FUNCTION_MODIFIERS: return(new sunNode(location));

            case __sunConstants.FUNCTION_CALL: return(new sunFunctionCall(location));

            case __sunConstants.PARAMETER_LIST: return(new sunParameterList(location));

            case __sunConstants.ARGUMENT_LIST: return(new sunNode(location));
            }

            // variables
            switch (id)
            {
            case __sunConstants.VARIABLE_REFERENCE: return(new sunStorableReference(location));

            case __sunConstants.VARIABLE_DECLARATION: return(new sunVariableDeclaration(location));

            case __sunConstants.VARIABLE_DEFINITION: return(new sunVariableDefinition(location));

            case __sunConstants.VARIABLE_MODIFIERS: return(new sunNode(location));

            case __sunConstants.VARIABLE_ASSIGNMENT: return(new sunStorableAssignment(location));

            case __sunConstants.VARIABLE_AUGMENT: return(new sunNode(location));
            }

            // flow control
            switch (id)
            {
            case __sunConstants.IF_STATEMENT: return(new sunIf(location));

            case __sunConstants.WHILE_STATEMENT: return(new sunWhile(location));

            case __sunConstants.DO_STATEMENT: return(new sunDo(location));

            case __sunConstants.FOR_STATEMENT: return(new sunFor(location));

            case __sunConstants.FOR_DECLARATION: return(new sunForDeclaration(location));

            case __sunConstants.FOR_CONDITION: return(new sunForCondition(location));

            case __sunConstants.FOR_ITERATION: return(new sunForIteration(location));

            case __sunConstants.RETURN_STATEMENT: return(new sunReturn(location));

            case __sunConstants.BREAK_STATEMENT: return(new sunBreak(location));

            case __sunConstants.CONTINUE_STATEMENT: return(new sunContinue(location));
            }

            // modifiers
            switch (id)
            {
            case __sunConstants.LOCAL: return(new sunLocalModifier(location));

            case __sunConstants.CONST: return(new sunConstModifier(location));
            }

            // emergency fallback
            return(null);
        }
Exemplo n.º 18
0
 public sunForIteration(sunSourceLocation location)
     : base(location)
 {
 }
Exemplo n.º 19
0
 public sunEllipsis(sunSourceLocation location)
     : base(location)
 {
 }
Exemplo n.º 20
0
 public sunReturn(sunSourceLocation location)
     : base(location)
 {
 }
Exemplo n.º 21
0
 public sunFunctionDefinition(sunSourceLocation location)
     : base(location)
 {
 }
Exemplo n.º 22
0
 public sunBreak(sunSourceLocation location)
     : base(location)
 {
 }
Exemplo n.º 23
0
 public sunExpression(sunSourceLocation location)
     : base(location)
 {
 }
Exemplo n.º 24
0
 public sunContinue(sunSourceLocation location)
     : base(location)
 {
 }
Exemplo n.º 25
0
 public sunUnaryOperatorList(sunSourceLocation location)
     : base(location)
 {
 }
Exemplo n.º 26
0
 protected sunLoopNode(sunSourceLocation location)
     : base(location)
 {
 }
Exemplo n.º 27
0
 public sunPrefixAugment(sunSourceLocation location)
     : base(location)
 {
 }
Exemplo n.º 28
0
 public sunWhile(sunSourceLocation location)
     : base(location)
 {
 }
Exemplo n.º 29
0
 public sunDecrement(sunSourceLocation location)
     : base(location)
 {
 }
Exemplo n.º 30
0
 public sunNode(sunSourceLocation location)
 {
     mChildren = new List <sunNode>(5);
     mLocation = location;
 }