Skip to content

Commit

Permalink
#378: Incomplete: extracted common parser code.
Browse files Browse the repository at this point in the history
  • Loading branch information
redcatbear committed Feb 16, 2024
1 parent a9bbf97 commit 23811d5
Show file tree
Hide file tree
Showing 21 changed files with 220 additions and 154 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

## What is OpenFastTrace?

OpenFastTrace (short OFT) is a requirement tracing suite. Requirement tracing helps you keeping track of whether you actually implemented everything you planned to in your specifications. It also identifies obsolete parts of your product and helps you getting rid of them.
OpenFastTrace (short OFT) is a requirement tracing suite. Requirement tracing keeps track of whether you actually implemented everything you planned to in your specifications. It also identifies obsolete parts of your product and helps you to get rid of them.

You can learn more about requirement tracing and how to use OpenFastTrace in the [user guide](doc/user_guide.md).

Below you see a screenshot of of a HTML tracing report where OFT traces itself. You see a summary followed by a detail view of the traced requirements.
Below you see a screenshot of an HTML tracing report where OFT traces itself. You see a summary followed by a detail view of the traced requirements.

<img src="doc/images/oft_screenshot_tracing_report.png" style="box-shadow: 5px 10px 18px #888888;" alt="OFT HTML tracing report">

Expand Down
2 changes: 1 addition & 1 deletion doc/changes/changes_3.8.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Code name: RST Importer

## Summary

In this release we derived a parser for Restructured Text (RST) from our existing Markdown parser.
Good news for our 🐍 Python friends: in this release we derived a parser for Restructured Text (RST) from our existing Markdown parser.

The Markdown parser in the process now accepts specification item titles underlined with either "=" (H1) or "-" (H2).

Expand Down
20 changes: 20 additions & 0 deletions importer/lightweightmarkup/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>openfasttrace-importer-lightweightmarkup</artifactId>
<name>OpenFastTrace Lightweight Markup Importer Base</name>
<parent>
<relativePath>../../parent/pom.xml</relativePath>
<groupId>org.itsallcode.openfasttrace</groupId>
<artifactId>openfasttrace-parent</artifactId>
<version>${revision}</version>
</parent>
<dependencies>
<dependency>
<groupId>org.itsallcode.openfasttrace</groupId>
<artifactId>openfasttrace-testutil</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
9 changes: 9 additions & 0 deletions importer/lightweightmarkup/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Base module for importers of lightweight markup formats.
*/
module org.itsallcode.openfasttrace.importer.lightweightmarkup
{
exports org.itsallcode.openfasttrace.importer.lightweightmarkup;

requires java.logging;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.itsallcode.openfasttrace.importer.markdown;
package org.itsallcode.openfasttrace.importer.lightweightmarkup;

enum State
public enum LineParserState
{
START, OUTSIDE, SPEC_ITEM, DESCRIPTION, COVERS, DEPENDS, RATIONALE, COMMENT, NEEDS, EOF, TITLE, TAGS
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.itsallcode.openfasttrace.importer.markdown;
package org.itsallcode.openfasttrace.importer.lightweightmarkup;

import java.util.logging.Logger;

Expand All @@ -15,23 +15,23 @@
* decides on resulting state and action depending on the configuration provided
* in the transition table.
*/
public class MarkdownImporterStateMachine
public class LineParserStateMachine
{
private static final Logger LOG = Logger
.getLogger(MarkdownImporterStateMachine.class.getName());
.getLogger(LineParserStateMachine.class.getName());

private State state = State.START;
private LineParserState state = LineParserState.START;
private String lastToken = "";
private final Transition[] transitions;

/**
* Create a new instance of the {@link MarkdownImporterStateMachine}
* Create a new instance of the {@link LineParserStateMachine}
*
* @param transitions
* the transition table that serves as configuration for the
* state machine
*/
public MarkdownImporterStateMachine(final Transition[] transitions)
public LineParserStateMachine(final Transition[] transitions)
{
this.transitions = transitions;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.itsallcode.openfasttrace.importer.lightweightmarkup;

import java.util.regex.Pattern;

/**
* Common interface for text patterns used in line parsers.
*/
public interface LinePattern {
/**
* Get the regular expression pattern associated with this line pattern.
*
* @return regular expression pattern
*/
public Pattern getPattern();
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
package org.itsallcode.openfasttrace.importer.markdown;
package org.itsallcode.openfasttrace.importer.lightweightmarkup;

class Transition
public class Transition
{
private final State from;
private final State to;
private final MdPattern markdownPattern;
private final LineParserState from;
private final LineParserState to;
private final LinePattern markdownPattern;
private final TransitionAction transitionAction;

public Transition(final State from, final State to, final MdPattern markdownPattern,
final TransitionAction transitionAction)
public Transition(final LineParserState from, final LineParserState to, final LinePattern markdownPattern,
final TransitionAction transitionAction)
{
this.from = from;
this.to = to;
this.markdownPattern = markdownPattern;
this.transitionAction = transitionAction;
}

public State getFrom()
public LineParserState getFrom()
{
return this.from;
}

public State getTo()
public LineParserState getTo()
{
return this.to;
}

public MdPattern getMarkdownPattern()
public LinePattern getMarkdownPattern()
{
return this.markdownPattern;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.itsallcode.openfasttrace.importer.lightweightmarkup;

@FunctionalInterface
public interface TransitionAction
{
void transit();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.itsallcode.openfasttrace.importer.lightweightmarkup;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

@ExtendWith(MockitoExtension.class)
class TransitionTest
{
@Test
void testToString(@Mock final TransitionAction actionMock, @Mock final LinePattern patternMock)
{
Mockito.when(patternMock.toString()).thenReturn("DUMMY_PATTERN");
final Transition transition = new Transition(LineParserState.OUTSIDE, LineParserState.TITLE, patternMock,
actionMock);
assertThat(transition.toString(),
equalTo("Transition [from=OUTSIDE, to=TITLE, markdownPattern=DUMMY_PATTERN]"));
}
}
4 changes: 4 additions & 0 deletions importer/markdown/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<groupId>org.itsallcode.openfasttrace</groupId>
<artifactId>openfasttrace-api</artifactId>
</dependency>
<dependency>
<groupId>org.itsallcode.openfasttrace</groupId>
<artifactId>openfasttrace-importer-lightweightmarkup</artifactId>
</dependency>
<dependency>
<groupId>org.itsallcode.openfasttrace</groupId>
<artifactId>openfasttrace-testutil</artifactId>
Expand Down
5 changes: 4 additions & 1 deletion importer/markdown/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.itsallcode.openfasttrace.importer.markdown.MarkdownImporterFactory;

/**
* This provides an importer for the MarkDown format.
*
Expand All @@ -7,7 +9,8 @@
{
requires java.logging;
requires transitive org.itsallcode.openfasttrace.api;
requires org.itsallcode.openfasttrace.importer.lightweightmarkup;

provides org.itsallcode.openfasttrace.api.importer.ImporterFactory
with org.itsallcode.openfasttrace.importer.markdown.MarkdownImporterFactory;
with MarkdownImporterFactory;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.itsallcode.openfasttrace.importer.markdown;

import static org.itsallcode.openfasttrace.importer.markdown.State.*;
import static org.itsallcode.openfasttrace.importer.lightweightmarkup.LineParserState.*;

import java.io.BufferedReader;
import java.io.IOException;
Expand All @@ -10,6 +10,7 @@
import org.itsallcode.openfasttrace.api.core.SpecificationItemId;
import org.itsallcode.openfasttrace.api.importer.*;
import org.itsallcode.openfasttrace.api.importer.input.InputFile;
import org.itsallcode.openfasttrace.importer.lightweightmarkup.*;

class MarkdownImporter implements Importer
{
Expand Down Expand Up @@ -140,7 +141,7 @@ class MarkdownImporter implements Importer

private final InputFile file;
private final ImportEventListener listener;
private final MarkdownImporterStateMachine stateMachine;
private final LineParserStateMachine stateMachine;
private String lastTitle = null;
private String lastLine = null;
private boolean inSpecificationItem;
Expand All @@ -150,7 +151,7 @@ class MarkdownImporter implements Importer
{
this.file = fileName;
this.listener = listener;
this.stateMachine = new MarkdownImporterStateMachine(this.transitions);
this.stateMachine = new LineParserStateMachine(this.transitions);
}

@Override
Expand Down Expand Up @@ -186,8 +187,8 @@ private void finishImport()
}
}

private static Transition transition(final State from, final State to,
final MdPattern pattern, final TransitionAction action)
private static Transition transition(final LineParserState from, final LineParserState to,
final LinePattern pattern, final TransitionAction action)
{
return new Transition(from, to, pattern, action);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import java.util.regex.Pattern;

import org.itsallcode.openfasttrace.api.core.SpecificationItemId;
import org.itsallcode.openfasttrace.importer.lightweightmarkup.LinePattern;

/**
* Patterns that describe tokens to be recognized within Markdown-style
* specifications.
*/
enum MdPattern
{
enum MdPattern implements LinePattern {
// [impl->dsn~md.specification-item-title~1]
// [impl->dsn~md.artifact-forwarding-notation~1]

Expand Down Expand Up @@ -67,6 +67,7 @@ enum MdPattern
*
* @return the pattern
*/
@Override
public Pattern getPattern()
{
return this.pattern;
Expand Down

This file was deleted.

Loading

0 comments on commit 23811d5

Please sign in to comment.