mirror of
https://github.com/hanzoai/graph.git
synced 2026-10-30 18:35:37 +00:00
Derived from Dgraph (github.com/dgraph-io/dgraph) at commit 64804bd2, Apache-2.0. See NOTICE. WHAT THIS IS. The graph engine as a Go library: posting lists, the DQL parser, the type and tokenizer system, the index and schema layers, and the wire types. 39,170 lines of the upstream's 166,337. THE STORE is github.com/luxfi/zapdb, a Badger fork that kept the package name, the subpackages (options, pb, y) and the API — Open, OpenManaged, DB, Options — so the 74 import sites are aliased rather than rewritten. THE CODEC is ZAP. zapdb serializes with ZAP, not protobuf: its pb package builds the ZAP types by default and the protobuf ones only under `-tags grpc`, a path that does not compile (table/builder.go calls pb.Marshal, which that tag removes). One call site in posting needed converting; every other type here is Hanzo's own protobuf and is untouched. NO TRANSPORT. An embedded engine dials nothing, so nothing here imports google.golang.org/grpc. Removed: 20 transport functions in x, the generated service stubs for Raft, Zero and Worker (1,657 lines), and the JWT helper — identity belongs to IAM. The core called none of them. NOT KEPT: worker, conn, raftwal, the cluster commands, the GraphQL layer and the test harnesses. `query`, the DQL execution engine, went with them because it depends on worker; parsing DQL is available here, executing it is not. The history of the upstream project lives at github.com/dgraph-io/dgraph. This repository begins at the derivation because three quarters of that history describes code this fork does not carry.
82 lines
1.8 KiB
Go
82 lines
1.8 KiB
Go
/*
|
|
* SPDX-FileCopyrightText: © 2017-2026 Istari Digital, Inc.
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
package lex
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// IRIRef emits an IRIREF or returns an error if the input is invalid.
|
|
func IRIRef(l *Lexer, styp ItemType) error {
|
|
l.Ignore() // ignore '<'
|
|
l.AcceptRunRec(isIRIRefChar)
|
|
l.Emit(styp) // will emit without '<' and '>'
|
|
r := l.Next()
|
|
if r == EOF {
|
|
return errors.New("Unexpected end of IRI")
|
|
}
|
|
if r != '>' {
|
|
return errors.Errorf("Unexpected character %q while parsing IRI", r)
|
|
}
|
|
l.Ignore() // ignore '>'
|
|
return nil
|
|
}
|
|
|
|
// isIRIRefChar returns whether the rune is a character allowed in an IRIRef.
|
|
// IRIREF ::= '<' ([^#x00-#x20<>"{}|^`\] | UCHAR)* '>'
|
|
func isIRIRefChar(r rune, l *Lexer) bool {
|
|
if r <= 32 { // no chars b/w 0x00 to 0x20 inclusive
|
|
return false
|
|
}
|
|
switch r {
|
|
case '<', '>', '"', '{', '}', '|', '^', '`':
|
|
return false
|
|
case '\\':
|
|
r2 := l.Next()
|
|
if r2 != 'u' && r2 != 'U' {
|
|
l.Backup()
|
|
return false
|
|
}
|
|
return HasUChars(r2, l)
|
|
}
|
|
return true
|
|
}
|
|
|
|
// HasUChars returns whether the lexer is at the beginning of a escaped Unicode character.
|
|
// UCHAR ::= '\u' HEX HEX HEX HEX | '\U' HEX HEX HEX HEX HEX HEX HEX HEX
|
|
func HasUChars(r rune, l *Lexer) bool {
|
|
if r != 'u' && r != 'U' {
|
|
return false
|
|
}
|
|
times := 4
|
|
if r == 'U' {
|
|
times = 8
|
|
}
|
|
return times == l.AcceptRunTimes(isHex, times)
|
|
}
|
|
|
|
// HasXChars returns whether the lexer is at the start of a escaped hexadecimal byte (e.g \xFE)
|
|
// XCHAR ::= '\x' HEX HEX
|
|
func HasXChars(r rune, l *Lexer) bool {
|
|
if r != 'x' {
|
|
return false
|
|
}
|
|
times := 2
|
|
return times == l.AcceptRunTimes(isHex, times)
|
|
}
|
|
|
|
// HEX ::= [0-9] | [A-F] | [a-f]
|
|
func isHex(r rune) bool {
|
|
switch {
|
|
case r >= '0' && r <= '9':
|
|
case r >= 'a' && r <= 'f':
|
|
case r >= 'A' && r <= 'F':
|
|
default:
|
|
return false
|
|
}
|
|
return true
|
|
}
|