Irontalk.InputSource.Parse C# (CSharp) Method

Parse() public method

public Parse ( IrontalkParser parser ) : PerCederberg.Grammatica.Runtime.Node
parser IrontalkParser
return PerCederberg.Grammatica.Runtime.Node
        public Node Parse(IrontalkParser parser)
        {
            string str = Input.ReadToEnd();
            str = str.Trim('\n', ' ', '\t');

            if (str == string.Empty)
                return null;

            parser.Reset(new StringReader (str + " \n."));

            try {
                return parser.Parse();
            } catch (ParserLogException e) {
                var error = e.GetError(0);
                throw new ParseException(new InputSource("input", null), error.Line, error.Message);
            }
        }

Usage Example

コード例 #1
0
ファイル: Compiler.cs プロジェクト: rezonant/irontalk
        public STObject Evaluate(InputSource source, Context context)
        {
            Source = source;
            try {
                Node root = source.Parse(Parser);

                if (root == null)
                    return STUndefinedObject.Instance; // parser found empty string so aborted

                if (STDebug.ShowParseTrees) {
                    var tr = Transcript.Instance;
                    if (tr != null)
                        root.PrintTo(tr.Out);
                    else
                        root.PrintTo(Console.Out);
                }

                return Evaluate (root, context);
            } finally {
                Source = null;
            }
        }