forked from EvilBeaver/OneScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSourceCode.cs
More file actions
59 lines (47 loc) · 2 KB
/
SourceCode.cs
File metadata and controls
59 lines (47 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*----------------------------------------------------------
This Source Code Form is subject to the terms of the
Mozilla Public License, v.2.0. If a copy of the MPL
was not distributed with this file, You can obtain one
at http://mozilla.org/MPL/2.0/.
----------------------------------------------------------*/
using OneScript.Language.LexicalAnalysis;
using OneScript.Language.Sources;
// ReSharper disable once CheckNamespace
namespace OneScript.Sources
{
public class SourceCode : ISourceCodeIndexer
{
private readonly ICodeSource _source;
private ISourceCodeIndexer _indexer;
private string _code = null;
internal SourceCode(string sourceName, ICodeSource source, string ownerPackageId = null)
{
_source = source;
Name = sourceName;
OwnerPackageId = ownerPackageId;
}
public SourceCodeIterator CreateIterator()
{
var newIterator = new SourceCodeIterator(this);
_indexer = newIterator;
return newIterator;
}
public string Location => _source.Location;
public string Name { get; }
/// <summary>
/// Идентификатор пакета-владельца. null если модуль не принадлежит библиотеке.
/// </summary>
public string OwnerPackageId { get; }
public string GetSourceCode()
{
// Однократное считывание того, что отдано на компиляцию
// При изменении источника (напр. файла) в любом случае потребуется перекомпиляция и смена номеров строк.
return _code ??= _source.GetSourceCode();
}
public string GetCodeLine(int lineNumber)
{
return _indexer?.GetCodeLine(lineNumber);
}
public override string ToString() => Name ?? Location;
}
}