Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/prism/internal/line_offset_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "prism/compiler/force_inline.h"

#include "prism/internal/assert.h"

#include "prism/arena.h"
#include "prism/line_offset_list.h"

Expand All @@ -18,6 +20,10 @@ void pm_line_offset_list_append_slow(pm_arena_t *arena, pm_line_offset_list_t *l
/* Append a new offset to the list. */
static PRISM_FORCE_INLINE void
pm_line_offset_list_append(pm_arena_t *arena, pm_line_offset_list_t *list, uint32_t cursor) {
/* Line and column lookups binary search this list, so it must stay strictly
* increasing. */
PRISM_ASSERT(list->size == 0 || cursor > list->offsets[list->size - 1]);

if (list->size < list->capacity) {
list->offsets[list->size++] = cursor;
} else {
Expand Down
196 changes: 196 additions & 0 deletions snapshots/heredoc_percent_newline_delimiter.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
@ ProgramNode (location: (1,0)-(31,0))
├── flags: ∅
├── locals: []
└── statements:
@ StatementsNode (location: (1,0)-(31,0))
├── flags: ∅
└── body: (length: 7)
├── @ ArrayNode (location: (1,0)-(3,0))
│ ├── flags: newline, static_literal
│ ├── elements: (length: 1)
│ │ └── @ InterpolatedStringNode (location: (2,0)-(2,6))
│ │ ├── flags: static_literal, mutable
│ │ ├── opening_loc: ∅
│ │ ├── parts: (length: 1)
│ │ │ └── @ EmbeddedStatementsNode (location: (2,0)-(2,6))
│ │ │ ├── flags: ∅
│ │ │ ├── opening_loc: (2,0)-(2,2) = "\#{"
│ │ │ ├── statements:
│ │ │ │ @ StatementsNode (location: (2,2)-(2,5))
│ │ │ │ ├── flags: ∅
│ │ │ │ └── body: (length: 1)
│ │ │ │ └── @ StringNode (location: (2,2)-(2,5))
│ │ │ │ ├── flags: static_literal, frozen
│ │ │ │ ├── opening_loc: (2,2)-(2,5) = "<<B"
│ │ │ │ ├── content_loc: (3,0)-(3,0) = ""
│ │ │ │ ├── closing_loc: (3,0)-(4,0) = "B\n"
│ │ │ │ └── unescaped: ""
│ │ │ └── closing_loc: (2,5)-(2,6) = "}"
│ │ └── closing_loc: ∅
│ ├── opening_loc: (1,0)-(2,0) = "%W\n"
│ └── closing_loc: (2,6)-(3,0) = "\n"
├── @ ArrayNode (location: (5,0)-(7,0))
│ ├── flags: newline, static_literal
│ ├── elements: (length: 1)
│ │ └── @ InterpolatedSymbolNode (location: (6,0)-(6,6))
│ │ ├── flags: static_literal
│ │ ├── opening_loc: ∅
│ │ ├── parts: (length: 1)
│ │ │ └── @ EmbeddedStatementsNode (location: (6,0)-(6,6))
│ │ │ ├── flags: ∅
│ │ │ ├── opening_loc: (6,0)-(6,2) = "\#{"
│ │ │ ├── statements:
│ │ │ │ @ StatementsNode (location: (6,2)-(6,5))
│ │ │ │ ├── flags: ∅
│ │ │ │ └── body: (length: 1)
│ │ │ │ └── @ StringNode (location: (6,2)-(6,5))
│ │ │ │ ├── flags: static_literal, frozen
│ │ │ │ ├── opening_loc: (6,2)-(6,5) = "<<B"
│ │ │ │ ├── content_loc: (7,0)-(7,0) = ""
│ │ │ │ ├── closing_loc: (7,0)-(8,0) = "B\n"
│ │ │ │ └── unescaped: ""
│ │ │ └── closing_loc: (6,5)-(6,6) = "}"
│ │ └── closing_loc: ∅
│ ├── opening_loc: (5,0)-(6,0) = "%I\n"
│ └── closing_loc: (6,6)-(7,0) = "\n"
├── @ InterpolatedRegularExpressionNode (location: (9,0)-(11,0))
│ ├── flags: newline, static_literal
│ ├── opening_loc: (9,0)-(10,0) = "%r\n"
│ ├── parts: (length: 1)
│ │ └── @ EmbeddedStatementsNode (location: (10,0)-(10,6))
│ │ ├── flags: ∅
│ │ ├── opening_loc: (10,0)-(10,2) = "\#{"
│ │ ├── statements:
│ │ │ @ StatementsNode (location: (10,2)-(10,5))
│ │ │ ├── flags: ∅
│ │ │ └── body: (length: 1)
│ │ │ └── @ StringNode (location: (10,2)-(10,5))
│ │ │ ├── flags: static_literal, frozen
│ │ │ ├── opening_loc: (10,2)-(10,5) = "<<B"
│ │ │ ├── content_loc: (11,0)-(11,0) = ""
│ │ │ ├── closing_loc: (11,0)-(12,0) = "B\n"
│ │ │ └── unescaped: ""
│ │ └── closing_loc: (10,5)-(10,6) = "}"
│ └── closing_loc: (10,6)-(11,0) = "\n"
├── @ ArrayNode (location: (13,0)-(15,0))
│ ├── flags: newline
│ ├── elements: (length: 1)
│ │ └── @ InterpolatedStringNode (location: (14,0)-(14,8))
│ │ ├── flags: ∅
│ │ ├── opening_loc: ∅
│ │ ├── parts: (length: 3)
│ │ │ ├── @ StringNode (location: (14,0)-(14,1))
│ │ │ │ ├── flags: static_literal, frozen
│ │ │ │ ├── opening_loc: ∅
│ │ │ │ ├── content_loc: (14,0)-(14,1) = "a"
│ │ │ │ ├── closing_loc: ∅
│ │ │ │ └── unescaped: "a"
│ │ │ ├── @ EmbeddedStatementsNode (location: (14,1)-(14,7))
│ │ │ │ ├── flags: ∅
│ │ │ │ ├── opening_loc: (14,1)-(14,3) = "\#{"
│ │ │ │ ├── statements:
│ │ │ │ │ @ StatementsNode (location: (14,3)-(14,6))
│ │ │ │ │ ├── flags: ∅
│ │ │ │ │ └── body: (length: 1)
│ │ │ │ │ └── @ StringNode (location: (14,3)-(14,6))
│ │ │ │ │ ├── flags: static_literal, frozen
│ │ │ │ │ ├── opening_loc: (14,3)-(14,6) = "<<B"
│ │ │ │ │ ├── content_loc: (15,0)-(16,0) = "body\n"
│ │ │ │ │ ├── closing_loc: (16,0)-(17,0) = "B\n"
│ │ │ │ │ └── unescaped: "body\n"
│ │ │ │ └── closing_loc: (14,6)-(14,7) = "}"
│ │ │ └── @ StringNode (location: (14,7)-(14,8))
│ │ │ ├── flags: static_literal, frozen
│ │ │ ├── opening_loc: ∅
│ │ │ ├── content_loc: (14,7)-(14,8) = "b"
│ │ │ ├── closing_loc: ∅
│ │ │ └── unescaped: "b"
│ │ └── closing_loc: ∅
│ ├── opening_loc: (13,0)-(14,0) = "%W\n"
│ └── closing_loc: (14,8)-(15,0) = "\n"
├── @ ArrayNode (location: (18,0)-(20,0))
│ ├── flags: newline, static_literal
│ ├── elements: (length: 1)
│ │ └── @ InterpolatedSymbolNode (location: (19,0)-(19,8))
│ │ ├── flags: static_literal
│ │ ├── opening_loc: ∅
│ │ ├── parts: (length: 3)
│ │ │ ├── @ StringNode (location: (19,0)-(19,1))
│ │ │ │ ├── flags: static_literal, frozen
│ │ │ │ ├── opening_loc: ∅
│ │ │ │ ├── content_loc: (19,0)-(19,1) = "a"
│ │ │ │ ├── closing_loc: ∅
│ │ │ │ └── unescaped: "a"
│ │ │ ├── @ EmbeddedStatementsNode (location: (19,1)-(19,7))
│ │ │ │ ├── flags: ∅
│ │ │ │ ├── opening_loc: (19,1)-(19,3) = "\#{"
│ │ │ │ ├── statements:
│ │ │ │ │ @ StatementsNode (location: (19,3)-(19,6))
│ │ │ │ │ ├── flags: ∅
│ │ │ │ │ └── body: (length: 1)
│ │ │ │ │ └── @ StringNode (location: (19,3)-(19,6))
│ │ │ │ │ ├── flags: static_literal, frozen
│ │ │ │ │ ├── opening_loc: (19,3)-(19,6) = "<<B"
│ │ │ │ │ ├── content_loc: (20,0)-(21,0) = "body\n"
│ │ │ │ │ ├── closing_loc: (21,0)-(22,0) = "B\n"
│ │ │ │ │ └── unescaped: "body\n"
│ │ │ │ └── closing_loc: (19,6)-(19,7) = "}"
│ │ │ └── @ StringNode (location: (19,7)-(19,8))
│ │ │ ├── flags: static_literal, frozen
│ │ │ ├── opening_loc: ∅
│ │ │ ├── content_loc: (19,7)-(19,8) = "b"
│ │ │ ├── closing_loc: ∅
│ │ │ └── unescaped: "b"
│ │ └── closing_loc: ∅
│ ├── opening_loc: (18,0)-(19,0) = "%I\n"
│ └── closing_loc: (19,8)-(20,0) = "\n"
├── @ InterpolatedRegularExpressionNode (location: (23,0)-(25,0))
│ ├── flags: newline, static_literal
│ ├── opening_loc: (23,0)-(24,0) = "%r\n"
│ ├── parts: (length: 3)
│ │ ├── @ StringNode (location: (24,0)-(24,1))
│ │ │ ├── flags: static_literal, frozen
│ │ │ ├── opening_loc: ∅
│ │ │ ├── content_loc: (24,0)-(24,1) = "a"
│ │ │ ├── closing_loc: ∅
│ │ │ └── unescaped: "a"
│ │ ├── @ EmbeddedStatementsNode (location: (24,1)-(24,7))
│ │ │ ├── flags: ∅
│ │ │ ├── opening_loc: (24,1)-(24,3) = "\#{"
│ │ │ ├── statements:
│ │ │ │ @ StatementsNode (location: (24,3)-(24,6))
│ │ │ │ ├── flags: ∅
│ │ │ │ └── body: (length: 1)
│ │ │ │ └── @ StringNode (location: (24,3)-(24,6))
│ │ │ │ ├── flags: static_literal, frozen
│ │ │ │ ├── opening_loc: (24,3)-(24,6) = "<<B"
│ │ │ │ ├── content_loc: (25,0)-(27,0) = "=begin\n=end\n"
│ │ │ │ ├── closing_loc: (27,0)-(28,0) = "B\n"
│ │ │ │ └── unescaped: "=begin\n=end\n"
│ │ │ └── closing_loc: (24,6)-(24,7) = "}"
│ │ └── @ StringNode (location: (24,7)-(24,8))
│ │ ├── flags: static_literal, frozen
│ │ ├── opening_loc: ∅
│ │ ├── content_loc: (24,7)-(24,8) = "b"
│ │ ├── closing_loc: ∅
│ │ └── unescaped: "b"
│ └── closing_loc: (24,8)-(25,0) = "\n"
└── @ InterpolatedRegularExpressionNode (location: (29,0)-(31,0))
├── flags: newline, static_literal
├── opening_loc: (29,0)-(30,0) = "%r\n"
├── parts: (length: 1)
│ └── @ EmbeddedStatementsNode (location: (30,0)-(30,6))
│ ├── flags: ∅
│ ├── opening_loc: (30,0)-(30,2) = "\#{"
│ ├── statements:
│ │ @ StatementsNode (location: (30,2)-(30,5))
│ │ ├── flags: ∅
│ │ └── body: (length: 1)
│ │ └── @ StringNode (location: (30,2)-(30,5))
│ │ ├── flags: static_literal, frozen
│ │ ├── opening_loc: (30,2)-(30,5) = "<<B"
│ │ ├── content_loc: (31,0)-(32,0) = "__END__\n"
│ │ ├── closing_loc: (32,0)-(33,0) = "B\n"
│ │ └── unescaped: "__END__\n"
│ └── closing_loc: (30,5)-(30,6) = "}"
└── closing_loc: (30,6)-(31,0) = "\n"
2 changes: 0 additions & 2 deletions src/line_offset_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "prism/compiler/align.h"
#include "prism/internal/arena.h"
#include "prism/internal/assert.h"

#include <string.h>

Expand Down Expand Up @@ -40,7 +39,6 @@ pm_line_offset_list_append_slow(pm_arena_t *arena, pm_line_offset_list_t *list,
list->offsets = new_offsets;
list->capacity = new_capacity;

PRISM_ASSERT(list->size == 0 || cursor > list->offsets[list->size - 1]);
list->offsets[list->size++] = cursor;
}

Expand Down
Loading
Loading