Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: generic parsing interface and parsing of JavaPP annotations #134

Merged
merged 27 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
359a009
refactor: introduce AnnotationParser interface to allow for parser ex…
AlexanderSchultheiss Feb 19, 2024
c3cba81
refactor: move C preprocessor-related implementations to own package
AlexanderSchultheiss Feb 19, 2024
0fadf87
fix: specify the correct matcher group id
AlexanderSchultheiss Feb 19, 2024
bc7747b
todos: add todo about AnnotationType to NodeType conversion
AlexanderSchultheiss Feb 20, 2024
e853ff7
docs: short addendum to docstrings of AnnotationParser
AlexanderSchultheiss Feb 20, 2024
90d19d0
refactor: move initialization of NodeType based on AnnotationType to …
AlexanderSchultheiss Feb 20, 2024
92d66c1
tests: add first test definitions for JavaPP parsing
AlexanderSchultheiss Feb 20, 2024
2d98af2
feat: add initial ANTLR grammar for JPP
AlexanderSchultheiss Feb 20, 2024
def9aa7
refactor: change rule names of JPP grammar
AlexanderSchultheiss Feb 20, 2024
f200c7a
refactor: pull up interface of CPP diff line extraction and abstracti…
AlexanderSchultheiss Feb 20, 2024
5407946
refactor: reduce overhead of AnnotationParser implementations
AlexanderSchultheiss Feb 20, 2024
5262889
feat: add stubs for JPP expression abstraction
AlexanderSchultheiss Feb 20, 2024
a7a247d
refactor: prepare JPPParserTest for more test cases
AlexanderSchultheiss Feb 20, 2024
cbbb3b4
docs: add comments describing the parser rules
AlexanderSchultheiss Feb 21, 2024
d239664
feat: first working version of JavaPP parsing
AlexanderSchultheiss Feb 21, 2024
6d9e315
test: add test for parsing entire JPP diff
AlexanderSchultheiss Feb 21, 2024
569f663
chore: increment DiffDetective version
AlexanderSchultheiss Feb 21, 2024
387c78f
refactor: use the more general type
AlexanderSchultheiss Feb 21, 2024
f356365
fix(docs): fix broken blocks in Docstring
AlexanderSchultheiss Feb 21, 2024
f91123b
Update the version number in the remaining files
ibbem Feb 21, 2024
f2d46b6
docs: add docstring for AnnotationParser
AlexanderSchultheiss Feb 21, 2024
50c1d8a
docs: update documentation of DiffLineFormulaExtractor
AlexanderSchultheiss Feb 21, 2024
16c6586
refactor: let Marlin.java use a custom constructor method of Preproce…
AlexanderSchultheiss Feb 21, 2024
987fe11
docs: revise JPPDiffLineFormulaExtractor docstring
AlexanderSchultheiss Feb 21, 2024
7a99762
docs: add comment about Javadoc-related import
AlexanderSchultheiss Feb 21, 2024
7433fa7
refactor: use switch expression
AlexanderSchultheiss Feb 22, 2024
e25fad4
refactor: exchange default with actual variant to cause compile error…
AlexanderSchultheiss Feb 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.variantsync</groupId>
<artifactId>diffdetective</artifactId>
<version>2.1.0</version>
<version>2.2.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -98,16 +98,16 @@
<groupId>org.sat4j</groupId>
<artifactId>core</artifactId>
<version>2.3.5</version>
<!-- <scope>system</scope>-->
<!-- <systemPath>${project.basedir}/lib/org.sat4j.core.jar</systemPath>-->
<!-- <scope>system</scope>-->
<!-- <systemPath>${project.basedir}/lib/org.sat4j.core.jar</systemPath>-->
</dependency>

<dependency>
<groupId>de.ovgu</groupId>
<artifactId>featureide.lib.fm</artifactId>
<version>3.8.1</version>
<!-- <scope>system</scope>-->
<!-- <systemPath>${project.basedir}/lib/de.ovgu.featureide.lib.fm-v3.8.1.jar</systemPath>-->
<!-- <scope>system</scope>-->
<!-- <systemPath>${project.basedir}/lib/de.ovgu.featureide.lib.fm-v3.8.1.jar</systemPath>-->
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,320 @@
grammar JPPExpression;
// A grammar for the JavaPreprocessor
// https://www.slashdev.ca/javapp/

expression
: logicalOrExpression
;

logicalOrExpression
: logicalAndExpression (OR logicalAndExpression)*
;

logicalAndExpression
: primaryExpression (AND primaryExpression)*
;

primaryExpression
: definedExpression
| undefinedExpression
| comparisonExpression
;

comparisonExpression
: operand ((LT|GT|LEQ|GEQ|EQ|NEQ) operand)?
;

operand
: propertyExpression
| unaryOperator Constant
| Constant
| StringLiteral+
;

definedExpression
: 'defined' '(' Identifier ')'
;

undefinedExpression
: NOT 'defined' '(' Identifier ')'
;

propertyExpression
: '${' Identifier '}'
;

unaryOperator
: U_PLUS
| U_MINUS
;

U_PLUS : '+';
U_MINUS : '-';

AND : 'and';
OR : 'or';
NOT : '!';

LT : '<';
LEQ : '<=';
GT : '>';
GEQ : '>=';

EQ : '==';
NEQ : '!=';

DOT : '.';

Identifier
: IdentifierNondigit ( IdentifierNondigit
| Digit
)*
;

fragment
IdentifierNondigit
: Nondigit
| UniversalCharacterName
//| // other implementation-defined characters...y
;

fragment
Nondigit
: [a-zA-Z_]
;

fragment
Digit
: [0-9]
;

fragment
UniversalCharacterName
: '\\u' HexQuad
| '\\U' HexQuad HexQuad
;

fragment
HexQuad
: HexadecimalDigit HexadecimalDigit HexadecimalDigit HexadecimalDigit
;

Constant
: IntegerConstant
| FloatingConstant
;

fragment
IntegerConstant
: DecimalConstant IntegerSuffix?
| OctalConstant IntegerSuffix?
| HexadecimalConstant IntegerSuffix?
| BinaryConstant
;

fragment
BinaryConstant
: '0' [bB] [0-1]+
;

fragment
DecimalConstant
: NonzeroDigit Digit*
;

fragment
OctalConstant
: '0' OctalDigit*
;

fragment
HexadecimalConstant
: HexadecimalPrefix HexadecimalDigit+
;

fragment
HexadecimalPrefix
: '0' [xX]
;

fragment
NonzeroDigit
: [1-9]
;

fragment
OctalDigit
: [0-7]
;

fragment
HexadecimalDigit
: [0-9a-fA-F]
;

fragment
IntegerSuffix
: UnsignedSuffix LongSuffix?
| UnsignedSuffix LongLongSuffix
| LongSuffix UnsignedSuffix?
| LongLongSuffix UnsignedSuffix?
;

fragment
UnsignedSuffix
: [uU]
;

fragment
LongSuffix
: [lL]
;

fragment
LongLongSuffix
: 'll' | 'LL'
;

fragment
FloatingConstant
: DecimalFloatingConstant
| HexadecimalFloatingConstant
;

fragment
DecimalFloatingConstant
: FractionalConstant ExponentPart? FloatingSuffix?
| DigitSequence ExponentPart FloatingSuffix?
;

fragment
HexadecimalFloatingConstant
: HexadecimalPrefix (HexadecimalFractionalConstant | HexadecimalDigitSequence) BinaryExponentPart FloatingSuffix?
;

fragment
FractionalConstant
: DigitSequence? '.' DigitSequence
| DigitSequence '.'
;

fragment
ExponentPart
: [eE] Sign? DigitSequence
;

fragment
Sign
: [+-]
;

DigitSequence
: Digit+
;

fragment
HexadecimalFractionalConstant
: HexadecimalDigitSequence? '.' HexadecimalDigitSequence
| HexadecimalDigitSequence '.'
;

fragment
BinaryExponentPart
: [pP] Sign? DigitSequence
;

fragment
HexadecimalDigitSequence
: HexadecimalDigit+
;

fragment
FloatingSuffix
: [flFL]
;


fragment
CCharSequence
: CChar+
;

fragment
CChar
: ~['\\\r\n]
| EscapeSequence
;

fragment
EscapeSequence
: SimpleEscapeSequence
| OctalEscapeSequence
| HexadecimalEscapeSequence
| UniversalCharacterName
;

fragment
SimpleEscapeSequence
: '\\' ['"?abfnrtv\\]
;

fragment
OctalEscapeSequence
: '\\' OctalDigit OctalDigit? OctalDigit?
;

fragment
HexadecimalEscapeSequence
: '\\x' HexadecimalDigit+
;

StringLiteral
: EncodingPrefix? '"' SCharSequence? '"'
;

fragment
EncodingPrefix
: 'u8'
| 'u'
| 'U'
| 'L'
;

fragment
SCharSequence
: SChar+
;

fragment
SChar
: ~["\\\r\n]
| EscapeSequence
| '\\\n' // Added line
| '\\\r\n' // Added line
;

Whitespace
: [ \t]+ -> channel(HIDDEN)
;

Newline
: ( '\r' '\n'?
| '\n'
)
-> channel(HIDDEN)
;

BlockComment
: '/*' .*? '*/'
-> channel(HIDDEN)
;

OpenBlockComment
: '/*' ~[*/]*
-> channel(HIDDEN)
;

LineComment
: '//' ~[\r\n]*
-> channel(HIDDEN)
;
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.variantsync.diffdetective.datasets;

import org.variantsync.diffdetective.feature.CPPAnnotationParser;
import org.variantsync.diffdetective.feature.AnnotationParser;
import org.variantsync.diffdetective.variation.diff.parse.VariationDiffParseOptions;

/**
* Parse options that should be used when parsing commits and patches within a commit history.
* @param diffStoragePolicy Decides if and how unix diffs should be remembered in a parsed
* {@link org.variantsync.diffdetective.diff.git.PatchDiff} when parsing commits.
*
* @param diffStoragePolicy Decides if and how unix diffs should be remembered in a parsed
* {@link org.variantsync.diffdetective.diff.git.PatchDiff} when parsing commits.
* @param variationDiffParseOptions Options for parsing a patch to a {@link
* org.variantsync.diffdetective.variation.diff.VariationDiff}. For
* more information, see {@link VariationDiffParseOptions}.
Expand All @@ -26,7 +27,7 @@ public enum DiffStoragePolicy {
/**
* Creates PatchDiffParseOptions with the given annotation parser.
*/
public PatchDiffParseOptions withAnnotationParser(CPPAnnotationParser annotationParser) {
public PatchDiffParseOptions withAnnotationParser(AnnotationParser annotationParser) {
return new PatchDiffParseOptions(
this.diffStoragePolicy(),
this.variationDiffParseOptions().withAnnotationParser(annotationParser)
Expand Down
Loading
Loading