예제 #1
0
        public DiagnosticResult <ScriptNode> Bind(ScriptFile file, PapyrusProgram program, IReadOnlyScriptText text, ITokenStream tokenStream, CommonTree objectNode)
        {
            return(DiagnosticResult <ScriptNode> .TryWithDiagnostics((diagnostics) =>
            {
                _text = text;
                _tokenStream = tokenStream;
                _diagnostics = diagnostics;

                _scriptNode = new ScriptNode
                {
                    File = file,
                    Program = program
                };
                _scriptNode.Script = _scriptNode;
                _scriptNode.CompilerNode = objectNode;
                _scriptNode.Range = objectNode.GetRange(tokenStream, text);
                _scriptNode.Text = text.Text;

                var children = new Scanner <CommonTree>(objectNode.GetChildren());
                children.Next();

                _scriptNode.Header = BindScriptHeader(_scriptNode, children);

                foreach (var child in children.AllRemaining())
                {
                    var blockChildren = new Scanner <CommonTree>(new CommonTree[] { child });
                    blockChildren.Next();

                    var definition = BindDefinition(_scriptNode, blockChildren);
                    if (definition != null)
                    {
                        lock (_definitionsLock)
                        {
                            _scriptNode.Definitions.Add(definition);
                        }
                    }
                }

                return _scriptNode;
            }));
        }