Skip to content

Commit

Permalink
added test for empty suffix (+1 squashed commit)
Browse files Browse the repository at this point in the history
Squashed commits:
[25e1926] allow empty subject suffix
  • Loading branch information
tzapu authored and boutros committed Mar 4, 2019
1 parent b6ee24f commit 8521bf4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -942,8 +942,10 @@ func lexPrefixLabel(l *lexer) stateFn {
l.next()
l.ignore()

if l.peek() == '#' {
p := l.peek()
if p == '#' || isWhitespace(p) {
// emit empty IRI suffix, easier than dealing with special case in parser
// empty suffix is also valid as per https://dvcs.w3.org/hg/rdf/raw-file/default/rdf-turtle/index.html#grammar-production-PN_LOCAL
l.emit(tokenIRISuffix)
return lexAny
}
Expand Down
7 changes: 7 additions & 0 deletions lex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ two
{tokenIRIAbs, "http://a.example/o"},
{tokenEOF, ""}},
},
{`p: <http://a.example/p> <http://a.example/o>`, []testToken{
{tokenPrefixLabel, "p"},
{tokenIRISuffix, ""},
{tokenIRIAbs, "http://a.example/p"},
{tokenIRIAbs, "http://a.example/o"},
{tokenEOF, ""}},
},
{"@base <http:/a.org/>.", []testToken{
{tokenBase, "base"},
{tokenIRIAbs, "http:/a.org/"},
Expand Down
10 changes: 10 additions & 0 deletions rune.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var (
badIRIRunes = [...]rune{' ', '<', '"', '{', '}', '|', '^', '`'}
badIRIRunesEsc = [...]rune{' ', '<', '"', '{', '}', '|', '^', '`', '>'}
okAfterRDFType = [...]rune{' ', '\t', '<', '"', '\''}
whitespace = [...]rune{' ', '\t', '\r', '\n'}
pnTab = []rune{
'A', 'Z',
'a', 'z',
Expand Down Expand Up @@ -105,6 +106,15 @@ func isPnLocalMid(r rune) bool {
return check(r, plTab)
}

func isWhitespace(r rune) bool {
for _, w := range whitespace {
if r == w {
return true
}
}
return false
}

const (
runeError = math.MaxInt32

Expand Down

0 comments on commit 8521bf4

Please sign in to comment.