public AstContainer Parse(StringSource source) { try { // Create tokenizer _tokenizer = new Tokenizer(source); // Create AST container var container = new AstContainer(source.DisplayName); container.SourcePosition = _tokenizer.Source.CreatePosition(0); // Parse all elements ParseIntoContainer(container); // Should be at EOF? _tokenizer.CheckToken(Token.EOF); // Return the container return(container); } catch { _tokenizer = null; throw; } }
private void ParseIntoContainer(AstContainer container) { while (_tokenizer.Token != Token.EOF) { try { var pos = _tokenizer.TokenPosition; // Check for container terminators if (_tokenizer.Token == Token.Identifier) { switch (_tokenizer.TokenString.ToUpperInvariant()) { case "ENDIF": case "ELSE": case "ELSEIF": case "ENDP": case "ENDM": return; } } // Parse an element var elem = ParseAstElement(); // Anything returned? if (elem != null) { elem.SourcePosition = pos; container.AddElement(elem); } // Unless it's a label, we should hit EOL after each element if (!(elem is AstLabel)) { _tokenizer.SkipToken(Token.EOL); } } catch (CodeException x) { // Log error Log.Error(x.Position, x.Message); // Skip to next line while (_tokenizer.Token != Token.EOF && _tokenizer.Token != Token.EOL) { try { _tokenizer.Next(); } catch (CodeException) { // Ignore other parse errors on this line } } } } }
public AstInclude(string filename, AstContainer content) { _filename = filename; _content = content; }