Build a Scope given TablesDict, from-expression and optional list of CTEs.
    fromx is a list of expressions (e.g. SelectX.tables). The list elts can be:
      1. string (i.e. tablename)
      2. AliasX(SelectX as name)
      3. AliasX(name as name)

def from_fromx(class_, tables, fromx, ctes=()):
    """Build a Scope given TablesDict, from-expression and optional list of CTEs.
    fromx is a list of expressions (e.g. SelectX.tables). The list elts can be:
      1. string (i.e. tablename)
      2. AliasX(SelectX as name)
      3. AliasX(name as name)
    """
    if ctes: raise NotImplementedError # note: I don't think any other part of the program supports CTEs yet either
    scope_ = class_(fromx)
    for exp in fromx:
      if isinstance(exp, basestring):
        scope_.add(exp, tables[exp])
      elif isinstance(exp, sqparse2.AliasX) and isinstance(exp.name, sqparse2.NameX):
        scope_.add(exp.alias, tables[exp.name.name])
      elif isinstance(exp, sqparse2.AliasX) and isinstance(exp.name, sqparse2.SelectX):
        scope_.add(exp.alias, SyntheticTable(exp.name))
      elif isinstance(exp, sqparse2.JoinX):
        raise NotImplementedError('todo: join')
      else:
        raise TypeError('bad fromx type', type(exp), exp)
    return scope_