Skip to content

Commit 913e680

Browse files
author
Itay Donanhirsh
committed
%stop!
1 parent 145aea6 commit 913e680

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- [# %stop #] -->
1+
<!-- [# %stop! #] -->
22

33
# [# Clutter #]
44

@@ -111,7 +111,7 @@ These tags are written as a normal tag to the index, with an added attribute `se
111111

112112
### Pragma Tags
113113

114-
There are only two pragma tags implemented: `%stop` and `%cont`. Example:
114+
There are only three pragma tags implemented: `%stop`, '%stop!' and `%cont`. Example:
115115

116116
```
117117
[# to_be #]
@@ -121,6 +121,9 @@ There are only two pragma tags implemented: `%stop` and `%cont`. Example:
121121
[# that_is_the_question #]
122122
```
123123

124+
`%stop!` will stop parsing the file entirely, ignoring further pragmas as well.
125+
126+
124127
## Index
125128

126129
To generate an index, use:

internal/pkg/scanner/scan_raw.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func ScanRawReader(
1313
z *zap.SugaredLogger,
1414
cfg BracketConfig,
1515
r io.Reader,
16-
f func(*RawElement) error, // will not include path. path is filled in [# .fill-path #].
16+
f func(*RawElement) error, // will not include path. path is filled in [# ./fill-path #].
1717
) error {
1818
re, err := cfg.Regexp()
1919
if err != nil {
@@ -24,6 +24,7 @@ func ScanRawReader(
2424

2525
stopped := false
2626

27+
S:
2728
for i := 0; scanner.Scan(); i++ {
2829
line := scanner.Text()
2930

@@ -39,6 +40,10 @@ func ScanRawReader(
3940

4041
if strings.HasPrefix(text, "%") {
4142
switch text[1:] {
43+
case "stop!":
44+
// hard stop will stop scanning the rest of the file.
45+
break S
46+
4247
case "stop":
4348
if stopped {
4449
return fmt.Errorf("already stopped")
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package scanner
2+
3+
import (
4+
"fmt"
5+
"io"
6+
7+
"go.uber.org/zap"
8+
)
9+
10+
func ScanSitterReader(
11+
z *zap.SugaredLogger,
12+
cfg BracketConfig,
13+
r io.Reader,
14+
f func(*RawElement) error, // will not include path. path is filled in [# ./fill-path #].
15+
) error {
16+
_, err := cfg.Regexp()
17+
if err != nil {
18+
return fmt.Errorf("invalid bracket: %w", err)
19+
}
20+
21+
return nil
22+
}

0 commit comments

Comments
 (0)