Class: Gloss::Parser
- Inherits:
-
Object
- Object
- Gloss::Parser
- Defined in:
- lib/gloss/parser.rb
Instance Method Summary collapse
-
#initialize(str) ⇒ Parser
constructor
A new instance of Parser.
- #run ⇒ Object
Constructor Details
#initialize(str) ⇒ Parser
Returns a new instance of Parser.
7 8 9 |
# File 'lib/gloss/parser.rb', line 7 def initialize(str) @str = str end |
Instance Method Details
#run ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/gloss/parser.rb', line 10 def run() tree_json = Gloss.parse_buffer(@str) begin JSON.parse(tree_json, symbolize_names: true) rescue JSON::ParserError = tree_json .match(/.+\s:(\d+)$/) (if $~.[](1) line_number = $~.[](1) .to_i context = @str.lines .[]((( line_number.-(2) )..(line_number))) .map .with_index() { |line, index| "#{index.-(1) .+(line_number)}| #{line}" } .join = "#{context.rstrip}\n\n#{}\n" end) throw(:"error", ) end end |