- From: Joe Gregorio <joe@bitworking.org>
- Date: Mon, 5 Nov 2007 12:32:05 -0500
- To: URI <uri@w3.org>
Based on everyone's feedback I've updated my proposal
and updated the URI Template explainer service to reflect that proposal.
Expansions are now of the form:
{var=default}
or
{-op|arg|vars}
where <op> is now a word, one of 'prefix', 'append',
'join', 'listjoin', 'opt', 'neg', or 'sub'. This addresses
the concerns with readability, extensibility, embedding in XML,
and also makes parsing easier by delimiting each part with '|'.
In addition I've added in the 'sub' operator
which operates on a sub-string.
Here is an example using sub:
URI Template
http://example.com/user/{-sub|0-1|username}/{-sub|1|username}
Variables
username := 'jcgregorio'
URI
http://example.com/user/j/cgregorio
The examples on this page have been updated
to reflect the new syntax:
http://bitworking.org/projects/URI-Templates/
Other restrictions that are found in the new BNF include
restricting var names to
[a-zA-Z0-9][a-zA-Z0-9\_\.\-]*
which makes disambiguating between the IdentityOperatorTemplate
and OperatorTemplate easier now that operators are not punctuation.
Here is the updated BNF:
token arg '[^\|]*';
token varname '[a-zA-Z0-9][a-zA-Z0-9\_\.\-]*' ;
token vardefault '[\w\-\.\~\%]+' ;
token num '[0-9]+';
START -> Template;
Template ->
IdentityOperatorTemplate
| OperatorTemplate
;
IdentityOperatorTemplate-> Var
OperatorTemplate ->
'-append\|' arg '\|' Var
| '-prefix\|' arg '\|' Var
| '-join\|' arg '\|' Vars
| '-listjoin\|' arg '\|' VarNoDefault
| '-opt\|' arg '\|' Vars
| '-neg\|' arg '\|' Vars
| '-sub\|'
num
( '-' num )?
'\|' Var
;
Vars -> Var
(
',' Var
) * ;
Var -> varname
(
'=' vardefault
) ? ;
VarNoDefault -> varname;
Here are the rest of the examples previously given
rewritten in the new syntax:
URI Template
{-join|&|q,num}
Variables:
q := fred
num := 10
URI
q=fred&num=10
URI Template
/foo{-prefix|/notebooks/|notebookID}
Variables
notebookID := stuff
URI
/foo/notebooks/stuff
URI Template
foo{-opt|/-/|categories}
Variables
opt := fred
URI
foo/-/
URI Template
/-/{-listjoin|/|categories}
Variables
categories := ['A|-B', 'C']
URI
/-/A%7C-B/C
The python implementation and the associated explainer service have
been updated:
http://code.google.com/p/uri-templates/
There are two issues that are outstanding:
1. Seven operations is a bit much. Prefix and append are both
convenience operators that can be done using 'opt'. Is it worth
dropping them to reduce the count to five?
2. The 'sub' operator could either be defined to operate on
the octets of the variables value, or on the unicode character points
of the equivalent utf-8 decoded string. Both have their pros and cons.
Thanks,
-joe
--
Joe Gregorio http://bitworking.org
Received on Monday, 5 November 2007 17:32:24 UTC