Skip to content

Commit baaa137

Browse files
authored
Merge pull request #339 from 1c-syntax/develop
v0.28.0
2 parents 10bb4a6 + a058158 commit baaa137

File tree

4 files changed

+135
-5
lines changed

4 files changed

+135
-5
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ plugins {
1515
id("com.github.ben-manes.versions") version "0.53.0"
1616
id("ru.vyarus.pom") version "3.0.0"
1717
id("org.jreleaser") version "1.21.0"
18-
id("org.sonarqube") version "7.1.0.6387"
18+
id("org.sonarqube") version "7.2.0.6526"
1919
id("me.champeau.gradle.jmh") version "0.5.3"
2020
}
2121

src/main/antlr/BSLParser.g4

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,12 @@ annotationParams
138138
RPAREN
139139
;
140140
annotationParam
141-
: (annotationParamName (ASSIGN constValue)?)
142-
| constValue
141+
: (annotationParamName (ASSIGN annotationParamValue)?)
142+
| annotationParamValue
143+
;
144+
annotationParamValue
145+
: constValue
146+
| annotation
143147
;
144148

145149
// vars

src/test/java/com/github/_1c_syntax/bsl/parser/BSLParserMatchesTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,10 @@ void testExecute(String inputString) {
265265
"Перем ИмяПерем1 Экспорт, ИмяПерем2 Экспорт",
266266
"&Аннотация\nПерем ИмяПерем",
267267
"&Аннотация\n&ВтораяАннотация\nПерем ИмяПерем",
268-
"&Аннотация\n#Область ИмяОбласти\n&ВтораяАннотация\nПерем ИмяПерем"
268+
"&Аннотация\n#Область ИмяОбласти\n&ВтораяАннотация\nПерем ИмяПерем",
269+
"&ДляКаждого(Значение = &Тип(\"Строка\"))\nПерем Параметр",
270+
"&ДляКаждого(&Тип(\"Число\", &Длина(10)))\nПерем Параметр",
271+
"&ДляКаждого(Значение = &Тип(\"Строка\"), &Тип(\"Число\", &Длина(10)))\nПерем Параметр"
269272
}
270273
)
271274
void moduleVar(String inputString) {
@@ -280,7 +283,11 @@ void moduleVar(String inputString) {
280283
"&Аннотация(Истина, Ложь)",
281284
"&Аннотация(П = 0, П2, Истина, \"строка\", П3)",
282285
"&Аннотация\n#Область ИмяОбласти\n&ВтораяАннотация\nПерем ИмяПерем",
283-
"&Перед", "&Перед(Парам1 = 1)", "&После", "&После(\"РегламентноеЗадание1\")", "&Вместо", "&ИзменениеИКонтроль"
286+
"&Перед", "&Перед(Парам1 = 1)", "&После", "&После(\"РегламентноеЗадание1\")", "&Вместо", "&ИзменениеИКонтроль",
287+
"&Тип(&Строка)", "&Тип(&Строка())",
288+
"&ДляКаждого(Значение = &Тип(\"Строка\"))",
289+
"&ДляКаждого(&Тип(\"Число\", &Длина(10)))",
290+
"&ДляКаждого(Значение = &Тип(\"Строка\"), &Тип(\"Число\", &Длина(10)))"
284291
}
285292
)
286293
void testAnnotation(String inputString) {

src/test/java/com/github/_1c_syntax/bsl/parser/BSLParserWithChildrenTest.java

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,125 @@ void testAnnotateParams() {
296296
assertThat(annotation2.annotationParams().annotationParam()).isNotNull().hasSize(3);
297297
}
298298

299+
@Test
300+
void testNestedAnnotations() {
301+
var content = testParser.assertThat("""
302+
&ДляКаждого(
303+
Значение = &Тип("Строка"),
304+
&Тип("Число", &Длина(10))
305+
)
306+
Перем Параметр;""");
307+
308+
var file = testParser.parser().file();
309+
content.matches(file);
310+
assertThat(file.moduleVars()).isNotNull();
311+
assertThat(file.moduleVars().moduleVar())
312+
.isNotNull()
313+
.hasSize(1);
314+
315+
var moduleVar = file.moduleVars().moduleVar(0);
316+
assertThat(moduleVar.annotation())
317+
.isNotNull()
318+
.hasSize(1);
319+
320+
var mainAnnotation = moduleVar.annotation().get(0);
321+
assertThat(mainAnnotation.annotationParams()).isNotNull();
322+
assertThat(mainAnnotation.annotationParams().annotationParam())
323+
.isNotNull()
324+
.hasSize(2);
325+
326+
// First param: Значение = &Тип("Строка")
327+
var param1 = mainAnnotation.annotationParams().annotationParam(0);
328+
assertThat(param1.annotationParamName()).isNotNull();
329+
assertThat(param1.annotationParamValue()).isNotNull();
330+
assertThat(param1.annotationParamValue().annotation()).isNotNull();
331+
332+
// Second param: &Тип("Число", &Длина(10))
333+
var param2 = mainAnnotation.annotationParams().annotationParam(1);
334+
assertThat(param2.annotationParamValue()).isNotNull();
335+
assertThat(param2.annotationParamValue().annotation()).isNotNull();
336+
var nestedAnnotation = param2.annotationParamValue().annotation();
337+
assertThat(nestedAnnotation.annotationParams()).isNotNull();
338+
assertThat(nestedAnnotation.annotationParams().annotationParam())
339+
.isNotNull()
340+
.hasSize(2);
341+
342+
// Check that the second param of the nested annotation is also an annotation
343+
var nestedParam2 = nestedAnnotation.annotationParams().annotationParam(1);
344+
assertThat(nestedParam2.annotationParamValue()).isNotNull();
345+
assertThat(nestedParam2.annotationParamValue().annotation()).isNotNull();
346+
}
347+
348+
@Test
349+
void testNestedAnnotationsInMethodDeclaration() {
350+
var content = testParser.assertThat("""
351+
&Аннотация(&Тип("Строка"))
352+
Процедура Метод()
353+
КонецПроцедуры""");
354+
355+
var file = testParser.parser().file();
356+
content.matches(file);
357+
assertThat(file.subs()).isNotNull();
358+
assertThat(file.subs().sub())
359+
.isNotNull()
360+
.hasSize(1);
361+
362+
var sub = file.subs().sub(0);
363+
var procDeclaration = sub.procedure().procDeclaration();
364+
assertThat(procDeclaration.annotation())
365+
.isNotNull()
366+
.hasSize(1);
367+
368+
var annotation = procDeclaration.annotation().get(0);
369+
assertThat(annotation.annotationParams()).isNotNull();
370+
assertThat(annotation.annotationParams().annotationParam())
371+
.isNotNull()
372+
.hasSize(1);
373+
374+
var param = annotation.annotationParams().annotationParam(0);
375+
assertThat(param.annotationParamValue()).isNotNull();
376+
assertThat(param.annotationParamValue().annotation()).isNotNull();
377+
}
378+
379+
@Test
380+
void testNestedAnnotationsInMethodParameter() {
381+
var content = testParser.assertThat("""
382+
Процедура Метод(
383+
&Тип(&Строка())
384+
Парам1
385+
)
386+
КонецПроцедуры""");
387+
388+
var file = testParser.parser().file();
389+
content.matches(file);
390+
assertThat(file.subs()).isNotNull();
391+
assertThat(file.subs().sub())
392+
.isNotNull()
393+
.hasSize(1);
394+
395+
var sub = file.subs().sub(0);
396+
var procDeclaration = sub.procedure().procDeclaration();
397+
assertThat(procDeclaration.paramList()).isNotNull();
398+
assertThat(procDeclaration.paramList().param())
399+
.isNotNull()
400+
.hasSize(1);
401+
402+
var param = procDeclaration.paramList().param(0);
403+
assertThat(param.annotation())
404+
.isNotNull()
405+
.hasSize(1);
406+
407+
var annotation = param.annotation().get(0);
408+
assertThat(annotation.annotationParams()).isNotNull();
409+
assertThat(annotation.annotationParams().annotationParam())
410+
.isNotNull()
411+
.hasSize(1);
412+
413+
var annotationParam = annotation.annotationParams().annotationParam(0);
414+
assertThat(annotationParam.annotationParamValue()).isNotNull();
415+
assertThat(annotationParam.annotationParamValue().annotation()).isNotNull();
416+
}
417+
299418
@Test
300419
void testRaise() {
301420
var content = testParser.assertThat("ВызватьИсключение (\"Документ не может быть проведен\", " +

0 commit comments

Comments
 (0)