1 -- Copyright 2006-2017 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- Ruby on Rails LPeg lexer.
4 local l
= require('lexer')
5 local token
, word_match
= l
.token
, l
.word_match
6 local P
, R
, S
= lpeg
.P
, lpeg
.R
, lpeg
.S
9 local M
= {_NAME
= 'rails'}
12 local ws
= token(l
.WHITESPACE
, l
.space^
1)
16 local actionpack
= token(l
.FUNCTION
, word_match
{
17 'before_filter', 'skip_before_filter', 'skip_after_filter', 'after_filter',
18 'around_filter', 'filter', 'filter_parameter_logging', 'layout',
19 'require_dependency', 'render', 'render_action', 'render_text', 'render_file',
20 'render_template', 'render_nothing', 'render_component',
21 'render_without_layout', 'rescue_from', 'url_for', 'redirect_to',
22 'redirect_to_path', 'redirect_to_url', 'respond_to', 'helper',
23 'helper_method', 'model', 'service', 'observer', 'serialize', 'scaffold',
24 'verify', 'hide_action'
27 local view_helpers
= token(l
.FUNCTION
, word_match
{
28 'check_box', 'content_for', 'error_messages_for', 'form_for', 'fields_for',
29 'file_field', 'hidden_field', 'image_submit_tag', 'label', 'link_to',
30 'password_field', 'radio_button', 'submit', 'text_field', 'text_area'
33 local activerecord
= token(l
.FUNCTION
, word_match
{
34 'after_create', 'after_destroy', 'after_save', 'after_update',
35 'after_validation', 'after_validation_on_create',
36 'after_validation_on_update', 'before_create', 'before_destroy',
37 'before_save', 'before_update', 'before_validation',
38 'before_validation_on_create', 'before_validation_on_update', 'composed_of',
39 'belongs_to', 'has_one', 'has_many', 'has_and_belongs_to_many', 'validate',
40 'validates', 'validate_on_create', 'validates_numericality_of',
41 'validate_on_update', 'validates_acceptance_of', 'validates_associated',
42 'validates_confirmation_of', 'validates_each', 'validates_format_of',
43 'validates_inclusion_of', 'validates_exclusion_of', 'validates_length_of',
44 'validates_presence_of', 'validates_size_of', 'validates_uniqueness_of',
45 'attr_protected', 'attr_accessible', 'attr_readonly',
46 'accepts_nested_attributes_for', 'default_scope', 'scope'
49 local active_support
= token(l
.FUNCTION
, word_match
{
50 'alias_method_chain', 'alias_attribute', 'delegate', 'cattr_accessor',
51 'mattr_accessor', 'returning', 'memoize'
54 -- Extend Ruby lexer to include Rails methods.
55 local ruby
= l
.load('ruby')
56 local _rules
= ruby
._rules
57 _rules
[1] = {'whitespace', ws
}
58 table.insert(_rules
, 3, {'actionpack', actionpack
})
59 table.insert(_rules
, 4, {'view_helpers', view_helpers
})
60 table.insert(_rules
, 5, {'activerecord', activerecord
})
61 table.insert(_rules
, 6, {'active_support', active_support
})
63 M
._foldsymbols
= ruby
._foldsymbols