logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

gherkin.lua (1160B)


  1. -- Copyright 2015-2024 Jason Schindler. See LICENSE.
  2. -- Gherkin (https://github.com/cucumber/cucumber/wiki/Gherkin) LPeg lexer.
  3. local lexer = require('lexer')
  4. local token, word_match = lexer.token, lexer.word_match
  5. local P, S = lpeg.P, lpeg.S
  6. local lex = lexer.new('gherkin', {fold_by_indentation = true})
  7. -- Whitespace.
  8. lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
  9. -- Keywords.
  10. lex:add_rule('keyword', token(lexer.KEYWORD, word_match(
  11. 'And Background But Examples Feature Given Outline Scenario Scenarios Then When')))
  12. -- Strings.
  13. local doc_str = lexer.range('"""')
  14. local dq_str = lexer.range('"')
  15. lex:add_rule('string', token(lexer.STRING, doc_str + dq_str))
  16. -- Comments.
  17. lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#')))
  18. -- Numbers.
  19. -- lex:add_rule('number', token(lexer.NUMBER, lexer.number))
  20. -- Tags.
  21. lex:add_rule('tag', token(lexer.LABEL, '@' * lexer.word^0))
  22. -- Placeholders.
  23. lex:add_rule('placeholder', token(lexer.VARIABLE, lexer.range('<', '>', false, false, true)))
  24. -- Examples.
  25. lex:add_rule('example', token(lexer.DEFAULT, lexer.to_eol('|')))
  26. lexer.property['scintillua.comment'] = '#'
  27. return lex