Skip to content

Commit

Permalink
Changed AT keyword to IN
Browse files Browse the repository at this point in the history
  • Loading branch information
apr94 committed Jul 20, 2017
1 parent 721cf7d commit b60eced
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion bql/grammar/grammar.go
Expand Up @@ -105,7 +105,7 @@ func BQL() *Grammar {
Elements: []Element{
NewTokenType(lexer.ItemDeconstruct),
NewSymbol("DECONSTRUCT_FACTS"),
NewTokenType(lexer.ItemAt),
NewTokenType(lexer.ItemIn),
NewSymbol("OUTPUT_GRAPHS"),
NewTokenType(lexer.ItemFrom),
NewSymbol("INPUT_GRAPHS"),
Expand Down
24 changes: 12 additions & 12 deletions bql/grammar/grammar_test.go
Expand Up @@ -146,13 +146,13 @@ func TestAcceptByParse(t *testing.T) {
?s "old_predicate_2"@[,] ?o2.
?s "old_predicate_3"@[,] ?o3};`,
// Test Deconstruct clause.
`deconstruct {?s "new_predicate"@[] ?o} at ?a from ?b where {?s "old_predicate"@[,] ?o} having ?s = ?o;`,
`deconstruct {?s "new_predicate"@[] ?o} at ?a from ?b where {?s "old_predicate"@[,] ?o};`,
`deconstruct {?s "new_predicate"@[] ?o} in ?a from ?b where {?s "old_predicate"@[,] ?o} having ?s = ?o;`,
`deconstruct {?s "new_predicate"@[] ?o} in ?a from ?b where {?s "old_predicate"@[,] ?o};`,
`deconstruct {?s ?p ?o.
_:v "_subject"@[] ?s.
_:v "_predicate"@[] ?p.
_:v "_object"@[] ?o}
at ?a, ?b
in ?a, ?b
from ?c, ?d
where {?n "_subject"@[] ?s.
?n "_predicate"@[] ?p.
Expand Down Expand Up @@ -275,25 +275,25 @@ func TestRejectByParse(t *testing.T) {
where {?s "old_predicate_1"@[,] ?o1.
?s "old_predicate_2"@[,] ?o2};`,
// Deconstruct clause without source.
`deconstruct {?s "foo"@[,] ?o} at ?a where{?s "foo"@[,] ?o} having ?s = ?o;`,
`deconstruct {?s "foo"@[,] ?o} in ?a where{?s "foo"@[,] ?o} having ?s = ?o;`,
// Deconstruct clause without destination.
`deconstruct {?s "foo"@[,] ?o} from ?b where{?s "foo"@[,] ?o} having ?s = ?o;`,
// Deconstruct clause with badly formed blank node.
`deconstruct {?s ?p ?o.
_v "some_pred"@[] ?k}
at ?a
in ?a
from ?b
where {?s "foo"@[,] ?o};`,
// Deconstruct clause with badly formed triple.
`deconstruct {?s ?p ?o.
_:v "some_pred"@[]}
at ?a
in ?a
from ?b
where {?s "foo"@[,] ?o};`,
// Deconstruct clause with multiple predicate-object pairs.
`deconstruct {?s "predicate_1"@[] ?o1;
"predicate_1"@[] ?o1}
at ?a
in ?a
from ?b
where {?s "old_predicate_1"@[,] ?o1.
?s "old_predicate_2"@[,] ?o2};`,
Expand Down Expand Up @@ -365,15 +365,15 @@ func TestAcceptGraphOpsByParseAndSemantic(t *testing.T) {

// Deconstruct data. Graphs can be input or output graphs.
{`deconstruct {?s "predicate_1"@[] ?o1}
at ?a
in ?a
from ?b
where {?s "old_predicate_1"@[,] ?o1.
?s "old_predicate_2"@[,] ?o2.
?s "old_predicate_3"@[,] ?o3};`, empty, []string{"?b"}, []string{"?a"}, 0},

// Deconstruct data at multiple output graphs from multple input graphs.
{`deconstruct {?s "predicate_1"@[] ?o1}
at ?a, ?b
in ?a, ?b
from ?c, ?d
where {?s "old_predicate_1"@[,] ?o1.
?s "old_predicate_2"@[,] ?o2.
Expand Down Expand Up @@ -540,7 +540,7 @@ func TestSemanticStatementConstructDeconstructClausesLengthCorrectness(t *testin
},
{
query: `deconstruct {?s "predicate_1"@[] ?o1}
at ?a
in ?a
from ?b
where {?s "old_predicate_1"@[,] ?o1.
?s "old_predicate_2"@[,] ?o2.
Expand All @@ -550,7 +550,7 @@ func TestSemanticStatementConstructDeconstructClausesLengthCorrectness(t *testin
{
query: `deconstruct {?s "predicate_1"@[] ?o1.
?s "predicate_3"@[] ?o3}
at ?a
in ?a
from ?b
where {?s "old_predicate_1"@[,] ?o1.
?s "old_predicate_2"@[,] ?o2.
Expand Down Expand Up @@ -651,7 +651,7 @@ func TestSemanticStatementPredicateObjectPairsLengthCorrectness(t *testing.T) {
{
query: `deconstruct {?s "predicate_1"@[] ?o1.
?s1 "predicate_1"@[] ?o1}
at ?a
in ?a
from ?b
where {?s "old_predicate_1"@[,] ?o1.
?s "old_predicate_2"@[,] ?o2.
Expand Down
9 changes: 9 additions & 0 deletions bql/lexer/lexer.go
Expand Up @@ -65,6 +65,8 @@ const (
ItemID
// ItemAt represents at keyword in BQL.
ItemAt
// ItemIn represents in keyword in BQL.
ItemIn
// ItemBefore represents the before keyword in BQL.
ItemBefore
// ItemAfter represents the after keyword in BQL.
Expand Down Expand Up @@ -231,6 +233,8 @@ func (tt TokenType) String() string {
return "TYPE"
case ItemAt:
return "AT"
case ItemIn:
return "IN"
case ItemDistinct:
return "DISTINCT"
default:
Expand Down Expand Up @@ -293,6 +297,7 @@ const (
id = "id"
typeKeyword = "type"
atKeyword = "at"
inKeyword = "in"
anchor = "\"@["
literalType = "\"^^type:"
literalBool = "bool"
Expand Down Expand Up @@ -588,6 +593,10 @@ func lexKeyword(l *lexer) stateFn {
consumeKeyword(l, ItemAt)
return lexSpace
}
if strings.EqualFold(input, inKeyword) {
consumeKeyword(l, ItemIn)
return lexSpace
}
for {
r := l.next()
if unicode.IsSpace(r) || r == eof {
Expand Down
6 changes: 3 additions & 3 deletions bql/planner/planner_test.go
Expand Up @@ -753,7 +753,7 @@ func TestPlannerDeconstructRemovesCorrectTriples(t *testing.T) {
}{
{
s: `deconstruct {?p1 "met"@[] ?p2}
at ?dest
in ?dest
from ?src
where {?p1 "lives_in"@[] /city<A>.
?p2 "lives_in"@[] /city<B>};`,
Expand All @@ -765,7 +765,7 @@ func TestPlannerDeconstructRemovesCorrectTriples(t *testing.T) {
{
s: `deconstruct {?p1 "met"@[] ?p2.
?p2 "met"@[] ?p1}
at ?dest
in ?dest
from ?src
where {?p1 "lives_in"@[] /city<A>.
?p2 "lives_in"@[] /city<B>};`,
Expand Down Expand Up @@ -822,7 +822,7 @@ func TestPlannerDeconstructRemovesCorrectTriples(t *testing.T) {
}
dt[trp.String()] = true
} else {
t.Errorf("unexpected triple: %v added to graph", t)
t.Errorf("unexpected triple: %v added to graph", trp)
}
}
if i != len(entry.trps) {
Expand Down

0 comments on commit b60eced

Please sign in to comment.