public static LinkedListNode <Lexeme> TryParse(LinkedListNode <Lexeme> lexemes, out StructLitStmt resultNode) { resultNode = null; if (lexemes.Value.Type != LT.IDENT) { return(lexemes); } var nextLexeme = lexemes.Next; if (nextLexeme.Value.Type != LT.OP_COLON) { return(lexemes); } nextLexeme = nextLexeme.Next; nextLexeme = BinaryExpr.TryParseExpr(nextLexeme, out var data); if (data != null) { resultNode = new StructLitStmt { Data = data, Token = lexemes.Value }; return(nextLexeme); } return(lexemes); }
public static LinkedListNode <Lexeme> TryParse(LinkedListNode <Lexeme> lexemes, out StructLit resultNode) { List <StructLitStmt> stmts = new List <StructLitStmt>(); resultNode = null; if (lexemes.Value.Type != LT.OP_BRACE_O) { return(lexemes); } LinkedListNode <Lexeme> nextLexeme = lexemes.Next; nextLexeme = StructLitStmt.TryParse(nextLexeme, out var stmt); if (stmt == null) { return(lexemes); } stmts.Add(stmt); while (nextLexeme.Value.Type == LT.OP_COMMA) { nextLexeme = nextLexeme.Next; nextLexeme = StructLitStmt.TryParse(nextLexeme, out stmt); if (stmt == null) { break; } stmts.Add(stmt); } resultNode = new StructLit { Statements = stmts, Token = nextLexeme.Value }; if (nextLexeme.Value.Type == LT.OP_BRACE_C) { nextLexeme = nextLexeme.Next; } else { throw new ArgumentException($"Missing closing brace at {nextLexeme.Value.File}:{nextLexeme.Value.Line}"); } return(nextLexeme); }