コード例 #1
0
ファイル: SourceSupervisor.cs プロジェクト: dtabuenc/spark
        public void PrimaryTextChanged(int processImmediately)
        {
            var primaryText = _source.GetPrimaryText();
            var sourceContext = new SourceContext(primaryText, 0, _path);
            var result = _grammar.Nodes(new Position(sourceContext));

            var descriptor = new SparkViewDescriptor()
                .AddTemplate(_path);

            var entry = _engine.CreateEntry(_engine.CreateKey(descriptor), false);

            var mappings = entry.SourceMappings
                .Where(m => string.Equals(m.Source.Begin.SourceContext.FileName, _path,
                                          StringComparison.InvariantCultureIgnoreCase))
                .Select(m => new _SOURCEMAPPING
                                 {
                                     start1 = m.Source.Begin.Offset,
                                     end1 = m.Source.End.Offset,
                                     start2 = m.OutputBegin,
                                     end2 = m.OutputEnd
                                 })
                .ToArray();

            var paints = result.Rest.GetPaint()
                .OfType<Paint<SparkTokenType>>()
                .Where(p => string.Equals(p.Begin.SourceContext.FileName, _path,
                                          StringComparison.InvariantCultureIgnoreCase))
                .Select(p => new _SOURCEPAINTING
                                 {
                                     start = p.Begin.Offset,
                                     end = p.End.Offset,
                                     color = (int)p.Value
                                 })
                .ToArray();

            int cMappings = mappings.Length;
            if (cMappings == 0)
                mappings = new _SOURCEMAPPING[1];

            int cPaints = paints.Length;
            if (cPaints == 0)
                paints = new _SOURCEPAINTING[1];

            foreach (var events in _events.Values)
            {
                events.OnGenerated(
                    primaryText,
                    entry.SourceCode,
                    cMappings,
                    ref mappings[0],
                    cPaints,
                    ref paints[0]);
            }
        }
コード例 #2
0
        private PaintInfo GetPaintInfo(string primaryText)
        {
            var paintInfo = new PaintInfo();
            try
            {
                var sourceContext = new SourceContext(primaryText, 0, _path);
                var result = _grammar.Nodes(new Position(sourceContext));

                paintInfo.Paint = result.Rest.GetPaint()
                    .OfType<Paint<SparkTokenType>>()
                    .Where(p => string.Equals(p.Begin.SourceContext.FileName, _path,
                                              StringComparison.InvariantCultureIgnoreCase))
                    .Select(p => new _SOURCEPAINTING
                                     {
                                         start = p.Begin.Offset,
                                         end = p.End.Offset,
                                         color = (int)p.Value
                                     })
                    .ToArray();

                paintInfo.Count = paintInfo.Paint.Length;
            }
            catch (Exception ex)
            {
                paintInfo.ParseError = ex;
            }

            if (paintInfo.Count == 0)
                paintInfo.Paint = new _SOURCEPAINTING[1];
            return paintInfo;
        }
コード例 #3
0
 public Position(SourceContext sourceContext)
     : this(sourceContext, sourceContext.Content.Length, 0, 1, 1, null)
 {
 }