Module: Antelope::Ace::Scanner::First

Included in:
Antelope::Ace::Scanner
Defined in:
lib/antelope/ace/scanner/first.rb

Overview

Scans the first section of the file. This contains directives and small blocks that can be copied directly into the body of the output. The blocks are formatted as %{ ... %}; however, the ending tag must be on its own line. The directive is formatted as %<name> <value>, with <name> being the key, and <value> being the value. The value can be a piece of straight-up text (no quotes), or it can be quoted. There can be any number of values to a directive.

Instance Method Summary collapse

Instance Method Details

#scan_first_copyBoolean

Scans for a block. It is called copy instead of block because contents of the block is copied directly into the body.

Returns:

  • (Boolean)

    if it matched.



33
34
35
36
37
# File 'lib/antelope/ace/scanner/first.rb', line 33

def scan_first_copy
  if @scanner.scan(/%{([\s\S]+?)\n\s*%}/)
    tokens << [:copy, @scanner[1]]
  end
end

#scan_first_directiveBoolean

Scans a directive. A directive has one name, and any number of arguments. Every argument is a value. The name can be any combinations of alphabetical characters, underscores, and dashes; the value can be word characters, or a quote-delimited string. It emits a :directive token with the directive (Sring) as an argument, and the passed arguments (Array).

Returns:

  • (Boolean)

    if it matched.



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/antelope/ace/scanner/first.rb', line 47

def scan_first_directive
  if @scanner.scan(/%([A-Za-z_-]+) ?/)
    directive = @scanner[1]
    arguments = []
    until @scanner.check(/\n/)
      @scanner.scan(/#{VALUE}/x) or error!
      arguments.push(@scanner[2] || @scanner[3])
      @scanner.scan(/ */)
    end

    tokens << [:directive, directive, arguments]
  end
end

#scan_first_partvoid

This method returns an undefined value.

Scans until the first content boundry. If it encounters anything but a block or a directive (or whitespace), it will raise an error.

Raises:

  • (SyntaxError)

    if it encounters anything but whitespace, a block, or a directive.



22
23
24
25
26
27
# File 'lib/antelope/ace/scanner/first.rb', line 22

def scan_first_part
  until @scanner.check(CONTENT_BOUNDRY)
    scan_first_copy || scan_first_directive ||
    scan_whitespace || error!
  end
end