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

Feature/antlr #117

Merged
merged 6 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions .github/workflows/sonar_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: 17
java-version: 21
distribution: zulu # Alternative distribution options are available
- name: Cache SonarCloud packages
uses: actions/cache@v3
Expand All @@ -35,4 +35,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew build sonar --info
run: ./gradlew build aggregateScoverage sonar --info
2 changes: 1 addition & 1 deletion build-logic/src/main/kotlin/code-quality.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins {

// id("com.github.hierynomus.license")
id("com.diffplug.spotless")
id("org.sonarqube")
id("djaxonomy.quality-sonar")
// id("com.javiersc.gradle.plugins.dependency.updates")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ NOTICE: You must still include a kotlin app / library etc. profile as we do not
*/

jacoco {
toolVersion = "0.8.10"
toolVersion = "0.8.12"
// reportsDirectory.set(layout.buildDirectory.dir("customJacocoReportDir"))
}

tasks.withType(JacocoReport::class) {
reports {
xml.required.set(false)
xml.required.set(true)
csv.required.set(false)
// html.outputLocation.set(layout.buildDirectory.dir("jacocoHtml"))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id ("org.sonarqube")
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ sonar {
).joinToString()
property("sonar.scala.coverage.reportPaths", rPath)
} else {
// use Jacoco
logger.warn("SONAR: ${project.name} is not a scala project or does not have the scala plugin applied, no coverage data will be available")
// use Jacoco ?
// sonar.coverage.jacoco.xmlReportPaths
}
val junitPaths =
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ junit-platform = "1.10.0"
kotest = "5.7.2"
# @pin We all move together
kotlin = "1.9.0"
logback = "1.4.11"
logback = "1.5.6"
mockito = "5.5.0"
monix = "3.4.1"
moshi = "1.15.0"
Expand Down
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.tree.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.truthencode.ddo.grammar.antlr.EnchantmentsParserBaseListener;
import io.truthencode.ddo.grammar.antlr.EnchantmentsParser;


import java.util.Arrays;
import java.util.stream.Collectors;
Expand All @@ -27,10 +23,10 @@ class DdoItemParserTest {
/**
* Default Listener just logs major entries / exits
*/
class DefaultTestListener extends EnchantmentsParserBaseListener {
private final EnchantmentsParser parser;
static class DefaultTestListener extends io.truthencode.ddo.grammar.antlr.EnchantmentsParserBaseListener {
private final io.truthencode.ddo.grammar.antlr.EnchantmentsParser parser;

public DefaultTestListener(EnchantmentsParser parser) {
public DefaultTestListener(io.truthencode.ddo.grammar.antlr.EnchantmentsParser parser) {
this.parser = parser;
}

Expand All @@ -57,15 +53,15 @@ void showTokenInfo(Token tok) {
LOG.info(msg);
}

void showLog(String tag, EnchantmentsParser.IdDeclContext ctx) {
void showLog(String tag, io.truthencode.ddo.grammar.antlr.EnchantmentsParser.IdDeclContext ctx) {
int idx = ctx.getRuleIndex();
String ph = String.format(tag + "\tid:%d \tdata:%s", idx, ctx.getText());
String ph = String.format("%s\tid:%d \tdata:%s", tag, idx, ctx.getText());
LOG.info(ph);

}

void showLog(String tag, String ctx) {
String ph = String.format(tag + ":\t%s", ctx);
String ph = String.format("%s:\t%s", tag,ctx);
LOG.info(ph);
}

Expand Down Expand Up @@ -97,48 +93,49 @@ public void exitEveryRule(ParserRuleContext ctx) {
}

@Override
public void enterParse(EnchantmentsParser.ParseContext ctx) {
public void enterParse(io.truthencode.ddo.grammar.antlr.EnchantmentsParser.ParseContext ctx) {
showLog("enterParse", ctx.getText());
}

@Override
public void exitParse(EnchantmentsParser.ParseContext ctx) {
public void exitParse(io.truthencode.ddo.grammar.antlr.EnchantmentsParser.ParseContext ctx) {
showLog("exitParse", ctx.getText());
}

@Override
public void enterIdDecl(EnchantmentsParser.IdDeclContext ctx) {
public void enterIdDecl(io.truthencode.ddo.grammar.antlr.EnchantmentsParser.IdDeclContext ctx) {
showLog("enterIdDecl", ctx);
}

@Override
public void exitIdDecl(EnchantmentsParser.IdDeclContext ctx) {
public void exitIdDecl(io.truthencode.ddo.grammar.antlr.EnchantmentsParser.IdDeclContext ctx) {
showLog("exitIdDecl", ctx.getText());
}

}

final static String SomeData = "Physical Sheltering +19\n" +
"Blue Augment Slot: Empty\n" +
"Fortification +94%\n" +
"+5 Enhancement Bonus\n" +
"Competence Healing Amplification +30\n" +
"False Life +29\n" +
"Flamecleansed Fury";
static final String SAMPLE_DATA = """
Physical Sheltering +19
Blue Augment Slot: Empty
Fortification +94%%
+5 Enhancement Bonus
Competence Healing Amplification +30
False Life +29
Flamecleansed Fury""";


@Test
void canReadPercent() {
// TODO: Refactor to inject tree listener
assertDoesNotThrow(() -> {
walkText(SomeData);
walkText(SAMPLE_DATA);
});
}

@Test
void canReadNumber() {
assertDoesNotThrow(() -> {
walkText(SomeData);
walkText(SAMPLE_DATA);
});
}

Expand All @@ -148,10 +145,10 @@ void walkText(String data) {

void walkText(String data, ParseTreeListener listener) {

EnchantmentsLexer lexer = new EnchantmentsLexer(CharStreams.fromString(data));
io.truthencode.ddo.grammar.antlr.EnchantmentsLexer lexer = new io.truthencode.ddo.grammar.antlr.EnchantmentsLexer(CharStreams.fromString(data));

CommonTokenStream tokens = new CommonTokenStream(lexer);
EnchantmentsParser parser = new EnchantmentsParser(tokens);
io.truthencode.ddo.grammar.antlr.EnchantmentsParser parser = new io.truthencode.ddo.grammar.antlr.EnchantmentsParser(tokens);
ParseTreeListener l = (listener != null) ? listener : new DefaultTestListener(parser);
ParseTree parseTree = parser.parse();
LOG.info(String.format("parseTree has %d children", parseTree.getChildCount()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,5 @@ object Feat extends Enum[Feat] with FeatSearchPrefix with LazyLogging {
}

override def values: IndexedSeq[Feat] =
GeneralFeat.values ++ ClassFeat.values ++ RacialFeat.values ++ MetaMagicFeat.values ++ DeityFeat.values ++ EpicFeat.values
GeneralFeat.values ++ ClassFeat.values ++ RacialFeat.values ++ MetaMagicFeat.values ++ DeityFeat.values ++ EpicFeat.values ++ SpecialFeat.values
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.truthencode.ddo.model.feats

import io.truthencode.ddo.support.requisite.{FeatRequisiteImpl, FreeFeat}

protected[feats] trait FeatRespecToken extends FeatRequisiteImpl with Passive with FreeFeat {
self: SpecialFeat =>
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,6 @@ object GeneralFeat
* Delimits the prefix and text.
*/
override protected val prefixSeparator: String = ": "
// val wow1: Seq[Seq[(WeaponCategory, Int)]] = for {
// weapon <- filterByWeaponClass(weaponClass)
// a1 <- icPlus1.filter(_ == weapon)
// a2 <- icPlus2.filter(_ == weapon)
// a3 <- icPlus3.filter(_ == weapon)
// } yield Seq((a1, 1), (a2, 2), (a3, 3))
// logger.info(s"found ${wow1.size} weapons for improved critical: ${weaponClass.entryName}")

override def prefix: Option[String] = Some("Improved Critical")

Expand Down Expand Up @@ -663,8 +656,6 @@ object GeneralFeat

case object Resilience extends GeneralFeat with Resilience

// Seq(Feat.WeaponFocusBludgeon, Feat.WeaponFocusPiercing, Feat.WeaponFocusSlashing, Feat.WeaponFocusRanged, Feat.WeaponFocusThrown)

// Passive Feats
// General passive feats
case object Diehard extends GeneralFeat with Diehard
Expand Down Expand Up @@ -941,8 +932,5 @@ object GeneralFeat
case object CoinLordFinishingSchoolTraining
extends GeneralFeat with CoinLordFinishingSchoolTraining

// Exchange feats
// case object FeatRespecToken extends Feat with FeatRespecToken

case object DraconicVitality extends GeneralFeat with DraconicVitality
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.truthencode.ddo.model.feats

import com.typesafe.scalalogging.LazyLogging
import enumeratum.Enum
import io.truthencode.ddo.model.effect.features.{Features, FeaturesImpl}
import io.truthencode.ddo.support.naming.FriendlyDisplay
import io.truthencode.ddo.support.requisite.{Inclusion, Requisite}

/**
* Meta / special feats such as Feat Respec Tokens which generally have meta-mechanic functions.
*/
sealed trait SpecialFeat extends Feat with FriendlyDisplay with SubFeatInformation with FeaturesImpl {
self: FeatType with Requisite with Inclusion with Features =>

}

object SpecialFeat extends Enum[SpecialFeat] with FeatSearchPrefix with FeatMatcher with LazyLogging {

val matchFeat: PartialFunction[Feat, SpecialFeat] = { case x: SpecialFeat =>
x
}

val matchFeatById: PartialFunction[String, SpecialFeat] = {
case x: String if SpecialFeat.namesToValuesMap.contains(x) =>
SpecialFeat.withNameOption(x) match {
case Some(y) => y
}
}

/**
* Used when qualifying a search with a prefix. Examples include finding "HalfElf" from qualified
* "Race:HalfElf"
*
* @return
* A default or applied prefix
*/
override def searchPrefixSource: String = "Special"

override def values: IndexedSeq[SpecialFeat] = findValues

// Exchange feats
case object FeatRespecToken extends SpecialFeat with FeatRespecToken
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.truthencode.ddo.model.feats

import com.typesafe.scalalogging.LazyLogging
import io.truthencode.ddo.model.feats.SpecialFeat.FeatRespecToken
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers

class SpecialFeatTest extends AnyFunSpec with Matchers with LazyLogging {
describe("A Feat Respec Token") {
it("should be retrieved from the base Feat Search") {
Feat.values should contain(SpecialFeat.FeatRespecToken)
}
}
}
Loading