aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-12-11 19:42:32 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-12-11 19:42:32 +0900
commit3ec662c34841bb5bcf05166d1b9efd800b1e9ea3 (patch)
treea7acd4fa535819a941da862905a14bfffa8493b5
parentMake character properties unavailable in bracket expressions (diff)
downloadtre-3ec662c34841bb5bcf05166d1b9efd800b1e9ea3.tar.gz
tre-3ec662c34841bb5bcf05166d1b9efd800b1e9ea3.tar.xz
Add tests of compiler/parser package
Diffstat (limited to '')
-rw-r--r--compiler/parser/error.go1
-rw-r--r--compiler/parser/parser.go8
-rw-r--r--compiler/parser/parser_test.go8
3 files changed, 13 insertions, 4 deletions
diff --git a/compiler/parser/error.go b/compiler/parser/error.go
index 8be6600..be81da4 100644
--- a/compiler/parser/error.go
+++ b/compiler/parser/error.go
@@ -15,6 +15,7 @@ var (
// syntax errors
synErrUnexpectedToken = fmt.Errorf("unexpected token")
synErrNullPattern = fmt.Errorf("a pattern must be a non-empty byte sequence")
+ synErrUnmatchablePattern = fmt.Errorf("a pattern cannot match any characters")
synErrAltLackOfOperand = fmt.Errorf("an alternation expression must have operands")
synErrRepNoTarget = fmt.Errorf("a repeat expression must have an operand")
synErrGroupNoElem = fmt.Errorf("a grouping expression must include at least one character")
diff --git a/compiler/parser/parser.go b/compiler/parser/parser.go
index 70d1ce6..fd85fab 100644
--- a/compiler/parser/parser.go
+++ b/compiler/parser/parser.go
@@ -205,7 +205,7 @@ func (p *parser) parseSingleChar() CPTree {
}
inverse := exclude(elem, genAnyCharAST())
if inverse == nil {
- panic(fmt.Errorf("a pattern that isn't matching any symbols"))
+ p.raiseParseError(synErrUnmatchablePattern, "")
}
for {
elem := p.parseBExpElem()
@@ -214,7 +214,7 @@ func (p *parser) parseSingleChar() CPTree {
}
inverse = exclude(elem, inverse)
if inverse == nil {
- panic(fmt.Errorf("a pattern that isn't matching any symbols"))
+ p.raiseParseError(synErrUnmatchablePattern, "")
}
}
if p.consume(tokenKindEOF) {
@@ -355,12 +355,12 @@ func (p *parser) parseCharProp() CPTree {
r := cpRanges[0]
alt = exclude(newRangeSymbolNode(r.From, r.To), genAnyCharAST())
if alt == nil {
- panic(fmt.Errorf("a pattern that isn't matching any symbols"))
+ p.raiseParseError(synErrUnmatchablePattern, "")
}
for _, r := range cpRanges[1:] {
alt = exclude(newRangeSymbolNode(r.From, r.To), alt)
if alt == nil {
- panic(fmt.Errorf("a pattern that isn't matching any symbols"))
+ p.raiseParseError(synErrUnmatchablePattern, "")
}
}
} else {
diff --git a/compiler/parser/parser_test.go b/compiler/parser/parser_test.go
index 1fa0489..bad6404 100644
--- a/compiler/parser/parser_test.go
+++ b/compiler/parser/parser_test.go
@@ -472,6 +472,14 @@ func TestParse(t *testing.T) {
syntaxError: synErrRangePropIsUnavailable,
},
{
+ pattern: "[^\\u{0000}-\\u{10FFFF}]",
+ syntaxError: synErrUnmatchablePattern,
+ },
+ {
+ pattern: "[^\\u{0000}-\\u{FFFF}\\u{010000}-\\u{10FFFF}]",
+ syntaxError: synErrUnmatchablePattern,
+ },
+ {
pattern: "[^]",
ast: newSymbolNode('^'),
},