bairui

Assignment Expression Grammar in Vimpeg

Jun 26th, 2011
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 1.74 KB | None | 0 0
  1. let ass = p.and(['name', p.e('='), 'expression'],                               {'id': 'assignment', 'on_match': 'Assignment'})
  2. call      p.and(['term', p.maybe_many(p.or(['add', 'subtract']))],              {'id': 'expression', 'on_match': 'Expression'})
  3. call      p.and([p.e('-'), 'term'],                                             {'id': 'subtract',   'on_match': 'Op'})
  4. call      p.and([p.e('+'), 'term'],                                             {'id': 'add',        'on_match': 'Op'})
  5. call      p.and(['factor', p.maybe_many(p.or(['multiply', 'divide']))],         {'id': 'term',       'on_match': 'Term'})
  6. call      p.and([p.e('/'), 'factor'],                                           {'id': 'divide',     'on_match': 'Op'})
  7. call      p.and([p.e('*'), 'factor'],                                           {'id': 'multiply',   'on_match': 'Op'})
  8. call       p.or(['number', p.and([p.e('('), 'expression', p.e(')')]), 'ident'], {'id': 'factor',     'on_match': 'Factor'})
  9. call       p.or(['func', 'name'],                                               {'id': 'ident',      'on_match': 'Ident'})
  10. call      p.and(['name', p.and([p.e('('), p.e(')')])],                          {'id': 'func',       'on_match': 'Func'})
  11. call      p.and(['alpha', p.maybe_many('alphanum')],                            {'id': 'name',       'on_match': 'Name'})
  12. call        p.e('[a-zA-Z_]',                                                    {'id': 'alpha'})
  13. call       p.or(['alpha', 'digit'],                                             {'id': 'alphanum'})
  14. call     p.many('digit',                                                        {'id': 'number',     'on_match': 'Number'})
  15. call        p.e('[0-9]',                                                        {'id': 'digit'})
Advertisement
Add Comment
Please, Sign In to add comment