Class: Psych::Pure::Parser::Context
- Inherits:
-
Object
- Object
- Psych::Pure::Parser::Context
- Defined in:
- lib/psych/pure.rb
Overview
A stack of contexts that the parser is currently within. We use this to decorate error messages with the context in which they occurred.
Instance Method Summary collapse
-
#initialize ⇒ Context
constructor
A new instance of Context.
- #syntax_error(source, filename, pos, message) ⇒ Object
- #within_block_mapping(pos, indent, &block) ⇒ Object
- #within_block_sequence(pos, indent, &block) ⇒ Object
- #within_double_quoted_scalar(pos, &block) ⇒ Object
- #within_flow_mapping(pos, context, &block) ⇒ Object
- #within_flow_sequence(pos, context, &block) ⇒ Object
Constructor Details
#initialize ⇒ Context
Returns a new instance of Context.
934 935 936 937 938 |
# File 'lib/psych/pure.rb', line 934 def initialize @contexts = [] @deepest = nil @deepest_depth = 0 end |
Instance Method Details
#syntax_error(source, filename, pos, message) ⇒ Object
940 941 942 943 944 945 946 947 948 949 950 951 952 953 |
# File 'lib/psych/pure.rb', line 940 def syntax_error(source, filename, pos, ) stack = @contexts.empty? ? @deepest : @contexts if stack && !stack.empty? pos = stack[-2] = "#{}\nwithin:\n" idx = 0 while idx < stack.size << " #{format_entry(source, stack[idx], stack[idx + 1], stack[idx + 2])}\n" idx += 3 # each entry uses 3 array slots [type, pos, extra] end end SyntaxError.new(filename, source.line(pos), source.column(pos), pos, , nil) end |
#within_block_mapping(pos, indent, &block) ⇒ Object
955 956 957 |
# File 'lib/psych/pure.rb', line 955 def within_block_mapping(pos, indent, &block) within(:block_mapping, pos, indent, &block) end |
#within_block_sequence(pos, indent, &block) ⇒ Object
959 960 961 |
# File 'lib/psych/pure.rb', line 959 def within_block_sequence(pos, indent, &block) within(:block_sequence, pos, indent, &block) end |
#within_double_quoted_scalar(pos, &block) ⇒ Object
963 964 965 |
# File 'lib/psych/pure.rb', line 963 def within_double_quoted_scalar(pos, &block) within(:double_quoted_scalar, pos, nil, &block) end |
#within_flow_mapping(pos, context, &block) ⇒ Object
967 968 969 |
# File 'lib/psych/pure.rb', line 967 def within_flow_mapping(pos, context, &block) within(:flow_mapping, pos, context, &block) end |
#within_flow_sequence(pos, context, &block) ⇒ Object
971 972 973 |
# File 'lib/psych/pure.rb', line 971 def within_flow_sequence(pos, context, &block) within(:flow_sequence, pos, context, &block) end |