Commit 9b04bcc
committed
Fix: Reject list syntax before || operator and support | | spacing
Addresses feedback from @bakaq about [a,b,c]||S being incorrectly accepted
and support for spaced "| |" syntax per spec.
Issue 1: List syntax like [a,b,c] was incorrectly accepted
---------------------------------------------------------
The issue was that in chars mode, reduce_list() converts lists like [a,b,c]
to CompleteString terms, making them indistinguishable from actual string
literals "abc" by the time the || validation runs.
Solution: Introduce LIST_TERM spec constant to mark terms originating from
list syntax ([...]), distinct from string literals ("..."). The || operator
now correctly rejects list syntax while accepting only double-quoted strings.
Issue 2: Spaced "| |" syntax not supported
-------------------------------------------
The spec explicitly shows "a"| |"b"| |"c" as valid syntax with spaces
between the bars. Modified HeadTailSeparator handling to peek ahead and
detect two consecutive | tokens, treating them as DoubleBar.
Comments are supported in all positions per spec:
- Before bars: "a" /* comment */ || "b"
- After bars: "a" || /* comment */ "b"
- Between bars: "a" | /* comment */ | "b"
- Multiple positions: "a" /* c1 */ | /* c2 */ | /* c3 */ "b"
- Line comments: "a" | % comment
| "b"
Changes:
- src/parser/ast.rs: Add LIST_TERM = 0x5000 constant
- src/parser/parser.rs:
* Set LIST_TERM spec in reduce_list()
* Check LIST_TERM in || validation to reject list syntax
* Detect | | token pair and handle as DoubleBar
- src/tests/double_bar.pl:
* Document [a,b,c]||S as invalid case
* Add tests for spaced "| |" syntax
* Add comprehensive tests for comments in all positions
Tested:
✅ [a,b,c]||S correctly rejected
✅ [1,2,3]||K correctly rejected
✅ [_]||Rs correctly rejected
✅ "abc"||K works correctly
✅ "abc" | | K works correctly (spaced syntax)
✅ "a" | | "b" | | "c" works correctly
✅ Comments before, after, and between bars work correctly
✅ All 21 integration tests pass
✅ All cargo tests pass (no regressions)1 parent af38843 commit 9b04bcc
3 files changed
+119
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| 144 | + | |
144 | 145 | | |
145 | 146 | | |
146 | 147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
757 | 757 | | |
758 | 758 | | |
759 | 759 | | |
760 | | - | |
| 760 | + | |
761 | 761 | | |
762 | 762 | | |
763 | 763 | | |
| |||
1044 | 1044 | | |
1045 | 1045 | | |
1046 | 1046 | | |
1047 | | - | |
1048 | | - | |
1049 | | - | |
1050 | | - | |
1051 | | - | |
1052 | | - | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
1053 | 1068 | | |
1054 | | - | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
1055 | 1078 | | |
1056 | | - | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
1057 | 1085 | | |
1058 | | - | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
1059 | 1096 | | |
1060 | | - | |
1061 | | - | |
1062 | | - | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
1063 | 1102 | | |
1064 | | - | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
1065 | 1109 | | |
1066 | 1110 | | |
1067 | 1111 | | |
1068 | 1112 | | |
1069 | 1113 | | |
1070 | | - | |
| 1114 | + | |
1071 | 1115 | | |
1072 | 1116 | | |
1073 | 1117 | | |
| |||
1076 | 1120 | | |
1077 | 1121 | | |
1078 | 1122 | | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
1079 | 1130 | | |
1080 | 1131 | | |
1081 | 1132 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
67 | 118 | | |
68 | 119 | | |
69 | 120 | | |
70 | 121 | | |
71 | 122 | | |
72 | 123 | | |
73 | 124 | | |
| 125 | + | |
74 | 126 | | |
75 | 127 | | |
0 commit comments