Esempio n. 1
0
        /// <summary>
        ///     Formats an <see cref="ILSLReadOnlySyntaxTreeNode" /> to an output writer, with the ability to provide source code hint text. <para/>
        ///     Comments are discarded.
        /// </summary>
        /// <param name="sourceCodeHint">
        ///     When provided the formatter can make more intelligent decisions in various places, such as retaining user spacing
        ///     when comments appear on the same line as a statement.
        /// </param>
        /// <param name="syntaxTree">Syntax tree node to format to output.</param>
        /// <param name="writer">The writer to write the formated source code to.</param>
        /// <param name="closeStream">
        ///     <c>true</c> if this method should close <paramref name="writer" /> when finished.  The
        ///     default value is <c>false</c>.
        /// </param>
        /// <exception cref="ArgumentException">
        ///     If <see cref="ILSLReadOnlySyntaxTreeNode.HasErrors" /> is <c>true</c> in
        ///     <paramref name="syntaxTree" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="sourceCodeHint" /> or <paramref name="syntaxTree" /> or <paramref name="writer" /> is
        ///     <c>null</c>.
        /// </exception>
        /// <exception cref="InvalidOperationException"><see cref="LSLCodeFormatter.Settings" /> is <c>null</c>.</exception>
        public void Format(
            string sourceCodeHint,
            ILSLReadOnlySyntaxTreeNode syntaxTree,
            TextWriter writer,
            bool closeStream = false)
        {
            if (sourceCodeHint == null)
            {
                throw new ArgumentNullException("sourceCodeHint");
            }
            if (syntaxTree == null)
            {
                throw new ArgumentNullException("syntaxTree");
            }
            if (syntaxTree.HasErrors)
            {
                throw new ArgumentException(typeof(ILSLCompilationUnitNode).Name +
                                            ".HasErrors is true, cannot format a tree with syntax errors.");
            }
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            if (Settings == null)
            {
                throw new InvalidOperationException(typeof(LSLCodeFormatter).Name + ".Settings cannot be null.");
            }

            var formatter = new LSLCodeFormatterVisitor(Settings);

            formatter.WriteAndFlush(sourceCodeHint, null, syntaxTree, writer, closeStream);
        }
        /// <summary>
        ///     Creates a source code range from an <see cref="ILSLReadOnlySyntaxTreeNode" />
        /// </summary>
        /// <param name="node">The syntax tree node to create the <see cref="LSLSourceCodeRange" /> from.</param>
        /// <exception cref="ArgumentNullException"><paramref name="node" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><see cref="ILSLReadOnlySyntaxTreeNode.SourceRangesAvailable"/> == <c>false</c>.</exception>
        public LSLSourceCodeRange(ILSLReadOnlySyntaxTreeNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (!node.SourceRangesAvailable)
            {
                throw new ArgumentException("node.SourceRangesAvailable == false.", "node");
            }

            LineStart   = node.SourceRange.LineStart;
            ColumnStart = node.SourceRange.ColumnStart;
            StartIndex  = node.SourceRange.StartIndex;
            StopIndex   = node.SourceRange.StopIndex;
            LineEnd     = node.SourceRange.LineEnd;
            ColumnEnd   = node.SourceRange.ColumnEnd;
        }
        /// <summary>
        ///     Creates a source code range that spans two <see cref="ILSLReadOnlySyntaxTreeNode" /> objects.
        /// </summary>
        /// <param name="start">The <see cref="ILSLReadOnlySyntaxTreeNode" />where the source code range starts.</param>
        /// <param name="end">The <see cref="ILSLReadOnlySyntaxTreeNode" />where the source code range ends.</param>
        /// <exception cref="ArgumentNullException"><paramref name="start" /> or <paramref name="end" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">
        ///     If <paramref name="start" />.SourceRangesAvailable or <paramref name="end" />
        ///     .SourceRangesAvailable are false.
        /// </exception>
        public LSLSourceCodeRange(ILSLReadOnlySyntaxTreeNode start, ILSLReadOnlySyntaxTreeNode end)
        {
            if (start == null)
            {
                throw new ArgumentNullException("start");
            }

            if (end == null)
            {
                throw new ArgumentNullException("end");
            }

            if (!start.SourceRangesAvailable)
            {
                throw new ArgumentException("start.SourceRangesAvailable == false", "start");
            }

            if (!end.SourceRangesAvailable)
            {
                throw new ArgumentException("end.SourceRangesAvailable == false", "end");
            }

            if (start.SourceRange.StartIndex < end.SourceRange.StopIndex &&
                end.SourceRange.StartIndex < start.SourceRange.StopIndex)
            {
                throw new ArgumentException(string.Format("{0}({1} start, {1} end): start and end ranges overlap.",
                                                          typeof(LSLSourceCodeRange).Name, typeof(ILSLReadOnlySyntaxTreeNode).Name));
            }

            LineStart   = start.SourceRange.LineStart;
            ColumnStart = start.SourceRange.ColumnStart;
            StartIndex  = start.SourceRange.StartIndex;
            StopIndex   = end.SourceRange.StopIndex;
            LineEnd     = end.SourceRange.LineEnd;
            ColumnEnd   = end.SourceRange.ColumnEnd;
        }
Esempio n. 4
0
 /// <summary>
 ///     The generic visit function for the syntax tree visitor.  It should delegate to treeNode.AcceptVisitor(this).
 /// </summary>
 /// <param name="treeNode">The Syntax Tree Node.</param>
 /// <returns>An object of type (T) from the visitor implementation of this function.</returns>
 public virtual T Visit(ILSLReadOnlySyntaxTreeNode treeNode)
 {
     return(treeNode.AcceptVisitor(this));
 }