public static Element GetRequiredElement(Scope sc, string index, Element element = null) { Element el = sc[index]; if (el == null) { throw (new Exception()); } return el; }
public Parser(List<Token> tokens, bool isBinary) { this.tokens = tokens; last = -1; current = -1; cursor = -1; this.isBinary = isBinary; root = new Scope(this, true); }
public Element(Token keyToken, Parser parser) { this.keyToken = keyToken; Token n; do { n = parser.AdvanceToNextToken(); if (n == null) { throw (new Exception("unexpected end of file, expected closing bracket")); } if (n.Type == TokenType.Data) { tokens.Add(n); n = parser.AdvanceToNextToken(); if (n == null) { throw (new Exception("unexpected end of file, expected bracket, comma or key")); } TokenType ty = n.Type; if (ty != TokenType.OpenBracket && ty != TokenType.CloseBracket && ty != TokenType.Comma && ty != TokenType.Key) { throw (new Exception("unexpected token; expected bracket, comma or key")); } } if (n.Type == TokenType.OpenBracket) { compound = new Scope(parser); // current token should be a TOK_CLOSE_BRACKET n = parser.CurrentToken; Debug.Assert(n != null); if (n.Type != TokenType.CloseBracket) { throw (new Exception("expected closing bracket")); } parser.AdvanceToNextToken(); return; } } while (n.Type != TokenType.Key && n.Type != TokenType.CloseBracket); }