From 8521bf4c5042825653ef324b371a4491818b986d Mon Sep 17 00:00:00 2001 From: Alex T Date: Mon, 20 Nov 2017 18:42:41 +0200 Subject: [PATCH] added test for empty suffix (+1 squashed commit) Squashed commits: [25e1926] allow empty subject suffix --- lex.go | 4 +++- lex_test.go | 7 +++++++ rune.go | 10 ++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lex.go b/lex.go index 3bd382d..8f07d9d 100644 --- a/lex.go +++ b/lex.go @@ -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 } diff --git a/lex_test.go b/lex_test.go index 85b2880..43e12cb 100644 --- a/lex_test.go +++ b/lex_test.go @@ -294,6 +294,13 @@ two {tokenIRIAbs, "http://a.example/o"}, {tokenEOF, ""}}, }, + {`p: `, []testToken{ + {tokenPrefixLabel, "p"}, + {tokenIRISuffix, ""}, + {tokenIRIAbs, "http://a.example/p"}, + {tokenIRIAbs, "http://a.example/o"}, + {tokenEOF, ""}}, + }, {"@base .", []testToken{ {tokenBase, "base"}, {tokenIRIAbs, "http:/a.org/"}, diff --git a/rune.go b/rune.go index 23c7595..3d1e3dc 100644 --- a/rune.go +++ b/rune.go @@ -13,6 +13,7 @@ var ( badIRIRunes = [...]rune{' ', '<', '"', '{', '}', '|', '^', '`'} badIRIRunesEsc = [...]rune{' ', '<', '"', '{', '}', '|', '^', '`', '>'} okAfterRDFType = [...]rune{' ', '\t', '<', '"', '\''} + whitespace = [...]rune{' ', '\t', '\r', '\n'} pnTab = []rune{ 'A', 'Z', 'a', 'z', @@ -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