Beispiel #1
0
 private static String GetLeafNodeValue(Semantics.Node n, ISemanticsNodeMaker nm, String ErrorCause)
 {
     if (!n.OnLeaf)
     {
         throw new Syntax.InvalidEvaluationException(ErrorCause, nm.GetFileRange(n), n);
     }
     return(n.Leaf);
 }
Beispiel #2
0
        private static TypeRef ParseTypeRef(TFSemantics.Node TypeNode, ISemanticsNodeMaker nm, Dictionary <Object, TextRange> Positions)
        {
            var ts = ParseTypeSpec(TypeNode, nm, Positions);

            if (!ts.OnTypeRef)
            {
                throw new InvalidEvaluationException("ExpectedTypeRef", nm.GetFileRange(ts), ts);
            }
            return(ts.TypeRef);
        }
Beispiel #3
0
        private List <TFSyntax.MultiNodes> TranslateNode(TFSemantics.Node Node, Dictionary <Object, Object> Positions)
        {
            var MultiNodesList = new List <TFSyntax.MultiNodes>();

            if (Positions.ContainsKey(Node))
            {
                var o = Positions[Node];
                if (o is TFSyntax.TextRange)
                {
                    var Range = (TFSyntax.TextRange)(o);
                    var slc   = new TFSyntax.SingleLineComment {
                        Content = new TFSyntax.FreeContent {
                            Text = Range.ToString()
                        }
                    };
                    MultiNodesList.Add(TFSyntax.MultiNodes.CreateNode(TFSyntax.Node.CreateSingleLineComment(slc)));
                }
            }
            if (Node.OnEmpty)
            {
                MultiNodesList.Add(TFSyntax.MultiNodes.CreateNode(TFSyntax.Node.CreateSingleLineNodeLine(new TFSyntax.SingleLineNodeLine {
                    SingleLineNode = TFSyntax.SingleLineNode.CreateEmptyNode(new TFSyntax.EmptyNode {
                    })
                })));
            }
            else if (Node.OnLeaf)
            {
                MultiNodesList.Add(TFSyntax.MultiNodes.CreateNode(TFSyntax.Node.CreateSingleLineNodeLine(new TFSyntax.SingleLineNodeLine {
                    SingleLineNode = TFSyntax.SingleLineNode.CreateSingleLineLiteral(new TFSyntax.SingleLineLiteral {
                        Text = Node.Leaf
                    })
                })));
            }
            else if (Node.OnStem)
            {
                var Children     = Node.Stem.Children.SelectMany(c => TranslateNode(c, Positions)).ToList();
                var EndDirective = Children.Count > 0 ? TreeFormat.Optional <TFSyntax.EndDirective> .Empty : new TFSyntax.EndDirective {
                    EndSingleLineComment = TreeFormat.Optional <TFSyntax.SingleLineComment> .Empty
                };
                MultiNodesList.Add(TFSyntax.MultiNodes.CreateNode(TFSyntax.Node.CreateMultiLineNode(new TFSyntax.MultiLineNode {
                    Head = new TFSyntax.SingleLineLiteral {
                        Text = Node.Stem.Name
                    }, SingleLineComment = TreeFormat.Optional <TFSyntax.SingleLineComment> .Empty, Children = Children, EndDirective = EndDirective
                })));
            }
            else
            {
                throw new InvalidOperationException();
            }
            return(MultiNodesList);
        }
Beispiel #4
0
        private static TypeSpec ParseTypeSpec(TFSemantics.Node TypeNode, ISemanticsNodeMaker nm, Dictionary <Object, TextRange> Positions)
        {
            var TypeSpecString = GetLeafNodeValue(TypeNode, nm, "InvalidTypeSpec");
            var InnerPositions = new Dictionary <Object, TextRange>();
            var ts             = OS.TypeParser.ParseTypeSpec
                                 (
                TypeSpecString,
                (o, Start, End) =>
            {
                var oRange = nm.GetRange(TypeNode);
                if (oRange.OnSome)
                {
                    var Range     = oRange.Value;
                    var TypeRange = new TextRange {
                        Start = nm.Text.Calc(Range.Start, Start), End = nm.Text.Calc(Range.Start, End)
                    };
                    InnerPositions.Add(o, TypeRange);
                }
            },
                Index =>
            {
                var FileRange = TreeFormat.Optional <FileTextRange> .Empty;
                var oRange    = nm.GetRange(TypeNode);
                if (oRange.OnSome)
                {
                    var Range = oRange.Value;
                    FileRange = new FileTextRange {
                        Text = nm.Text, Range = new TextRange {
                            Start = nm.Text.Calc(Range.Start, Index), End = nm.Text.Calc(Range.Start, Index + 1)
                        }
                    };
                }
                return(new InvalidTokenException("InvalidChar", FileRange, TypeSpecString.Substring(Index, 1)));
            }
                                 );

            return(TranslateTypeSpec(ts, nm.Text, InnerPositions, Positions));
        }