Skip to content

Instantly share code, notes, and snippets.

let dqlParser2 = peg("top_level", stack: ParseStack):
top_level <- goal * end_marker
S <- *Space
end_marker <- "."
goal <- S * predicate * S * *( separator * S * goal) * *(unary_op)
unary_op <- S * "|>" * S * "UN" * S
separator <- ","
predicate <- named_predicate | selection_stuff | group
selection_stuff <- "SEL"
group <- "GROUP"
@@grammar::dql
############### top markers used by the parser for different contexts
start_query
=
@:top_goal end_marker $
;
start_consult
WITH RECURSIVE
xaxis(x) AS (VALUES(-2.0) UNION ALL SELECT x+0.05 FROM xaxis WHERE x<1.2),
yaxis(y) AS (VALUES(-1.0) UNION ALL SELECT y+0.1 FROM yaxis WHERE y<1.0),
m(iter, cx, cy, x, y) AS (
SELECT 0, x, y, 0.0, 0.0 FROM xaxis, yaxis
UNION ALL
SELECT iter+1, cx, cy, x*x-y*y + cx, 2.0*x*y + cy FROM m
WHERE (x*x + y*y) < 4.0 AND iter<28
),
m2(iter, cx, cy) AS (
male(terah).
male(abraham).
male(nahor).
male(haran).
male(isaac).
male(ismael).
male(jacob).
female(sarah).
female(hagar).
curl -L http://tinyurl.com/DanielVim

Keybase proof

I hereby claim:

  • I am reverendpaco on github.
  • I am reverend_paco (https://keybase.io/reverend_paco) on keybase.
  • I have a public key ASB5p5DKzM53ePcNbBUtjDq-xieXECxljY75e_Dy_z6OTQo

To claim this, I am signing this object:

import math
def vpcnum(n):
Y,X = math.modf( (n-1)/float(16) )
x = "10.{0}.{1}.0".format(int(X),int(Y*256))
return x
def client(n):
clientNum = (n*2 + 16)
return (vpcnum(clientNum-1),vpcnum(clientNum))
queryNode source node = bool
where (bool,_) = queryNodeWithPath source node []
queryNodeWithPath :: (Ord a) => [a] -> TrieNode a -> [[a]] -> (Bool,[[a]])
queryNodeWithPath source@(s:_) node@TrieNode{ nodeType = Top, children=ch} acc
| Map.member s ch = queryNodeWithPath source (ch ! s) acc
| otherwise = (False,acc)
queryNodeWithPath source node@TrieNode{ wordFragment = target, nodeType=nT, children=ch } acc = case matchData of
ExactMatchDatum {shared=source}
| nT == Word -> (True, (target:acc))
-- this will be the complicated case
insertNode contextNode@TrieNode{children=childNodes,nodeType=oldNodeType}
SharedPrefixDatum { shared = sharedPrefix ,
suffixS = sourceSuffix@(s:ss),
suffixT = targetSuffix@(t:ts)}
= newForkNode {children = ourTwoNewNodes }
where newForkNode = nonWordNode sharedPrefix
ourTwoNewNodes = Map.fromList [(s,newSourceSuffixNode),(t,newTargetSuffixNode) ]
newSourceSuffixNode = wordNode sourceSuffix
newTargetSuffixNode = contextNode{ wordFragment = targetSuffix}
-- the following is for trie nodes where the source is smaller
insertNode contextNode@TrieNode{children=childNodes,nodeType=oldNodeType}
SourceIsSmallerDatum {pre=source,
suffixT= suffixStringOfTarget}
= contextNode{ wordFragment = source,
nodeType = Word,
children= slidNode *-> childNodes }
where slidNode = contextNode{wordFragment=suffixStringOfTarget,nodeType=oldNodeType}