Fixing pr11100
original commit: 339681018aa1257bf487f274bdcfdb535a5e33b7
This commit is contained in:
parent
5e021c9a87
380eb82c43
dfb1da8e37
5c82f510da
a5c2d46d36
f514febf9d
f43cb23c83
93a28ed14e
a89d757639
0a86976eb1
commit
371cc2a620
|
@ -46,6 +46,7 @@
|
|||
(literal [(predicate-sym LPAREN RPAREN) (make-literal (make-srcloc $1-start-pos $3-end-pos) $1 empty)]
|
||||
[(predicate-sym LPAREN terms RPAREN) (make-literal (make-srcloc $1-start-pos $4-end-pos) $1 $3)]
|
||||
[(predicate-sym) (make-literal (make-srcloc $1-start-pos $1-end-pos) $1 empty)]
|
||||
[(term NEQUAL term) (make-literal (make-srcloc $1-start-pos $3-end-pos) '!= (list $1 $3))]
|
||||
[(term EQUAL term) (make-literal (make-srcloc $1-start-pos $3-end-pos) '= (list $1 $3))])
|
||||
(predicate-sym [(IDENTIFIER) (string->symbol $1)]
|
||||
[(STRING) $1])
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
(prefix-in : parser-tools/lex-sre))
|
||||
|
||||
(define-tokens dtokens (VARIABLE IDENTIFIER STRING))
|
||||
(define-empty-tokens dpunct (LPAREN COMMA RPAREN TSTILE DOT EQUAL TILDE QMARK EOF))
|
||||
(define-empty-tokens dpunct (LPAREN COMMA RPAREN TSTILE DOT EQUAL NEQUAL TILDE QMARK EOF))
|
||||
(define-lex-abbrev line-break #\newline)
|
||||
(define-lex-abbrev id-chars (char-complement (char-set "(,)=:.~?\"% \n")))
|
||||
(define-lex-abbrev variable-re (:: upper-case (:* (:or upper-case lower-case (char-set "0123456789_")))))
|
||||
|
@ -38,6 +38,7 @@
|
|||
[#\~ (token-TILDE)]
|
||||
[#\? (token-QMARK)]
|
||||
[#\= (token-EQUAL)]
|
||||
["!=" (token-NEQUAL)]
|
||||
[(eof) (token-EOF)]))
|
||||
|
||||
(provide dtokens dpunct
|
||||
|
|
|
@ -128,6 +128,14 @@
|
|||
[(unify-term (empty-env) a b)
|
||||
=> (lambda (env) (equal-test (subst-term env a) (subst-term env b)))]
|
||||
[else (equal-test a b)])]
|
||||
[(struct literal (srcloc '!= (list a b)))
|
||||
(define (equal-test a b)
|
||||
(unless (term-equal? a b)
|
||||
(fact! sg (make-literal srcloc '!= (list a b)))))
|
||||
(cond
|
||||
[(unify-term (empty-env) a b)
|
||||
=> (lambda (env) (equal-test (subst-term env a) (subst-term env b)))]
|
||||
[else (equal-test a b)])]
|
||||
[_
|
||||
(search-theory! sg)]))
|
||||
(define sg (make-subgoal q empty empty))
|
||||
|
|
|
@ -43,7 +43,7 @@ included in a string. The remaining characters may be specified using escape cha
|
|||
|
||||
A literal, is a predicate symbol followed by an optional parenthesized list of comma separated terms. A predicate symbol is either an identifier
|
||||
or a string. A term is either a variable or a constant. As with predicate symbols, a constant is either an identifier or a string. As a special case,
|
||||
two terms separated by @litchar["="] is a literal for the equality predicate.
|
||||
two terms separated by @litchar["="] (@litchar["!="]) is a literal for the equality (inequality) predicate.
|
||||
The following are literals:
|
||||
@verbatim[#:indent 4 #<<END
|
||||
parent(john, douglas)
|
||||
|
@ -96,7 +96,8 @@ The following BNF describes the syntax of Datalog.
|
|||
(BNF-seq (nonterm "predicate-sym") (litchar "(") (litchar ")"))
|
||||
(BNF-seq (nonterm "predicate-sym") (litchar "(") (nonterm "terms") (litchar ")"))
|
||||
(nonterm "predicate-sym")
|
||||
(BNF-seq (nonterm "term") (litchar "=") (nonterm "term")))
|
||||
(BNF-seq (nonterm "term") (litchar "=") (nonterm "term"))
|
||||
(BNF-seq (nonterm "term") (litchar "!=") (nonterm "term")))
|
||||
(list (nonterm "predicate-sym")
|
||||
(nonterm "IDENTIFIER")
|
||||
(nonterm "STRING"))
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
[identifier-re
|
||||
(syn-val lexeme 'identifier #f start-pos end-pos)]
|
||||
[(:or #\) #\() (syn-val lexeme 'parenthesis #f start-pos end-pos)]
|
||||
[(:or #\= #\? #\~ #\. #\, ":-") (syn-val lexeme 'parenthesis #f start-pos end-pos)]
|
||||
[(:or "!=" #\= #\? #\~ #\. #\, ":-") (syn-val lexeme 'parenthesis #f start-pos end-pos)]
|
||||
[(eof) (syn-val lexeme 'eof #f start-pos end-pos)]
|
||||
[#\" ((colorize-string start-pos) input-port)]
|
||||
[any-char (syn-val lexeme 'error #f start-pos end-pos)]))
|
8
collects/tests/datalog/examples/sym.rkt
Normal file
8
collects/tests/datalog/examples/sym.rkt
Normal file
|
@ -0,0 +1,8 @@
|
|||
#lang datalog
|
||||
|
||||
sym(a).
|
||||
sym(b).
|
||||
sym(c).
|
||||
perm(X,Y) :- sym(X), sym(Y), X != Y.
|
||||
|
||||
perm(X,Y)?
|
11
collects/tests/datalog/paren-examples/sym.rkt
Normal file
11
collects/tests/datalog/paren-examples/sym.rkt
Normal file
|
@ -0,0 +1,11 @@
|
|||
#lang datalog/sexp
|
||||
|
||||
(! (sym a))
|
||||
(! (sym b))
|
||||
(! (sym c))
|
||||
(! (:- (perm X Y)
|
||||
(sym X)
|
||||
(sym Y)
|
||||
(!= X Y)))
|
||||
|
||||
(? (perm X Y))
|
8
collects/tests/datalog/paren-examples/sym.txt
Normal file
8
collects/tests/datalog/paren-examples/sym.txt
Normal file
|
@ -0,0 +1,8 @@
|
|||
perm(a, c).
|
||||
perm(a, b).
|
||||
perm(c, a).
|
||||
perm(b, a).
|
||||
perm(b, c).
|
||||
perm(c, b).
|
||||
|
||||
|
|
@ -21,6 +21,8 @@
|
|||
(make-literal #f 'parent (list (make-constant #f 'john) (make-constant #f 'douglas))))
|
||||
(test-literal-parse "1 = 2"
|
||||
(make-literal #f '= (list (make-constant #f '|1|) (make-constant #f '|2|))))
|
||||
(test-literal-parse "1 != 2"
|
||||
(make-literal #f '!= (list (make-constant #f '|1|) (make-constant #f '|2|))))
|
||||
(test-literal-parse "zero-arity-literal"
|
||||
(make-literal #f 'zero-arity-literal empty))
|
||||
(test-literal-parse "zero-arity-literal()"
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
"lex"
|
||||
|
||||
(test-lexer "=" 'EQUAL #f)
|
||||
(test-lexer "!=" 'NEQUAL #f)
|
||||
(test-lexer "?" 'QMARK #f)
|
||||
(test-lexer "~" 'TILDE #f)
|
||||
(test-lexer "." 'DOT #f)
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
(test-color "123var" 'identifier)
|
||||
(test-color "(" 'parenthesis)
|
||||
(test-color ")" 'parenthesis)
|
||||
(test-color "!=" 'parenthesis)
|
||||
(test-color "=" 'parenthesis)
|
||||
(test-color "?" 'parenthesis)
|
||||
(test-color "~" 'parenthesis)
|
||||
|
|
Loading…
Reference in New Issue
Block a user