Implement a basic keypath parser that tokenizes a keypath into path + interface pairs.
Showing
1 changed file
with
20 additions
and
0 deletions
... | @@ -348,6 +348,26 @@ class Rivets.View | ... | @@ -348,6 +348,26 @@ class Rivets.View |
348 | @models[key] = model for key, model of models | 348 | @models[key] = model for key, model of models |
349 | binding.update models for binding in @bindings | 349 | binding.update models for binding in @bindings |
350 | 350 | ||
351 | # Rivets.KeypathParser | ||
352 | # -------------------- | ||
353 | |||
354 | # Parser and tokenizer for keypaths in binding declarations. | ||
355 | class Rivets.KeypathParser | ||
356 | # Parses the keypath and returns a set of adapter interface + path tokens. | ||
357 | @parse: (keypath, interfaces, root) -> | ||
358 | tokens = [] | ||
359 | current = {interface: root, path: ''} | ||
360 | |||
361 | for index, char of keypath | ||
362 | if char in interfaces | ||
363 | tokens.push current | ||
364 | current = {interface: char, path: ''} | ||
365 | else | ||
366 | current.path += char | ||
367 | |||
368 | tokens.push current | ||
369 | tokens | ||
370 | |||
351 | # Rivets.TextTemplateParser | 371 | # Rivets.TextTemplateParser |
352 | # ------------------------- | 372 | # ------------------------- |
353 | 373 | ... | ... |
-
Please register or sign in to post a comment