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
-
#scan_first_copy ⇒ Boolean
Scans for a block.
-
#scan_first_directive ⇒ Boolean
Scans a directive.
-
#scan_first_directive_arguments ⇒ Array<Argument>
Scan the arguments for a directive.
-
#scan_first_part ⇒ void
Scans until the first content boundry.
Instance Method Details
#scan_first_copy ⇒ Boolean
Scans for a block. It is called copy
instead of block
because
contents of the block is copied directly into the body.
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_directive ⇒ Boolean
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
47 48 49 50 51 52 53 54 |
# File 'lib/antelope/ace/scanner/first.rb', line 47 def scan_first_directive if @scanner.scan(/%(#{IDENTIFIER}) ?/) directive = @scanner[1] arguments = scan_first_directive_arguments tokens << [:directive, directive, arguments] end end |
#scan_first_directive_arguments ⇒ Array<Argument>
Scan the arguments for a directive. It keeps attempting to
scan arguments until the first newline that was not in a
block. Arguments can be blocks, carets, or text; blocks are
encapsulated with {
and }
, carets are encapsulated with
<
and >
, and text is encapsulated with quotes or
nothing.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/antelope/ace/scanner/first.rb', line 64 def scan_first_directive_arguments arguments = [] until @scanner.check(/\n/) if @scanner.scan(/\{/) argument = Argument.new(:block, _scan_block[1..-2]) elsif @scanner.scan(/</) @scanner.scan(/((?:\\>|[^>])*)\>/) argument = Argument.new(:caret, @scanner[1]) else @scanner.scan(/#{VALUE}/x) or error! argument = Argument.new(:text, @scanner[2] || @scanner[3]) end arguments.push(argument) @scanner.scan(/ */) end arguments end |
#scan_first_part ⇒ void
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.
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 || scan_comment || error! end end |