'Resolve a selector (=field path) against a resource
@param resource: the S3Resource to resolve against
@param selector: the field selector string
@param tail: tokens to append to the selector
The general syntax for a selector is:
selector = {[alias].}{[key]$}[field|selector]
(Parts in {} are optional, | indicates alternatives)
* Alias can be:
~           refers to the resource addressed by the
preceding parts of the selector (=last
resource)
component   alias of a component of the last resource
linktable   alias of a link table of the last resource
table       name of a table that has a foreign key for
the last resource (auto-detect the key)
key:table   same as above, but specifying the foreign key
* Key can be:
key         the name of a foreign key in the last resource
context     a context expression
* Field can be:
fieldname   the name of a field or virtual field of the
last resource
context     a context expression
A "context expression" is a name enclosed in parentheses:
(context)
During parsing, context expressions get replaced by the
string which has been configured for this name for the
last resource with:
s3db.configure(tablename, context = dict(name = "string"))
With context expressions, the same selector can be used
for different resources, each time resolving into the
specific field path. However, the field addressed must
be of the same type in all resources to form valid
queries.
If a context name can not be resolved, resolve() will
still succeed - but the S3FieldPath returned will have
colname=None and ftype="context" (=unresolvable context).'

@classmethod
def resolve(cls, resource, selector, tail=None):

    if (not selector):
        raise SyntaxError(('Invalid    selector:    %s' % selector))
    tokens = re.split('(\\.|\\$)', selector)
    if tail:
        tokens.extend(tail)
    parser = cls(resource, None, tokens)
    parser.original = selector
    return parser
