Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- source ../plugin/vimpeg.vim
- let p = Vimpeg({'skip_white': 1})
- " <expression> ::= '(' <statement> ')' | <statement> | <predicate>
- " <statement> ::= <equivalence> | <implication> | <xor> | <or> | <and> | <not>
- " <equivalence> ::= <expression> '<[-=]>' <expression>
- " <implication> ::= <expression> '[-=]>' <expression>
- " <xor> ::= <expression> '*' <expression>
- " <or> ::= <expression> '[vV]' <expression> ( '[vV]' <expression> )*
- " <and> ::= <expression> '[&^]' <expression> ( '[&^]' <expression> )*
- " <not> ::= '[~!]' <expression>
- " <predicate> ::= '[a-uA-U]' | '[w-zW-Z]'
- " '~p', 'p', 'p ^ q', 'p v q', 'p => q', 'p <-> q', 'p ^ (q => r)'
- "let expr = p.or([p.and([p.e('('), 'statement', p.e(')')]), 'statement', 'predicate'],
- let expr = p.or(['equivalence', 'implication', 'xor', 'or', 'and', 'not', 'predicate'],
- \{'id': 'expression', 'on_match': 'Expression'})
- "call p.or(['equivalence', 'implication', 'xor', 'or', 'and', 'not'],
- "let expr = p.or(['and', 'not', 'predicate'],
- " \{'id': 'statement', 'on_match': 'Statement'})
- call p.and(['predicate', p.e('<[-=]>'), 'predicate'],
- \{'id': 'equivalence', 'on_match': 'Equivalence'})
- call p.and(['predicate', p.e('[-=]>'), 'predicate'],
- \{'id': 'implication', 'on_match' : 'Implication'})
- call p.and(['predicate', p.e('*'), 'predicate', p.maybe_many([p.e('*'), 'predicate'])],
- \{'id': 'xor', 'on_match': 'Xor'})
- call p.and(['predicate', p.e('[vV∨]'), 'predicate'],
- \{'id': 'or', 'on_match': 'Or'})
- call p.and(['predicate', p.e('[&∧^]'), 'predicate'],
- \{'id': 'and', 'on_match': 'And'})
- call p.and([p.e('[~!¬]'), 'predicate'],
- \{'id': 'not', 'on_match': 'Not'})
- call p.e('[a-uA-U]\|[w-zW-Z]',
- \{'id': 'predicate', 'on_match': 'Predicate'})
- function! Expression(elems)
- echo 'Expression: '.string(a:elems)
- endfunction
- function! Statement(elems)
- echo 'Statement: '.string(a:elems)
- endfunction
- function! Equivalence(elems)
- echo 'Equivalence: '.string(a:elems)
- endfunction
- function! Implication(elems)
- echo 'Implication: '.string(a:elems)
- endfunction
- function! Xor(elems)
- echo 'Xor: '.string(a:elems)
- endfunction
- function! Or(elems)
- echo 'Or: '.string(a:elems)
- endfunction
- function! And(elems)
- echo 'And: '.string(a:elems)
- endfunction
- function! Not(elems)
- echo 'Not: '.string(a:elems)
- endfunction
- function! Predicate(elems)
- echo 'Predicate: '.string(a:elems)
- endfunction
- function! Test(expr)
- return string(g:expr.match(a:expr))
- endfunction
- echo Test('p =>q')
Advertisement
Add Comment
Please, Sign In to add comment