Skip to content

Commit 805a9a7

Browse files
committed
Add support for time code literals
1 parent dba087f commit 805a9a7

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

atom/language-flitter/grammars/flitter.cson

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ patterns: [
1111
match: '--.*$'
1212
name: 'comment.single.flitter'
1313
}
14+
{
15+
match: '\\b([0-9]+:)?[0-5]?[0-9]:[0-5]?[0-9](\\.[0-9]+)?\\b'
16+
name: 'constant.timecode.flitter'
17+
}
1418
{
1519
match: '\\b[-+]?([0-9][_0-9]*(\\.[0-9][_0-9]*)?|\\.[0-9][_0-9]*)([eE][-+]?[0-9][_0-9]*)?[pnuµmkMGT]?\\b'
1620
name: 'constant.numeric.flitter'

docs/language.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,23 @@ symbol, then that symbol must be used to retrieve the state value. If a string
238238
has been used, then a symbol *cannot* be used to retrieve the value.
239239
:::
240240

241+
### Time codes
242+
243+
In addition to normal literal numbers, as described above, **Flitter** supports
244+
literal *time codes*, which are given as a sequence of hours, minutes and
245+
seconds separated with colon characters (`:`), with the hours being optional
246+
and the seconds having an optional decimal fraction. For example:
247+
248+
```flitter
249+
!video filename='test.mp4' position=02:05.3
250+
```
251+
252+
Time codes are converted by the parser into a single-item numeric vector
253+
representing the total number of seconds (*125.3* in the example above).
254+
The hours component may be an arbitrarily large integer value, the minutes
255+
and seconds must be in the range *[0,60)*. Time codes may not be combined with
256+
exponents or SI prefixes, and do not support `_` separators.
257+
241258
### Nodes
242259

243260
The purpose of any **Flitter** program is to construct a render tree.

src/flitter/language/grammar.lark

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ NODE : /![_\p{alpha}][_\p{alnum}]*'*/i
1111
TAG : /#[_\p{alpha}][_\p{alnum}]*'*/i
1212
SYMBOL : /:[_\p{alpha}][_\p{alnum}]*'*/i
1313
NUMBER : /([0-9][_0-9]*(\.[0-9][_0-9]*)?|\.[0-9][_0-9]*)([eE][-+]?[0-9][_0-9]*)?[pnuµmkMGT]?/
14+
TIMECODE.2 : /([0-9]+:)?[0-5]?[0-9]:[0-5]?[0-9](\.[0-9]+)?/
1415
STRING : /('''([^'\\]|\\.|'{1,2}(?!'))*'''|'([^'\n\\]|\\.)*'|"""([^"\\]|\\.|"{1,2}(?!"))*"""|"([^"\n\\]|\\.)*")/
1516
_HASHBANG : /#!.*\r?\n/
1617
_LPAREN : "("
@@ -133,6 +134,7 @@ named_arg : NAME "=" node -> binding
133134
| _LPAREN node _RPAREN
134135

135136
literal : NUMBER
137+
| TIMECODE
136138
| STRING
137139
| SYMBOL
138140
| NODE

src/flitter/language/parser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ def NUMBER(self, token):
5656
token = token[:-1]
5757
return model.Vector.coerce(float(token) * multiplier)
5858

59+
def TIMECODE(self, token):
60+
parts = token.split(':')
61+
seconds = 60*int(parts[-2]) + float(parts[-1])
62+
if len(parts) == 3:
63+
seconds += 3600*int(parts[-3])
64+
return model.Vector.coerce(seconds)
65+
5966
def TAG(self, token):
6067
return intern(str(token)[1:])
6168

0 commit comments

Comments
 (0)