Reikriam

lark-extern

Jul 25th, 2020
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. from lark import Lark
  2.  
  3. test_str = """
  4. //asdasd
  5.  
  6. extern "C"
  7. {
  8.  
  9. //odfsafd
  10. def ak():
  11.  
  12. //blablabla
  13. def xkcd():
  14.  
  15. }
  16.  
  17. """
  18.  
  19. pydef_parser = Lark(r"""
  20. file: (COMMENT)* "extern 'C' {" [(COMMENT)*(def)*]* "}"
  21. def: "def" FUNCNAME "():"
  22.  
  23. FUNCNAME: LETTER[(INT)*(LETTER)*]*
  24. COMMENT: /\/\/[^\n]*/
  25. | /#include[^\n]*/
  26.  
  27. %import common.LETTER
  28. %import common.INT
  29. %import common.WS
  30. %ignore WS
  31. %ignore COMMENT
  32. """, start="file")
  33.  
  34. print(pydef_parser.parse(test_str))
Advertisement
Add Comment
Please, Sign In to add comment