Class: XRT::Syntax
- Inherits:
-
Object
- Object
- XRT::Syntax
- Defined in:
- lib/xrt/syntax.rb
Instance Method Summary collapse
- #beginning_block?(statement) ⇒ Boolean
- #beginning_block_regexp ⇒ Object
- #block?(statement) ⇒ Boolean
- #block_level(statement) ⇒ Object
- #end_block?(statement) ⇒ Boolean
- #end_block_regexp ⇒ Object
- #remove_comment(statement) ⇒ Object
- #whitespace?(statement) ⇒ Boolean
Instance Method Details
#beginning_block?(statement) ⇒ Boolean
11 12 13 14 |
# File 'lib/xrt/syntax.rb', line 11 def beginning_block? statement without_comment = remove_comment statement without_comment =~ beginning_block_regexp end |
#beginning_block_regexp ⇒ Object
22 23 24 25 |
# File 'lib/xrt/syntax.rb', line 22 def beginning_block_regexp keywords = %w(IF UNLESS FOR FOREACH WHILE SWITCH MACRO BLOCK WRAPPER FILTER) /\[%.?\s*\b(#{keywords.join('|')})\b/i end |
#block?(statement) ⇒ Boolean
7 8 9 |
# File 'lib/xrt/syntax.rb', line 7 def block? statement statement =~ /\A\[%.+%\]\Z/m end |
#block_level(statement) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/xrt/syntax.rb', line 35 def block_level(statement) stripped = statement.strip return 0 unless block? stripped level = 0 level += 1 if beginning_block? stripped level -= 1 if end_block? stripped level end |
#end_block?(statement) ⇒ Boolean
16 17 18 19 20 |
# File 'lib/xrt/syntax.rb', line 16 def end_block? statement return unless block? statement without_comment = remove_comment statement without_comment =~ end_block_regexp end |
#end_block_regexp ⇒ Object
27 28 29 |
# File 'lib/xrt/syntax.rb', line 27 def end_block_regexp /\bEND\b/i end |
#remove_comment(statement) ⇒ Object
31 32 33 |
# File 'lib/xrt/syntax.rb', line 31 def remove_comment(statement) statement.gsub(/\s*#.*$/, '') end |
#whitespace?(statement) ⇒ Boolean
3 4 5 |
# File 'lib/xrt/syntax.rb', line 3 def whitespace? statement statement.match(/\A\s*\Z/) end |