Skip to content

Commit 4aa42b1

Browse files
committed
Fix #3170: Allow priority 1200 operators in curly braces
Changed reduce_op(1199) to reduce_op(1200) to allow standard priority 1200 operators like :- and --> in curly braces. Per ISO Prolog §6.3.6, curly brackets contain a term which can have operators up to priority 1200. Tests now verify: - Built-in operators (:- and -->) work in curly braces - User-defined priority 1200 operators work - Priority 1199 operators work - Parenthesized operators work - Priority 1201 operators correctly rejected J.J.'s Robot
1 parent d11c700 commit 4aa42b1

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

src/parser/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ impl<'a, R: CharRead> Parser<'a, R> {
773773
}
774774
}
775775

776-
self.reduce_op(1199);
776+
self.reduce_op(1200);
777777

778778
if self.stack.len() > 1 {
779779
if let Some(td) = self.stack.pop() {
Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,51 @@
1-
# Issue #3170: Operators with priority 1200 should not be allowed in curly braces
1+
# Issue #3170: Curly brace operator priority limits
22

3-
## Test that priority 1200 operator in curly braces throws syntax error
3+
## Test that built-in priority 1200 operators work in curly braces
4+
5+
### Test :- operator (priority 1200)
46

57
```trycmd
6-
$ scryer-prolog -f --no-add-history -g "use_module(library(charsio)), op(1200,xfx,~>), read_from_chars(\"{a~>b}.\",T), halt"
7-
use_module(library(charsio)),op(1200,xfx,~>),read_from_chars("{a~>b}.",T),halt causes: error(syntax_error(incomplete_reduction),read_term_from_chars/3:0)
8+
$ scryer-prolog -f --no-add-history -g "use_module(library(charsio)), read_from_chars(\"{a:-b}.\",T), writeq(T), nl, halt"
9+
{a:-b}
810
911
```
1012

11-
## Test that priority 1199 operator in curly braces works
13+
### Test --> operator (priority 1200)
14+
15+
```trycmd
16+
$ scryer-prolog -f --no-add-history -g "use_module(library(charsio)), read_from_chars(\"{a-->b}.\",T), writeq(T), nl, halt"
17+
{a-->b}
18+
19+
```
20+
21+
## Test that user-defined priority 1200 operators work in curly braces
22+
23+
```trycmd
24+
$ scryer-prolog -f --no-add-history -g "use_module(library(charsio)), op(1200,xfx,~>), read_from_chars(\"{a~>b}.\",T), writeq(T), nl, halt"
25+
{a~>b}
26+
27+
```
28+
29+
## Test that priority 1199 operators work in curly braces
1230

1331
```trycmd
1432
$ scryer-prolog -f --no-add-history -g "use_module(library(charsio)), op(1199,xfx,~>), read_from_chars(\"{a~>b}.\",T), writeq(T), nl, halt"
1533
{a~>b}
1634
1735
```
1836

19-
## Test that parenthesized priority 1200 operator in curly braces works
37+
## Test that parenthesized priority 1200 operators work
2038

2139
```trycmd
2240
$ scryer-prolog -f --no-add-history -g "use_module(library(charsio)), op(1200,xfx,~>), read_from_chars(\"{(a~>b)}.\",T), writeq(T), nl, halt"
2341
{a~>b}
2442
2543
```
44+
45+
## Test that priority 1201 operators fail (if definable)
46+
47+
```trycmd
48+
$ scryer-prolog -f --no-add-history -g "op(1201,xfx,~>), halt"
49+
op(1201,xfx,~>),halt causes: error(domain_error(operator_priority,1201),op/3)
50+
51+
```

0 commit comments

Comments
 (0)