Module: Hamlit::Parsers::Script
- Extended by:
- Concerns::Included
- Includes:
- Concerns::Error, Concerns::Indentable
- Included in:
- Hamlit::Parser
- Defined in:
- lib/hamlit/parsers/script.rb
Constant Summary collapse
- INTERNAL_STATEMENTS =
%w[else elsif rescue ensure when].freeze
- DEFAULT_SCRIPT_OPTIONS =
{ force_escape: false, disable_escape: false }.freeze
Instance Method Summary collapse
Methods included from Concerns::Included
Methods included from Concerns::Indentable
#count_indent, #count_width, #indent_label, #next_indent, #next_width, #replace_hard_tabs, #reset_indent, #same_indent?, #validate_indentation!, #with_indented
Methods included from Concerns::Error
#assert_scan!, #copmile_error!, #syntax_error, #syntax_error!
Instance Method Details
#parse_script(scanner, options = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/hamlit/parsers/script.rb', line 20 def parse_script(scanner, = {}) assert_scan!(scanner, /=|&=|!=|~/) = DEFAULT_SCRIPT_OPTIONS.merge() code, with_comment = scan_code(scanner, comment_check: true) return syntax_error("There's no Ruby code for = to evaluate.") if code.empty? && !with_comment unless has_block? return [:dynamic, code] if [:disable_escape] return escape_html([:dynamic, code], [:force_escape]) end ast = [:haml, :script, code, ] ast += with_indented { parse_lines } ast << [:code, 'end'] ast end |
#parse_silent_script(scanner) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/hamlit/parsers/script.rb', line 37 def parse_silent_script(scanner) assert_scan!(scanner, /-/) if scanner.scan(/#/) with_indented { skip_lines } return [:multi] end code = scan_code(scanner) ast = [:multi, [:code, code]] unless has_block? if internal_statement?(code) && !statement_continuing? ast << [:code, 'end'] end return ast end ast += with_indented { parse_lines } unless statement_continuing? ast << [:code, 'end'] end ast end |