/// <summary> /// Initializes a new instance of the <see cref="T:ExpressionEvaluator.Lexer"/> class. /// </summary> /// <param name="textReader">Text reader.</param> public Lexer(TextReader textReader) { TextReader = textReader; Line = 1; Column = 1; Diagnostics = new DiagnosticsBag(); }
/// <summary> /// Creates an instance of a <see cref="DocumentSyntax"/> /// </summary> public DocumentSyntax() : base(SyntaxKind.Document) { KeyValues = new SyntaxList <KeyValueSyntax>() { Parent = this }; Tables = new SyntaxList <TableSyntaxBase>() { Parent = this }; Diagnostics = new DiagnosticsBag(); }
public SyntaxTree Parse() { var lexer = new Internal.MLexerGreen(_window); var lexerDiagnostics = lexer.Diagnostics; var tokens = lexer.ParseAll(); var parser = new Internal.MParserGreen(tokens, new Internal.SyntaxFactory()); var green = parser.ParseRoot(); var parserDiagnostics = parser.Diagnostics; var totalDiagnostics = new DiagnosticsBag(lexerDiagnostics.Concat(parserDiagnostics)); var root = new RootSyntaxNode(green, 0); return(new SyntaxTree(root, totalDiagnostics)); }
public DocumentSyntax Run() { var doc = new DocumentSyntax(); _diagnostics = doc.Diagnostics; _currentTable = null; _hideNewLine = true; NextToken(); while (TryParseTableEntry(out var itemEntry)) { if (itemEntry == null) { continue; } if (itemEntry is TableSyntaxBase table) { _currentTable = table; AddToListAndUpdateSpan(doc.Tables, table); } else if (_currentTable == null) { AddToListAndUpdateSpan(doc.KeyValues, (KeyValueSyntax)itemEntry); } else { // Otherwise, we know that we can only have a key-value AddToListAndUpdateSpan(_currentTable.Items, (KeyValueSyntax)itemEntry); } } if (_currentTable != null) { Close(_currentTable); _currentTable = null; } Close(doc); if (_lexer.HasErrors) { foreach (var lexerError in _lexer.Errors) { Log(lexerError); } } return(doc); }
internal void Load(DocumentSyntax doc, string filePath, DiagnosticsBag diagnostics) { var table = doc.Tables.FindByName("package"); if (table == null) { diagnostics.Error(new SourceSpan(filePath, new TextPosition(), new TextPosition()), $"Unable to find [package] section"); return; } if (table.Kind != SyntaxKind.Table) { diagnostics.Error(new SourceSpan(filePath, new TextPosition(), new TextPosition()), $"Unable to find [package] section must be a table and not a table array [[package]]"); return; } foreach (var item in table.Items) { var key = item.Key.AsText(); switch (key) { case "name": Name = item.Value.AsObject()?.ToString(); break; case "version": Name = item.Value.AsObject()?.ToString(); break; case "authors": break; default: // log error break; } } }
public Lexer(SourceText text) { _text = text; Diagnostics = new DiagnosticsBag(); }
private Binder(BoundScope parent) { Diagnostics = new DiagnosticsBag(); _scope = new BoundScope(parent); }
private ErgonProject(string path) { Diagnostics = new DiagnosticsBag(); Package = new ErgonPackageDeclaration(); FullPath = path; }
public SyntaxTree(RootSyntaxNode nullRoot, DiagnosticsBag diagnostics) { NullRoot = nullRoot ?? throw new ArgumentNullException(nameof(nullRoot)); Diagnostics = diagnostics ?? throw new ArgumentNullException(nameof(diagnostics)); }