Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove ebnf and disallow digits in dpath #116

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions dmap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const ebnf = require('ebnf')
const ethers = require('ethers')

const pack = require('./pack/dmap.json')
Expand All @@ -20,25 +19,6 @@ lib.address = dmap_address
lib.artifact = artifact

lib.FLAG_LOCK = 1
lib.grammar = `
dpath ::= (step)* EOF
step ::= (rune) (name)
name ::= [a-z0-9]+
rune ::= ":" | "."
`

lib.parser = new ebnf.Parser(ebnf.Grammars.W3C.getRules(lib.grammar))
lib.parse =s=> {
const ast = lib.parser.getAST(s)
return ast.children.map(step => {
const rune = step.children[0]
const name = step.children[1]
return {
locked: rune.text === ":",
name: name.text
}
})
}

lib.get = async (dmap, slot) => {
const nextslot = ethers.utils.hexZeroPad(
Expand Down Expand Up @@ -75,6 +55,14 @@ lib.slot = async (dmap, slot) => {
return res[0]
}

lib.parse = (path) => {
if (path === '') return []
const baned = path.match(/[^a-z.:]/)
const names = path.match(/[a-z]+/g)
const runes = path.match(/[:.]/g)
need(names.length === runes.length && baned === null, `Invalid dpath`)
return names.map((name, i) => ({locked: runes[i] === ':', name: name}))
}

lib.walk = async (dmap, path) => {
if ( path.length > 0 && ![':', '.'].includes(path.charAt(0))) path = ':' + path
Expand Down
Loading