~alexreg/mathtexdotnet/0.1

« back to all changes in this revision

Viewing changes to TexDotNet/TexHelper.cs

  • Committer: Alex Regueiro
  • Date: 2009-09-17 00:51:15 UTC
  • Revision ID: alexreg@gmail.com-20090917005115-wru7sxue0rko028j
Updated grammar specification. Added support for catching unexpected end of token stream. Parser now handles fractions, binomials, and square roots (with optional index argument). Added IsArgument property to ExpressionNode; handled by TreeTextRenderer class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
using System;
2
2
using System.Collections.Generic;
 
3
using System.IO;
3
4
using System.Linq;
4
5
using System.Text;
5
6
 
6
7
namespace TexDotNet
7
8
{
8
9
    using TokenStream = IEnumerator<Token>;
9
 
 
 
10
    
10
11
    public static class TexHelper
11
12
    {
 
13
        public static string CreateText(this ExpressionTree tree)
 
14
        {
 
15
            using (var stringWriter = new StringWriter())
 
16
            {
 
17
                var texWriter = new TexWriter(stringWriter);
 
18
                texWriter.Write(tree);
 
19
                return stringWriter.ToString();
 
20
            }
 
21
        }
 
22
 
 
23
        public static string CreateText(this ExpressionNode node)
 
24
        {
 
25
            using (var stringWriter = new StringWriter())
 
26
            {
 
27
                var texWriter = new TexWriter(stringWriter);
 
28
                texWriter.Write(node);
 
29
                return stringWriter.ToString();
 
30
            }
 
31
        }
 
32
 
12
33
        public static ExpressionTree CreateExpressionTree(string expression)
13
34
        {
14
35
            return ExpressionTree.FromParseTree(CreateParseTree(expression));
25
46
            var lexer = new TexLexer();
26
47
            return lexer.Tokenise(expression);
27
48
        }
 
49
 
 
50
        internal static void ForceMoveNext(this TokenStream tokenStream)
 
51
        {
 
52
            if (!tokenStream.MoveNext())
 
53
                throw new ParserException(Token.Null, "Unexpected end of token stream.");
 
54
        }
28
55
    }
29
56
}