Skip to content

Commit d33983b

Browse files
authored
Merge pull request #1219 from ProdOrDev/feat/NO-ISSUE/more-identifier-characters
feat: support underscores and forward slashes in identifiers
2 parents 4cd5087 + efe6fbe commit d33983b

File tree

4 files changed

+89
-1
lines changed

4 files changed

+89
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1111

1212
- Improved performance in various scenarios like autocrafting and opening a Grid.
1313
- Fixed autocrafter name field history not working
14+
- Added support for underscores and forward slashes in search names.
1415

1516
## [2.0.0] - 2025-09-27
1617

refinedstorage-query-parser/src/main/java/com/refinedmods/refinedstorage/query/lexer/Lexer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void scan() {
4646
}
4747

4848
private boolean isValidIdentifier(final char c) {
49-
return Character.isLetterOrDigit(c);
49+
return c == '_' || c == '/' || Character.isLetterOrDigit(c);
5050
}
5151

5252
private void scanNumber() {

refinedstorage-query-parser/src/test/java/com/refinedmods/refinedstorage/query/lexer/LexerTest.java

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,83 @@ void testMultipleIdentifiers() {
6868
assertPosition(baz.position(), SOURCE_NAME, 1, 14, 1, 16);
6969
}
7070

71+
@Test
72+
void testUnderscoreInIdentifier() {
73+
// Act
74+
final List<Token> tokens = getTokens("foo_bar");
75+
76+
// Assert
77+
assertThat(tokens).hasSize(1);
78+
79+
final Token token = tokens.getFirst();
80+
assertToken(token, "foo_bar", TokenType.IDENTIFIER);
81+
assertPosition(token.position(), SOURCE_NAME, 1, 1, 1, 7);
82+
}
83+
84+
@Test
85+
void testSlashInIdentifier() {
86+
// Act
87+
final List<Token> tokens = getTokens("foo/bar");
88+
89+
// Assert
90+
assertThat(tokens).hasSize(1);
91+
92+
final Token token = tokens.getFirst();
93+
assertToken(token, "foo/bar", TokenType.IDENTIFIER);
94+
assertPosition(token.position(), SOURCE_NAME, 1, 1, 1, 7);
95+
}
96+
97+
@Test
98+
void testUnderscoreAndSlashInIdentifier() {
99+
// Act
100+
final List<Token> tokens = getTokens("foo/bar_baz");
101+
102+
// Assert
103+
assertThat(tokens).hasSize(1);
104+
105+
final Token token = tokens.getFirst();
106+
assertToken(token, "foo/bar_baz", TokenType.IDENTIFIER);
107+
assertPosition(token.position(), SOURCE_NAME, 1, 1, 1, 11);
108+
}
109+
110+
@Test
111+
void testMultipleUnderscoreAndSlashInIdentifier() {
112+
// Act
113+
final List<Token> tokens = getTokens("foo_bar/ba__z/quux_1/e2//d");
114+
115+
// Assert
116+
assertThat(tokens).hasSize(1);
117+
118+
final Token token = tokens.getFirst();
119+
assertToken(token, "foo_bar/ba__z/quux_1/e2//d", TokenType.IDENTIFIER);
120+
assertPosition(token.position(), SOURCE_NAME, 1, 1, 1, 26);
121+
}
122+
123+
@Test
124+
void testSlashOperatorWithSlashInIdentifier() {
125+
// Act
126+
final List<Token> tokens = getTokens("/ foo/ /bar");
127+
128+
// Assert
129+
assertThat(tokens).hasSize(4);
130+
131+
final Token slash = tokens.getFirst();
132+
assertToken(slash, "/", TokenType.BIN_OP);
133+
assertPosition(slash.position(), SOURCE_NAME, 1, 1, 1, 1);
134+
135+
final Token foo = tokens.get(1);
136+
assertToken(foo, "foo/", TokenType.IDENTIFIER);
137+
assertPosition(foo.position(), SOURCE_NAME, 1, 3, 1, 6);
138+
139+
final Token slash2 = tokens.get(2);
140+
assertToken(slash2, "/", TokenType.BIN_OP);
141+
assertPosition(slash2.position(), SOURCE_NAME, 1, 8, 1, 8);
142+
143+
final Token bar = tokens.get(3);
144+
assertToken(bar, "bar", TokenType.IDENTIFIER);
145+
assertPosition(bar.position(), SOURCE_NAME, 1, 9, 1, 11);
146+
}
147+
71148
@Test
72149
void testSingleStringIdentifier() {
73150
// Act

refinedstorage-query-parser/src/test/java/com/refinedmods/refinedstorage/query/lexer/SyntaxHighlighterTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ private static Stream<Arguments> provideInput() {
4646
new SyntaxHighlightedCharacter("o", "WHITE")
4747
)
4848
),
49+
Arguments.of(
50+
"a_b/c",
51+
Arrays.asList(
52+
new SyntaxHighlightedCharacter("a", "WHITE"),
53+
new SyntaxHighlightedCharacter("_", "WHITE"),
54+
new SyntaxHighlightedCharacter("b", "WHITE"),
55+
new SyntaxHighlightedCharacter("/", "WHITE"),
56+
new SyntaxHighlightedCharacter("c", "WHITE")
57+
)
58+
),
4959
Arguments.of(
5060
"!not&&",
5161
Arrays.asList(

0 commit comments

Comments
 (0)