parser: Sequencia de cerrada de ATX Heading
This commit is contained in:
parent
3875e464a6
commit
3ccaba3104
3 changed files with 45 additions and 9 deletions
50
parser.zig
50
parser.zig
|
@ -135,13 +135,14 @@ fn checkIfBlockStillMatches(line: *[]const u8, block: Block) bool {
|
|||
const ATXHeading = struct {
|
||||
spaces: u2,
|
||||
level: u3,
|
||||
closing_sequence: usize,
|
||||
closing_sequence_spaces: usize,
|
||||
|
||||
pub fn content(self: ATXHeading, line: []const u8) []const u8 {
|
||||
if (line.len > self.spaces + self.level) {
|
||||
return line[self.spaces + self.level + 1 ..];
|
||||
} else {
|
||||
// If it's an empty heading without a space (example 79)
|
||||
return line[self.spaces + self.level ..];
|
||||
}
|
||||
// It's possible it might not have a space after the heading as it can
|
||||
// be an empty heading.
|
||||
const has_space: u1 = if (line.len > self.spaces + self.level) 1 else 0;
|
||||
return line[self.spaces + self.level + has_space .. line.len - self.closing_sequence - self.closing_sequence_spaces];
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -165,7 +166,42 @@ fn parseATXHeading(line: []const u8) ?ATXHeading {
|
|||
return null;
|
||||
}
|
||||
if (level == 0) return null;
|
||||
return ATXHeading{ .level = level, .spaces = spaces };
|
||||
var heading = ATXHeading{
|
||||
.level = level,
|
||||
.spaces = spaces,
|
||||
.closing_sequence = 0,
|
||||
.closing_sequence_spaces = 0,
|
||||
};
|
||||
closing_sequence_block: {
|
||||
const rest = heading.content(line);
|
||||
var closing_sequence: usize = 0;
|
||||
var closing_sequence_spaces: usize = 0;
|
||||
if (rest.len == 0) break :closing_sequence_block;
|
||||
var i: usize = rest.len - 1;
|
||||
while (i >= 0) : (i -= 1) {
|
||||
const char = rest[i];
|
||||
if (char == ' ')
|
||||
closing_sequence_spaces += 1
|
||||
else if (char == '#')
|
||||
break
|
||||
else
|
||||
break :closing_sequence_block;
|
||||
if (i == 0) break;
|
||||
}
|
||||
while (i >= 0) : (i -= 1) {
|
||||
const char = rest[i];
|
||||
if (char == '#')
|
||||
closing_sequence += 1
|
||||
else if (char == ' ' or char == '\t')
|
||||
break
|
||||
else
|
||||
break :closing_sequence_block;
|
||||
if (i == 0) break;
|
||||
}
|
||||
heading.closing_sequence = closing_sequence;
|
||||
heading.closing_sequence_spaces = closing_sequence_spaces;
|
||||
}
|
||||
return heading;
|
||||
}
|
||||
fn checkIfBlockStarts(allocator: std.mem.Allocator, line: *[]const u8) !?Block {
|
||||
if (std.mem.startsWith(u8, line.*, ">")) {
|
||||
|
|
|
@ -19,7 +19,7 @@ Ver [cli.zig](cli.zig)
|
|||
|
||||
## CommonMark
|
||||
|
||||
Actualmente: `123 passed, 529 failed, 0 errored, 0 skipped`
|
||||
Actualmente: `127 passed, 525 failed, 0 errored, 0 skipped`
|
||||
|
||||
Para correr los tests:
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ See [cli.zig](cli.zig)
|
|||
|
||||
## CommonMark
|
||||
|
||||
Currently: `114 passed, 538 failed, 0 errored, 0 skipped`
|
||||
Currently: `127 passed, 525 failed, 0 errored, 0 skipped`
|
||||
|
||||
To run the tests:
|
||||
|
||||
|
|
Loading…
Reference in a new issue