Class: Kwalify::Yaml::Parser

Inherits:
BaseParser
  • Object
show all
Defined in:
lib/kwalify/parser/yaml-patcher.rb

Instance Method Summary collapse

Instance Method Details

#parse_block_value(level, rule, path, uniq_table, container) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/kwalify/parser/yaml-patcher.rb', line 2

def parse_block_value(level, rule, path, uniq_table, container)
  skip_spaces_and_comments
  ## nil
  return nil if @column < level || (@column == level && !match?(/-\s+/)) || eos?
  ## anchor and alias
  name = nil
  if scan(/\&([-\w]+)/)
    name = parse_anchor(rule, path, uniq_table, container)
  elsif scan(/\*([-\w]+)/)
    return parse_alias(rule, path, uniq_table, container)
  end
  ## type
  skip_spaces_and_comments if scan(/!!?\w+/)
  ## sequence
  if match?(/-\s+/)
    if rule && !rule.sequence
      # _validate_error("sequence is not expected.", path)
      rule = nil
    end
    seq = create_sequence(rule, @linenum, @column)
    @anchors[name] = seq if name
    parse_block_seq(seq, rule, path, uniq_table)
    return seq
  end
  ## mapping
  if match?(MAPKEY_PATTERN)
    if rule && !rule.mapping
      # _validate_error("mapping is not expected.", path)
      rule = nil
    end
    map = create_mapping(rule, @linenum, @column)
    @anchors[name] = map if name
    parse_block_map(map, rule, path, uniq_table)
    return map
  end
  ## sequence (flow-style)
  if match?(/\[/)
    if rule && !rule.sequence
      # _validate_error("sequence is not expected.", path)
      rule = nil
    end
    seq = create_sequence(rule, @linenum, @column)
    @anchors[name] = seq if name
    parse_flow_seq(seq, rule, path, uniq_table)
    return seq
  end
  ## mapping (flow-style)
  if match?(/\{/)
    if rule && !rule.mapping
      # _validate_error("mapping is not expected.", path)
      rule = nil
    end
    map = create_mapping(rule, @linenum, @column)
    @anchors[name] = map if name
    parse_flow_map(map, rule, path, uniq_table)
    return map
  end
  ## block text
  if match?(/[|>]/)
    text = parse_block_text(level, rule, path, uniq_table)
    @anchors[name] = text if name
    return text
  end
  ## scalar
  scalar = parse_block_scalar(rule, path, uniq_table)
  @anchors[name] = scalar if name
  scalar
end