Exemple #1
0
 /// <summary>
 /// Output Debug Info
 /// </summary>
 /// <param name="context"></param>
 public override void ExitHsc(HS_Gen1Parser.HscContext context)
 {
     GenerateBranches();
     if(_debug)
     {
         DeclarationsToXML();
         ExpressionsToXML();
         StringsToFile();
     }
     _result = new ScriptData(_scripts, _globals, _references, _expressions, _strings);
 }
Exemple #2
0
        /// <summary>
        /// Generate script and global lookups.
        /// </summary>
        /// <param name="context"></param>
        public override void EnterHsc(HS_Gen1Parser.HscContext context)
        {
            // Generate the globals lookup.
            if (context.globalDeclaration() != null)
            {
                _mapGlobalsLookup = context.globalDeclaration().Select((g, index) => new GlobalInfo(g, (ushort)index)).ToDictionary(g => g.Name);

            }

            // Generate the script lookup and determine the index, which the next generated branch script will have.
            var declarations = context.scriptDeclaration();
            if (declarations != null)
            {
                _nextGenBranchIndex = (ushort)declarations.Length;
                _scriptLookup = new Dictionary<string, List<ScriptInfo>>();

                for(ushort i = 0; i < context.scriptDeclaration().Length; i++)
                {
                    var info = new ScriptInfo(declarations[i], i);
                    AddScriptToLookup(info);
                }
            }

            // The declaration count is used to calculate the current progress.
            _declarationCount = context.scriptDeclaration().Length + context.globalDeclaration().Length;

            // Find all missing carriage returns. Somehow antlr removes them under certain circumstances and messes up the text position indeces.
            string text = context.Start.InputStream.GetText(new Interval(0, context.Start.InputStream.Size));
            string otherText = context.GetText();
            bool same = text == otherText;
            var missingCarriageReturns = Regex.Matches(text, @"(?<!\r)\n");
            foreach (Match match in missingCarriageReturns)
            {
                _missingCarriageReturnPositions.Add(match.Index);
            }
        }
 /// <summary>
 /// Exit a parse tree produced by <see cref="HS_Gen1Parser.hsc"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitHsc([NotNull] HS_Gen1Parser.HscContext context)
 {
 }