osxphotos/osxphotos/phototemplate.tx
Rhet Turnbull 0a973d67f9
Updated template language to match autofile
* Added field_arg to template grammar

* Updated template grammar to match autofile MTL

* Added format and filter args from autofile

* Added cloud_metadata to PhotoInfo

* Version bump, updated docs

* Added tests for filters
2022-05-27 18:33:07 -07:00

144 lines
1.9 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// OSXPhotos Metadata Template Language (MTL)
// a TemplateString has format:
// pre{delim+template_field:subfield(field_arg)|filter[find,replace] conditional?bool_value,default}post
// a TemplateStatement may contain zero or more TemplateStrings
// The pre and post are optional strings
// The template itself (inside the {}) is also optional but if present
// everything but template_field is also optional
Statement:
(template_strings+=TemplateString)?
;
TemplateString:
pre=NON_TEMPLATE_STRING?
template=Template?
post=NON_TEMPLATE_STRING?
;
Template:
(
"{"
delim=Delim
field=Field
subfield=SubField
fieldarg=FieldArg
filter=Filter
findreplace=FindReplace
conditional=Conditional
bool=Boolean
default=Default
"}"
)?
;
NON_TEMPLATE_STRING:
/[^\{\},\?]*/
;
Delim:
(
(value=DELIM_WORD)?
'+'
)?
;
DELIM_WORD:
/[^\{\}]*(?=\+\w)/
;
Field:
FIELD_WORD+
;
FIELD_WORD:
/[\%]?[\.\w]+/
;
SubField:
(
":"-
SUBFIELD_WORD+
)?
;
SUBFIELD_WORD:
/[\.\w:\/\-\~\'\"\%\@\#\^\]+/
/\\\s/?
;
Filter:
(
"|"-
(value+=FILTER_FUNCTION['|'])?
)?
;
FILTER_FUNCTION:
/[\.\w:\/]+(\([^\)]*\))?/
;
Conditional:
(
(" "+)-
(negation=NEGATION)?
(operator=OPERATOR)
(" "+)-
(value+=Statement['|'])
)?
;
NEGATION:
"not "
;
OPERATOR:
"contains" | "matches" | "startswith" | "endswith" | "<=" | ">=" | "<" | ">" | "==" | "!="
;
FieldArg:
(
"("
(value=/[^\(\)\{\}]+/)?
")"
)?
;
FindReplace:
(
"["
(pairs+=FindReplacePair['|'])?
"]"
)?
;
FindReplacePair:
find=FIND_WORD
","
(replace=REPLACE_WORD)?
;
FIND_WORD:
/[^\[\]\|]*(?=\,)/
;
REPLACE_WORD:
/[^\[\]\|]*/
;
Boolean:
(
"?"
(value=Statement)?
)?
;
Default:
(
","
(value=Statement)?
)?
;