1

我是Maven的新手。我有一个项目,其中包含一个由 SableCC 读取的语法定义文件,它是一个解析器生成器。SableCC 读取一个语法文件并生成 Java 源代码,一旦编译,就会创建一个解析器。我的项目的其余部分使用解析器。

我不认为我的问题是 SableCC 问题,因为我已经看到类似的 POM.XML 文件使用 Antlr(另一个与 SableCC 相当的解析器生成器),并且该POM.XML 的部分看起来与我的部分<plugin>几乎相同<plugin>在我的 POM.XML 文件中。

这是我项目的文件结构,标识了 SableCC 使用的那些部分:

在此处输入图像描述

这是我完整的 POM.XML 文件,我根据迄今为止看到的插件示例(特别是 SableCC 的示例)拼凑而成:

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mbm</groupId>
    <artifactId>properties</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Properties</name>
    <description>Define and process program arguments</description>
    <dependencies>
    </dependencies>
    <build>
        <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>sablecc-maven-plugin</artifactId>
                <version>2.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        </pluginManagement>
    </build>
</project>

我的问题是 SableCC 插件如何知道输入文件在哪里以及生成的 4 类输出 Java 源文件(分析、词法分析器、节点和解析器)应该去哪里?我怀疑我需要在我的 POM 文件中添加更多 Maven“东西”,但我不知道是什么。

4

1 回答 1

0

您可以在此处查看插件配置: https ://github.com/tychobrailleur/sablecc-maven-plugin

进一步来说:

sourceDirectory:包含语法文件的目录。默认情况下,${basedir}/src/main/sablecc

outputDirectory:包含生成源的目录。默认情况下,${project.build.directory}/generated-sources/sablecc

您还可以提取 JAR 并在 plugin.xml 文件中查看这些配置:

<configuration>
  <outputDirectory implementation="java.lang.String">${project.build.directory}/generated-sources/sablecc</outputDirectory>
  <timestampDirectory implementation="java.lang.String">${basedir}/target</timestampDirectory>
  <sourceDirectory implementation="java.lang.String">${basedir}/src/main/sablecc</sourceDirectory>
  <project implementation="org.apache.maven.project.MavenProject">${project}</project>
  <staleMillis implementation="int" default-value="0">${lastModGranularityMs}</staleMillis>
</configuration>
于 2020-05-03T17:02:38.967 回答