diff --git a/pmd-awl/src/main/antlr4/net/sourceforge/pmd/lang/awl/ast/AWLLexer.g4 b/pmd-awl/src/main/antlr4/net/sourceforge/pmd/lang/awl/ast/AWLLexer.g4 index b2e2bdbcac4..c3e6bb0ed4e 100644 --- a/pmd-awl/src/main/antlr4/net/sourceforge/pmd/lang/awl/ast/AWLLexer.g4 +++ b/pmd-awl/src/main/antlr4/net/sourceforge/pmd/lang/awl/ast/AWLLexer.g4 @@ -7,7 +7,13 @@ INSTRUCTIONNAME : '<=' | '+AR1' | '+AR2' | '+D' | '-D' | '*D' | '/D' | '==D' | ' LOGICCOMPARISON : '==0' | '<>0' | '>0' | '<0' | '>=0' | '<=0' ; -TITLE : 'TITLE' [ \t]* '=' ~[\r\n]* ; +TITLE : 'TITLE' Whitespace? '=' ~[\r\n]* LineTerm? ; +FUNCTION_BLOCK : ID Whitespace StringConstant (Whitespace? ':' Whitespace? ID)? LineTerm? ; +fragment BRACED_BLOCK: '{' ~[\r\n]+ '}' LineTerm? ; +FAMILY_FIELD: 'FAMILY' Whitespace? ':' Whitespace? (REAL | INT | StringConstant | ID)+ LineTerm? ; +VERSION_FIELD: 'VERSION' Whitespace? ':' Whitespace? (REAL | INT | StringConstant | ID)+ LineTerm? ; + +HEADER: FUNCTION_BLOCK TITLE BRACED_BLOCK* FAMILY_FIELD? VERSION_FIELD -> channel(HIDDEN) ; POINTER_OP : 'P#' 'DBX'? ; diff --git a/pmd-awl/src/test/java/net/sourceforge/pmd/lang/awl/cpd/AwlCpdLexerTest.java b/pmd-awl/src/test/java/net/sourceforge/pmd/lang/awl/cpd/AwlCpdLexerTest.java index e87b289dc3b..1a80f4d06a2 100644 --- a/pmd-awl/src/test/java/net/sourceforge/pmd/lang/awl/cpd/AwlCpdLexerTest.java +++ b/pmd-awl/src/test/java/net/sourceforge/pmd/lang/awl/cpd/AwlCpdLexerTest.java @@ -19,4 +19,9 @@ void examples() { doTest("awl_examples"); } + @Test + void headers() { + doTest("headers"); + } + } diff --git a/pmd-awl/src/test/resources/net/sourceforge/pmd/lang/awl/cpd/testdata/awl_examples.txt b/pmd-awl/src/test/resources/net/sourceforge/pmd/lang/awl/cpd/testdata/awl_examples.txt index c50f53d7e94..e46cc78cf00 100644 --- a/pmd-awl/src/test/resources/net/sourceforge/pmd/lang/awl/cpd/testdata/awl_examples.txt +++ b/pmd-awl/src/test/resources/net/sourceforge/pmd/lang/awl/cpd/testdata/awl_examples.txt @@ -1,23 +1,4 @@ [Image] or [Truncated image[ Bcol Ecol -L5 - [FUNCTION_BLOCK] 1 15 - ["fb1"] 16 21 -L6 - [TITLE = %version: 1 % Title inform[ 1 64 -L7 - [{] 1 2 - [this_is_false] 3 16 - [:=] 17 19 - ['FALSE'] 20 27 - [}] 28 29 -L8 - [FAMILY] 1 7 - [:] 8 9 - [Fam1] 10 14 -L9 - [VERSION] 1 8 - [:] 9 10 - [0.0] 11 14 L12 [VAR_INPUT] 4 13 L13 diff --git a/pmd-awl/src/test/resources/net/sourceforge/pmd/lang/awl/cpd/testdata/headers.awl b/pmd-awl/src/test/resources/net/sourceforge/pmd/lang/awl/cpd/testdata/headers.awl new file mode 100644 index 00000000000..cc505f558df --- /dev/null +++ b/pmd-awl/src/test/resources/net/sourceforge/pmd/lang/awl/cpd/testdata/headers.awl @@ -0,0 +1,31 @@ +FUNCTION_BLOCK "fb1" +TITLE = %version: 1 % Title information is present here % $ ^ \ +{ this_is_false := 'FALSE' } +FAMILY : Fam1 +VERSION : 0.0 + +FUNCTION_BLOCK "fb2" : Void +TITLE = %version: 2 % Title information is present here % $ ^ \ +{ this_is_false := 'TRUE' } +FAMILY : Fam2 +VERSION : 0.2 + + +NETWORK +TITLE = GC: Start transfers SWS07/TRS08 + NOP 0; + +NETWORK +TITLE = HA: Transfer data from TRS03 to TRS01 + NOP 0; + +FUNCTION "F1" : Void +TITLE = %version: 42% %Commit: badbed1% +{ this_is_false_again := 'FALSE' } +FAMILY : Brouwers +VERSION : 0.2 + +ORGANIZATION_BLOCK "YOU_ARE_BLOCKED" +TITLE = The Memoirs of an Organization Block +{ this_is_false_is_false := 'TRUE' } +VERSION : 9000.1 diff --git a/pmd-awl/src/test/resources/net/sourceforge/pmd/lang/awl/cpd/testdata/headers.txt b/pmd-awl/src/test/resources/net/sourceforge/pmd/lang/awl/cpd/testdata/headers.txt new file mode 100644 index 00000000000..68ed66d2791 --- /dev/null +++ b/pmd-awl/src/test/resources/net/sourceforge/pmd/lang/awl/cpd/testdata/headers.txt @@ -0,0 +1,18 @@ + [Image] or [Truncated image[ Bcol Ecol +L14 + [NETWORK] 1 8 +L15 + [TITLE = GC: Start transfers SWS07/[ 1 41 +L16 + [NOP] 7 10 + [0] 11 12 + [;] 12 13 +L18 + [NETWORK] 1 8 +L19 + [TITLE = HA: Transfer data from TRS[ 1 47 +L20 + [NOP] 7 10 + [0] 11 12 + [;] 12 13 +EOF