コード例 #1
0
ファイル: CustomLiteral.cs プロジェクト: dadhi/ecsharp
 internal string LiteralTypeAsLes3Identifier()
 {
     if (Les2Printer.IsNormalIdentifier(TypeMarker))
     {
         return(TypeMarker.Name);
     }
     else
     {
         return("`" + PrintHelpers.EscapeCStyle(TypeMarker.Name, EscapeC.Control, '`') + "`");
     }
 }
コード例 #2
0
ファイル: TokenType.cs プロジェクト: qwertie/LoycCore
        /// <summary>Expresses an LES token as a string.</summary>
        /// <remarks>Note that some Tokens do not contain enough information to
        /// reconstruct a useful token string, e.g. comment tokens do not store the
        /// comment but merely contain the location of the comment in the source code.
        /// For performance reasons, a <see cref="Token"/> does not have a reference
        /// to its source file, so this method cannot return the original string.
        /// <para/>
        /// The results are undefined if the token was not produced by <see cref="Les2Lexer"/>.
        /// </remarks>
        public static string ToString(Token t)
        {
            StringBuilder sb = new StringBuilder();

            switch (t.Type())
            {
            case TT.Newline: return("\n");

            case TT.SLComment: return("//\n");

            case TT.MLComment: return("/**/");

            case TT.Literal:
                return(Les2Printer.PrintLiteral(t.Value, t.Style));

            case TT.BQOperator:
                return(Les2Printer.PrintString((t.Value ?? "").ToString(), '`', false));

            case TT.Id:
                return(Les2Printer.PrintId(t.Value as Symbol ?? GSymbol.Empty));

            case TT.LParen: return("(");

            case TT.RParen: return(")");

            case TT.LBrack: return("[");

            case TT.RBrack: return("]");

            case TT.LBrace: return("{");

            case TT.RBrace: return("}");

            //case TT.OpenOf: return ".[";
            case TT.Shebang: return("#!" + t.Value + "\n");

            case TT.Dot:
            case TT.Assignment:
            case TT.NormalOp:
            case TT.PreOrSufOp:
            case TT.PrefixOp:
            //case TT.SuffixOp:
            case TT.At:
            case TT.Comma:
            case TT.Semicolon:
            case TT.Not:
                var name = (t.Value ?? "(punc missing value)").ToString();
                return(name);

            default:
                return("@unknown_token");
            }
        }
コード例 #3
0
ファイル: Les2Printer.cs プロジェクト: saisirisha1835/ecsharp
        internal static void Print(ILNode node, StringBuilder target, IMessageSink sink, ParsingMode mode, ILNodePrinterOptions options = null)
        {
            var p          = _printer = _printer ?? new Les2Printer(TextWriter.Null, null);
            var oldOptions = p._o;
            var oldWriter  = p.Writer;
            var oldSink    = p.ErrorSink;

            p.ErrorSink = sink;
            p.SetOptions(options);
            p.Writer = new Les2PrinterWriter(target, p.Options.IndentString ?? "\t", p.Options.NewlineString ?? "\n");

            if (mode == ParsingMode.Expressions)
            {
                p.Print(node, StartStmt, "");
            }
            else
            {
                p.Print(node, StartStmt, ";");
            }

            p.Writer    = oldWriter;
            p._o        = oldOptions;
            p.ErrorSink = oldSink;
        }
コード例 #4
0
        /// <summary>Expresses a token as a string, using LES printers for identifiers and literals.</summary>
        /// <remarks>Note that some Tokens do not contain enough information to
        /// reconstruct a useful token string, e.g. comment tokens do not store the
        /// comment but merely contain the location of the comment in the source code.
        /// For performance reasons, a <see cref="Token"/> does not have a reference
        /// to its source file, so this method cannot return the original string.
        /// </remarks>
        public static string ToString(Token t)
        {
            StringBuilder sb = new StringBuilder();

            switch (t.Kind)
            {
            case TokenKind.Spaces: return((t.Value ?? " ").ToString());

            case TokenKind.Comment:
                if (t.Type() == TokenType.SLComment)
                {
                    return("// (comment)");
                }
                else
                {
                    return("/* (comment) */");
                }

            case TokenKind.Id:
                return(Les2Printer.PrintId(t.Value as Symbol ?? GSymbol.Empty));

            case TokenKind.Literal:
                return(Les2Printer.PrintLiteral(t.Value, t.Style));
            }
            if (t.Value != null)
            {
                if (t.Type() == TokenType.BQOperator)
                {
                    return(Les2Printer.PrintString((t.Value ?? "").ToString(), '`', false));
                }
                else if (t.Type() == TokenType.Shebang)
                {
                    return("#!" + t.Value.ToString() + "\n");
                }
                return(t.Value.ToString());
            }
            switch (t.Kind)
            {
            case TokenKind.LParen: return("(");

            case TokenKind.RParen: return(")");

            case TokenKind.LBrack: return("[");

            case TokenKind.RBrack: return("]");

            case TokenKind.LBrace: return("{");

            case TokenKind.RBrace: return("}");

            case TokenKind.Indent:       return("(Indent)");

            case TokenKind.Dedent:       return("(Dedent)");

            case TokenKind.Dot:          return("(Dot)");

            case TokenKind.Assignment:   return("(Assignment)");

            case TokenKind.Operator:     return("(Operator)");

            case TokenKind.Separator:    return("(Separator)");

            case TokenKind.AttrKeyword:  return("(AttrKeyword)");

            case TokenKind.TypeKeyword:  return("(TypeKeyword)");

            case TokenKind.OtherKeyword: return("(OtherKeyword)");
            }
            return("(Type " + t.TypeInt + ")");
        }
コード例 #5
0
 public void Print(ILNode node, StringBuilder target, IMessageSink sink = null, ParsingMode mode = null, ILNodePrinterOptions options = null)
 {
     Les2Printer.Print(node, target, sink, mode, options);
 }
コード例 #6
0
ファイル: Les2Printer.cs プロジェクト: dadhi/ecsharp
 static void MaybeInitThread()
 {
     _staticPrinter       = _staticPrinter ?? new Les2Printer(_staticStringBuilder);
     _staticWriter        = _staticWriter ?? new Les2PrinterWriter(_staticStringBuilder);
     _staticStringBuilder = _staticStringBuilder ?? new StringBuilder();
 }