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
Instance Method Details
#beginning_block?(statement) ⇒ Boolean
7 8 9 10 |
# File 'lib/xrt/syntax.rb', line 7 def beginning_block? statement without_comment = remove_comment statement without_comment =~ beginning_block_regexp end |
#beginning_block_regexp ⇒ Object
18 19 20 21 |
# File 'lib/xrt/syntax.rb', line 18 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
3 4 5 |
# File 'lib/xrt/syntax.rb', line 3 def block? statement statement =~ /\A\[%.+%\]\Z/m end |
#block_level(statement) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/xrt/syntax.rb', line 31 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
12 13 14 15 16 |
# File 'lib/xrt/syntax.rb', line 12 def end_block? statement return unless block? statement without_comment = remove_comment statement without_comment =~ end_block_regexp end |
#end_block_regexp ⇒ Object
23 24 25 |
# File 'lib/xrt/syntax.rb', line 23 def end_block_regexp /\bEND\b/i end |
#remove_comment(statement) ⇒ Object
27 28 29 |
# File 'lib/xrt/syntax.rb', line 27 def remove_comment(statement) statement.gsub(/\s*#.*$/, '') end |