forked from linkeddata/rdflib.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdumpParser.js
90 lines (77 loc) · 2.47 KB
/
dumpParser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* Parse a N3 store dump.
* This parses things like:
*
* <foo.ttl> log:metadata { ... }; log:sematics { ...} .
*
* (not necessarily in that order) as though it were the n3
*/
$rdf.DumpParser.prototype = new $rdf.N3Parser()
$rdf.DumpParser = function (store, openFormula, thisDoc, baseURI, genPrefix, metaURI, flags, why) {
$rdf.N3Parser.prototype.call(this, store, openFormula, thisDoc, baseURI, genPrefix, metaURI, flags, why)
this._context = null // Normally not allowed in base class init
}
$rdf.DumpParser.prototype.node = function (str, i, res, subjectAlready) {
if (typeof subjectAlready === 'undefined') {
subjectAlready = null
}
// var subj = subjectAlready // not used
var j = this.skipSpace(str, i)
if (j < 0) {
return j
}
i = j
var ch = pyjslib_slice(str, i, (i + 1))
if (ch !== '{' || !this.dumpTarget) {
return $rdf.N3Parser.prototype.node(str, i, res, subjectAlready)
} else {
var oldSource = this.source
this.source = this.dumpTarget
var result = $rdf.N3Parser.prototype.node.call(this, str, i, res, subjectAlready)
this.source = oldSource
return result
} // braces
}
$rdf.DumpParser.prototype.statement = function (str, i) {
var r = new pyjslib_List([])
var j = this.object(str, i, r)
if (j < 0) {
return j
}
this.dumpTarget = this._context ? null : r[0] // pass on to node() on outermost level only
j = this.property_list(str, i, r[0])
if (j < 0) {
throw BadSyntax(this._thisDoc, this.lines, str, i, 'expected propertylist')
}
return j
}
// @@@@@@@@@@ Move to the normal file
$rdf.n3parser.prototype.feedString = function (str) {
/*
Feed an string to the parser
if BadSyntax is raised, the string
passed in the exception object is the
remainder after any statements have been parsed.
So if there is more data to feed to the
parser, it should be straightforward to recover.*/
var i = 0
while ((i >= 0)) {
var j = this.skipSpace(str, i)
if (j < 0) {
return
}
i = this.directiveOrStatement(str, j)
if (i < 0) {
throw BadSyntax(this._thisDoc, this.lines, str, j, 'expected directive or statement')
}
}
}
$rdf.IndexedFormula.prototype.restoreFromBuffer = function (buf, baseURI, flags) {
var p = new $rdf.DumpParser(str, null, 'meta:', baseURI, flags)
p.feed(buf)
}
$rdf.IndexedFormula.prototype.restoreFromString = function (str, baseURI, flags) {
var p = new $rdf.DumpParser(str, null, 'meta:', baseURI, flags)
p.feedString(str)
}
// ends