public static FromClause Build(PlSqlParser.FromClauseContext context) { if (context == null) return null; var clause = new FromClause(); var list = context.tableRefList(); if (list.IsEmpty) throw new ParseCanceledException("No source set in FROM clause"); var tableRefs = list.tableRef().Select(FormTableRef); bool joinSeen = false; bool first = true; foreach (var tableRef in tableRefs) { if (joinSeen) throw new ParseCanceledException("Invalid join clause"); var source = tableRef.Source; if (source.SubQuery != null) { clause.AddSubQuery(source.Alias, source.SubQuery); } else if (source.TableName != null) { clause.AddTable(source.Alias, source.TableName); } foreach (var joinNode in tableRef.Join) { var joinSource = joinNode.Source; if (joinSource.SubQuery != null) { clause.AddSubQuery(joinSource.Alias, joinSource.SubQuery); } else if (joinSource.TableName != null) { clause.AddTable(joinSource.Alias, joinSource.TableName); } clause.Join(joinNode.JoinType, joinNode.OnExpression); joinSeen = true; } if (!first && !joinSeen) { clause.Join(JoinType.Inner, null); } first = false; } return clause; }