Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • bugfix/missing-newline-parse-error
  • develop
  • jastadd-fix-inc-param-debug
  • master
  • 1.0.0-pre-release.alpha
  • jastadd-2.3.5
6 results

Target

Select target project
No results found
Select Git revision
  • bugfix/missing-newline-parse-error
  • develop
  • jastadd-fix-inc-param-debug
  • master
  • 1.0.0-pre-release.alpha
  • jastadd-2.3.5
6 results
Show changes
Commits on Source (22)
Showing
with 420 additions and 139 deletions
......@@ -45,6 +45,8 @@ ragdoc_build:
script:
- JAVA_FILES=$(find src/ -name '*.java')
- /ragdoc-builder/start-builder.sh -excludeGenerated -d data/ $JAVA_FILES
only:
- master
artifacts:
paths:
- "data/"
......@@ -62,6 +64,8 @@ ragdoc_view:
- OUTPUT_DIR=$(pwd -P)/pages/docs/ragdoc
- cd /ragdoc-view/src/ && rm -rf data && ln -s $DATA_DIR
- /ragdoc-view/build-view.sh --output-path=$OUTPUT_DIR
only:
- master
artifacts:
paths:
- "pages/docs/ragdoc"
......@@ -76,9 +80,8 @@ pages:
- pip install -U mkdocs mkdocs-macros-plugin mkdocs-git-revision-date-localized-plugin
script:
- cd pages && mkdocs build
# only:
# - develop
# - master
only:
- master
artifacts:
paths:
- public
......@@ -29,26 +29,49 @@ sourceSets {
}
}
def versionFile = 'src/main/resources/preprocessor.properties'
def versionProps = new Properties()
try {
file(versionFile).withInputStream { stream -> versionProps.load(stream) }
version = versionProps['version']
} catch (e) {
// this happens, if either the properties file is not present, or cannot be read from
throw new GradleException("File ${versionFile} not found or unreadable. Aborting.", e)
}
task fatJar(type: Jar) {
group = "build"
archiveAppendix = "fatjar"
from sourceSets.main.output
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
manifest {
attributes "Main-Class": "${mainClassName}"
}
}
task modelJar(type: Jar) {
group = "build"
archiveBaseName = 'model'
archiveVersion = ''
archiveAppendix = "model"
from sourceSets.model.output
}
artifacts {
archives modelJar
archives fatJar
}
dependencies {
modelImplementation group: 'org.jastadd', name: 'jastadd', version: '2.3.4'
modelImplementation group: 'org.jastadd', name: 'jastadd', version: '2.3.5'
modelImplementation group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11'
implementation files(modelJar.archiveFile.get())
api group: 'org.jastadd', name: 'jastadd', version: '2.3.4'
api group: 'org.jastadd', name: 'jastadd', version: '2.3.5'
api group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11'
implementation group: 'com.github.jknack', name: 'handlebars', version: '4.2.0'
implementation group: 'com.github.jknack', name: 'handlebars', version: '4.3.0'
implementation group: 'org.yaml', name: 'snakeyaml', version: '1.27'
// test
......@@ -64,25 +87,8 @@ dependencies {
testFixturesApi group: 'commons-io', name: 'commons-io', version: '2.8.0'
}
def versionFile = 'src/main/resources/preprocessor.properties'
def versionProps = new Properties()
try {
file(versionFile).withInputStream { stream -> versionProps.load(stream) }
version = versionProps['version']
} catch (e) {
// this happens, if either the properties file is not present, or cannot be read from
throw new GradleException("File ${versionFile} not found or unreadable. Aborting.", e)
}
jar {
manifest {
attributes "Main-Class": "${mainClassName}"
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
archiveAppendix = "base"
}
test {
......
aspect Navigation {
/** Tests if Comment is a WhitespaceComment.
* @return 'true' if this is a WhitespaceComment, otherwise 'false'
*/
syn boolean Comment.isWhitespaceComment() = false;
eq WhitespaceComment.isWhitespaceComment() = true;
/** Tests if Comment is a SingleLineComment.
* @return 'true' if this is a SingleLineComment, otherwise 'false'
*/
syn boolean Comment.isSingleLineComment() = false;
eq SingleLineComment.isSingleLineComment() = true;
/** Tests if Comment is a MultiLineComment.
* @return 'true' if this is a MultiLineComment, otherwise 'false'
*/
syn boolean Comment.isMultiLineComment() = false;
eq MultiLineComment.isMultiLineComment() = true;
/** Tests if Comment is a DocComment.
* @return 'true' if this is a DocComment, otherwise 'false'
*/
syn boolean Comment.isDocComment() = false;
eq DocComment.isDocComment() = true;
/** Tests if DirectedRelation is a LeftDirectedRelation.
* @return 'true' if this is a LeftDirectedRelation, otherwise 'false'
*/
syn boolean DirectedRelation.isLeftDirectedRelation() = false;
eq LeftDirectedRelation.isLeftDirectedRelation() = true;
/** Tests if DirectedRelation is a RightDirectedRelation.
* @return 'true' if this is a RightDirectedRelation, otherwise 'false'
*/
syn boolean DirectedRelation.isRightDirectedRelation() = false;
eq RightDirectedRelation.isRightDirectedRelation() = true;
/** Tests if TypeComponent is a NormalComponent.
* @return 'true' if this is a NormalComponent, otherwise 'false'
*/
syn boolean TypeComponent.isNormalComponent() = false;
eq NormalComponent.isNormalComponent() = true;
/** Tests if TypeComponent is a ListComponent.
* @return 'true' if this is a ListComponent, otherwise 'false'
*/
syn boolean TypeComponent.isListComponent() = false;
eq ListComponent.isListComponent() = true;
/** Tests if TypeComponent is a OptComponent.
* @return 'true' if this is a OptComponent, otherwise 'false'
*/
syn boolean TypeComponent.isOptComponent() = false;
eq OptComponent.isOptComponent() = true;
/** Tests if Grammar is a GrammarFile.
* @return 'true' if this is a GrammarFile, otherwise 'false'
*/
syn boolean Grammar.isGrammarFile() = false;
eq GrammarFile.isGrammarFile() = true;
/** Tests if NavigableRole is a NormalRole.
* @return 'true' if this is a NormalRole, otherwise 'false'
*/
syn boolean NavigableRole.isNormalRole() = false;
eq NormalRole.isNormalRole() = true;
/** Tests if NavigableRole is a ListRole.
* @return 'true' if this is a ListRole, otherwise 'false'
*/
syn boolean NavigableRole.isListRole() = false;
eq ListRole.isListRole() = true;
/** Tests if NavigableRole is a OptRole.
* @return 'true' if this is a OptRole, otherwise 'false'
*/
syn boolean NavigableRole.isOptRole() = false;
eq OptRole.isOptRole() = true;
/** Tests if Component is a TypeComponent.
* @return 'true' if this is a TypeComponent, otherwise 'false'
*/
syn boolean Component.isTypeComponent() = false;
eq TypeComponent.isTypeComponent() = true;
/** Tests if Component is a TokenComponent.
* @return 'true' if this is a TokenComponent, otherwise 'false'
*/
syn boolean Component.isTokenComponent() = false;
eq TokenComponent.isTokenComponent() = true;
/** Tests if JavaTypeUse is a SimpleJavaTypeUse.
* @return 'true' if this is a SimpleJavaTypeUse, otherwise 'false'
*/
syn boolean JavaTypeUse.isSimpleJavaTypeUse() = false;
eq SimpleJavaTypeUse.isSimpleJavaTypeUse() = true;
/** Tests if JavaTypeUse is a ParameterizedJavaTypeUse.
* @return 'true' if this is a ParameterizedJavaTypeUse, otherwise 'false'
*/
syn boolean JavaTypeUse.isParameterizedJavaTypeUse() = false;
eq ParameterizedJavaTypeUse.isParameterizedJavaTypeUse() = true;
/** Tests if Relation is a DirectedRelation.
* @return 'true' if this is a DirectedRelation, otherwise 'false'
*/
syn boolean Relation.isDirectedRelation() = false;
eq DirectedRelation.isDirectedRelation() = true;
/** Tests if Relation is a BidirectionalRelation.
* @return 'true' if this is a BidirectionalRelation, otherwise 'false'
*/
syn boolean Relation.isBidirectionalRelation() = false;
eq BidirectionalRelation.isBidirectionalRelation() = true;
/** Tests if Role is a NavigableRole.
* @return 'true' if this is a NavigableRole, otherwise 'false'
*/
syn boolean Role.isNavigableRole() = false;
eq NavigableRole.isNavigableRole() = true;
/** Tests if Role is a UnnamedRole.
* @return 'true' if this is a UnnamedRole, otherwise 'false'
*/
syn boolean Role.isUnnamedRole() = false;
eq UnnamedRole.isUnnamedRole() = true;
/** Tests if Declaration is a EmptyDeclaration.
* @return 'true' if this is a EmptyDeclaration, otherwise 'false'
*/
syn boolean Declaration.isEmptyDeclaration() = false;
eq EmptyDeclaration.isEmptyDeclaration() = true;
/** Tests if Declaration is a TypeDecl.
* @return 'true' if this is a TypeDecl, otherwise 'false'
*/
syn boolean Declaration.isTypeDecl() = false;
eq TypeDecl.isTypeDecl() = true;
/** Tests if Declaration is a Relation.
* @return 'true' if this is a Relation, otherwise 'false'
*/
syn boolean Declaration.isRelation() = false;
eq Relation.isRelation() = true;
/** casts a Comment into a WhitespaceComment if possible.
* @return 'this' cast to a WhitespaceComment or 'null'
*/
syn WhitespaceComment Comment.asWhitespaceComment();
eq Comment.asWhitespaceComment() = null;
eq WhitespaceComment.asWhitespaceComment() = this;
/** casts a Comment into a SingleLineComment if possible.
* @return 'this' cast to a SingleLineComment or 'null'
*/
syn SingleLineComment Comment.asSingleLineComment();
eq Comment.asSingleLineComment() = null;
eq SingleLineComment.asSingleLineComment() = this;
/** casts a Comment into a MultiLineComment if possible.
* @return 'this' cast to a MultiLineComment or 'null'
*/
syn MultiLineComment Comment.asMultiLineComment();
eq Comment.asMultiLineComment() = null;
eq MultiLineComment.asMultiLineComment() = this;
/** casts a Comment into a DocComment if possible.
* @return 'this' cast to a DocComment or 'null'
*/
syn DocComment Comment.asDocComment();
eq Comment.asDocComment() = null;
eq DocComment.asDocComment() = this;
/** casts a DirectedRelation into a LeftDirectedRelation if possible.
* @return 'this' cast to a LeftDirectedRelation or 'null'
*/
syn LeftDirectedRelation DirectedRelation.asLeftDirectedRelation();
eq DirectedRelation.asLeftDirectedRelation() = null;
eq LeftDirectedRelation.asLeftDirectedRelation() = this;
/** casts a DirectedRelation into a RightDirectedRelation if possible.
* @return 'this' cast to a RightDirectedRelation or 'null'
*/
syn RightDirectedRelation DirectedRelation.asRightDirectedRelation();
eq DirectedRelation.asRightDirectedRelation() = null;
eq RightDirectedRelation.asRightDirectedRelation() = this;
/** casts a TypeComponent into a NormalComponent if possible.
* @return 'this' cast to a NormalComponent or 'null'
*/
syn NormalComponent TypeComponent.asNormalComponent();
eq TypeComponent.asNormalComponent() = null;
eq NormalComponent.asNormalComponent() = this;
/** casts a TypeComponent into a ListComponent if possible.
* @return 'this' cast to a ListComponent or 'null'
*/
syn ListComponent TypeComponent.asListComponent();
eq TypeComponent.asListComponent() = null;
eq ListComponent.asListComponent() = this;
/** casts a TypeComponent into a OptComponent if possible.
* @return 'this' cast to a OptComponent or 'null'
*/
syn OptComponent TypeComponent.asOptComponent();
eq TypeComponent.asOptComponent() = null;
eq OptComponent.asOptComponent() = this;
/** casts a Grammar into a GrammarFile if possible.
* @return 'this' cast to a GrammarFile or 'null'
*/
syn GrammarFile Grammar.asGrammarFile();
eq Grammar.asGrammarFile() = null;
eq GrammarFile.asGrammarFile() = this;
/** casts a NavigableRole into a NormalRole if possible.
* @return 'this' cast to a NormalRole or 'null'
*/
syn NormalRole NavigableRole.asNormalRole();
eq NavigableRole.asNormalRole() = null;
eq NormalRole.asNormalRole() = this;
/** casts a NavigableRole into a ListRole if possible.
* @return 'this' cast to a ListRole or 'null'
*/
syn ListRole NavigableRole.asListRole();
eq NavigableRole.asListRole() = null;
eq ListRole.asListRole() = this;
/** casts a NavigableRole into a OptRole if possible.
* @return 'this' cast to a OptRole or 'null'
*/
syn OptRole NavigableRole.asOptRole();
eq NavigableRole.asOptRole() = null;
eq OptRole.asOptRole() = this;
/** casts a Component into a TypeComponent if possible.
* @return 'this' cast to a TypeComponent or 'null'
*/
syn TypeComponent Component.asTypeComponent();
eq Component.asTypeComponent() = null;
eq TypeComponent.asTypeComponent() = this;
/** casts a Component into a TokenComponent if possible.
* @return 'this' cast to a TokenComponent or 'null'
*/
syn TokenComponent Component.asTokenComponent();
eq Component.asTokenComponent() = null;
eq TokenComponent.asTokenComponent() = this;
/** casts a JavaTypeUse into a SimpleJavaTypeUse if possible.
* @return 'this' cast to a SimpleJavaTypeUse or 'null'
*/
syn SimpleJavaTypeUse JavaTypeUse.asSimpleJavaTypeUse();
eq JavaTypeUse.asSimpleJavaTypeUse() = null;
eq SimpleJavaTypeUse.asSimpleJavaTypeUse() = this;
/** casts a JavaTypeUse into a ParameterizedJavaTypeUse if possible.
* @return 'this' cast to a ParameterizedJavaTypeUse or 'null'
*/
syn ParameterizedJavaTypeUse JavaTypeUse.asParameterizedJavaTypeUse();
eq JavaTypeUse.asParameterizedJavaTypeUse() = null;
eq ParameterizedJavaTypeUse.asParameterizedJavaTypeUse() = this;
/** casts a Relation into a DirectedRelation if possible.
* @return 'this' cast to a DirectedRelation or 'null'
*/
syn DirectedRelation Relation.asDirectedRelation();
eq Relation.asDirectedRelation() = null;
eq DirectedRelation.asDirectedRelation() = this;
/** casts a Relation into a BidirectionalRelation if possible.
* @return 'this' cast to a BidirectionalRelation or 'null'
*/
syn BidirectionalRelation Relation.asBidirectionalRelation();
eq Relation.asBidirectionalRelation() = null;
eq BidirectionalRelation.asBidirectionalRelation() = this;
/** casts a Role into a NavigableRole if possible.
* @return 'this' cast to a NavigableRole or 'null'
*/
syn NavigableRole Role.asNavigableRole();
eq Role.asNavigableRole() = null;
eq NavigableRole.asNavigableRole() = this;
/** casts a Role into a UnnamedRole if possible.
* @return 'this' cast to a UnnamedRole or 'null'
*/
syn UnnamedRole Role.asUnnamedRole();
eq Role.asUnnamedRole() = null;
eq UnnamedRole.asUnnamedRole() = this;
/** casts a Declaration into a EmptyDeclaration if possible.
* @return 'this' cast to a EmptyDeclaration or 'null'
*/
syn EmptyDeclaration Declaration.asEmptyDeclaration();
eq Declaration.asEmptyDeclaration() = null;
eq EmptyDeclaration.asEmptyDeclaration() = this;
/** casts a Declaration into a TypeDecl if possible.
* @return 'this' cast to a TypeDecl or 'null'
*/
syn TypeDecl Declaration.asTypeDecl();
eq Declaration.asTypeDecl() = null;
eq TypeDecl.asTypeDecl() = this;
/** casts a Declaration into a Relation if possible.
* @return 'this' cast to a Relation or 'null'
*/
syn Relation Declaration.asRelation();
eq Declaration.asRelation() = null;
eq Relation.asRelation() = this;
}
......@@ -2,6 +2,8 @@ aspect Navigation {
// --- program ---
inh Program ASTNode.program();
eq Grammar.getChild().program() = null;
eq GrammarFile.getChild().program() = program();
eq Program.getChild().program() = this;
// --- typeDecls ---
......@@ -28,66 +30,10 @@ aspect Navigation {
// --- containedFile ---
inh GrammarFile ASTNode.containedFile();
eq Grammar.getChild().containedFile() = null;
eq Program.getChild().containedFile() = null;
eq GrammarFile.getChild().containedFile() = this;
// --- containedFileName ---
inh String ASTNode.containedFileName();
eq GrammarFile.getChild().containedFileName() = getFileName();
// --- isTokenComponent ---
syn boolean Component.isTokenComponent() = false;
eq TokenComponent.isTokenComponent() = true;
// --- asTokenComponent ---
syn TokenComponent Component.asTokenComponent() = null;
eq TokenComponent.asTokenComponent() = this;
// --- isTypeDecl (should be in preprocessor) ---
syn boolean Declaration.isTypeDecl() = false;
eq TypeDecl.isTypeDecl() = true;
// --- asTypeDecl (should be in preprocessor) ---
syn TypeDecl Declaration.asTypeDecl() = null;
eq TypeDecl.asTypeDecl() = this;
// --- isTypeComponent (should be in preprocessor) ---
syn boolean Component.isTypeComponent() = false;
eq TypeComponent.isTypeComponent() = true;
// --- asTypeComponent (should be in preprocessor) ---
syn TypeComponent Component.asTypeComponent() = null;
eq TypeComponent.asTypeComponent() = this;
// --- isNormalComponent (should be in preprocessor) ---
syn boolean Component.isNormalComponent() = false;
eq NormalComponent.isNormalComponent() = true;
// --- asNormalComponent (should be in preprocessor) ---
syn NormalComponent Component.asNormalComponent() = null;
eq NormalComponent.asNormalComponent() = this;
// --- isListComponent (should be in preprocessor) ---
syn boolean Component.isListComponent() = false;
eq ListComponent.isListComponent() = true;
// --- asListComponent (should be in preprocessor) ---
syn ListComponent Component.asListComponent() = null;
eq ListComponent.asListComponent() = this;
// --- isDirectedRelation (should be in preprocessor) ---
syn boolean Relation.isDirectedRelation() = false;
eq DirectedRelation.isDirectedRelation() = true;
// --- asDirectedRelation (should be in preprocessor) ---
syn DirectedRelation Relation.asDirectedRelation() = null;
eq DirectedRelation.asDirectedRelation() = this;
// --- asBidirectionalRelation (should be in preprocessor) ---
syn BidirectionalRelation Relation.asBidirectionalRelation() = null;
eq BidirectionalRelation.asBidirectionalRelation() = this;
// --- isListRole (should be in preprocessor) ---
syn boolean Role.isListRole() = false;
eq ListRole.isListRole() = true;
syn String ASTNode.containedFileName() = containedFile().getFileName();
}
......@@ -127,6 +127,7 @@ aspect BackendAbstractGrammar {
}
public void ParameterizedJavaTypeUse.generateAbstractGrammar(StringBuilder b) {
b.append(getName());
b.append("<");
boolean first = true;
for (JavaTypeUse javaTypeUse : getJavaTypeUseList()) {
......
GrammarFile goal
= comment_list.c grammar_file.f {: f.getDeclarationList().insertChild(new EmptyDeclaration(c), 0); return f; :}
| grammar_file
;
GrammarFile grammar_file
......@@ -16,8 +15,8 @@ Declaration declaration
// this method would be create by the JAstAddParser from a usage of
// 'comment+' in a rule, but only for the standard list class 'List'.
JastAddList comment_list
= comment.n {: return new JastAddList().add(n); :}
| comment_list.l comment.n {: return l.add(n); :}
= comment.c comment_list.l {: l.insertChild(c, 0); return l; :}
| /* epsilon */ {: return new JastAddList(); :}
;
Comment comment
......
<YYINITIAL,DECLARATION> {
<YYINITIAL,COMMENT,DECLARATION> {
"abstract" { yybegin(DECLARATION); return sym(Terminals.ABSTRACT); }
"rel" { yybegin(DECLARATION); return sym(Terminals.RELATION); }
}
<YYINITIAL,DECLARATION> {
<YYINITIAL,COMMENT,DECLARATION> {
{ID} { yybegin(DECLARATION); return sym(Terminals.ID); }
[^] { throw new ScannerError((yyline+1) +"," + (yycolumn+1) + ": Illegal character <"+yytext()+">"); }
}
<YYINITIAL,DECLARATION,COMMENT> {
<YYINITIAL,COMMENT,DECLARATION> {
<<EOF>> { return sym(Terminals.EOF); }
[^] { throw new ScannerError((yyline+1) +"," + (yycolumn+1) + ": Illegal character <"+yytext()+">"); }
}
\ No newline at end of file
<YYINITIAL,DECLARATION> {
<YYINITIAL,COMMENT,DECLARATION> {
";" { yybegin(COMMENT); return sym(Terminals.SCOL); }
":" { yybegin(DECLARATION); return sym(Terminals.COL); }
"::=" { yybegin(DECLARATION); return sym(Terminals.ASSIGN); }
......
......@@ -140,7 +140,6 @@ public class PreprocessorConfiguration extends org.jastadd.Configuration {
allOptions.add(cacheCycleOption);
allOptions.add(componentCheckOption);
allOptions.add(inhEqCheckOption);
allOptions.add(suppressWarningsOption);
allOptions.add(refineLegacyOption);
allOptions.add(licenseOption);
allOptions.add(debugOption);
......@@ -180,27 +179,6 @@ public class PreprocessorConfiguration extends org.jastadd.Configuration {
// New since 2.3.4
allOptions.add(optimizeImports);
// Deprecated in 2.1.5.
allOptions.add(doxygenOption);
allOptions.add(cacheAllOption);
allOptions.add(noCachingOption);
allOptions.add(cacheNoneOption);
allOptions.add(cacheImplicitOption);
allOptions.add(ignoreLazyOption);
allOptions.add(fullFlushOption);
// Deprecated in 2.1.9.
allOptions.add(docOption);
allOptions.add(java1_4Option); // Disabled in 2.1.10.
allOptions.add(noLazyMapsOption);
allOptions.add(noVisitCheckOption);
allOptions.add(noCacheCycleOption);
allOptions.add(noRefineLegacyOption);
allOptions.add(noComponentCheckOption);
allOptions.add(noInhEqCheckOption);
allOptions.add(noStaticOption);
allOptions.add(deterministicOption);
return allOptions;
}
......
......@@ -39,9 +39,11 @@ public class Mustache {
Handlebars handlebars = new Handlebars(loader);
handlebars.prettyPrint(true); // set handlebars to mustache mode (skip some whitespace)
handlebars.infiniteLoops(true); // allow partial recursion
Template template = handlebars.compile(templateFileName);
try (Writer w = new FileWriter(outputFileName)) {
System.out.println("Writing " + outputFileName);
template.apply(context, w);
w.flush();
}
......
......@@ -25,9 +25,20 @@ public abstract class RelAstProcessor extends AbstractCompiler {
super(name, jastAddCompliant);
}
protected boolean isGrammarFile(String fileName) {
String extension = fileName.subSequence(fileName.lastIndexOf('.'), fileName.length()).toString();
return extension.equals(".relast") || extension.equals(".ast");
protected boolean isGrammarFile(Path path) {
if (path.getFileName() == null) { return false; }
String fileName = path.getFileName().toString();
int dotIndex = fileName.lastIndexOf('.');
if (dotIndex < 0) {
printMessage(path + " has no extension, ignoring it.");
return false;
}
String extension = fileName.subSequence(dotIndex, fileName.length()).toString();
boolean isGrammar = extension.equals(".relast") || extension.equals(".ast");
if (!isGrammar) {
printMessage(path + " is not a grammar file, ignoring it.");
}
return isGrammar;
}
@Override
......@@ -44,14 +55,14 @@ public abstract class RelAstProcessor extends AbstractCompiler {
inputBasePath = Paths.get(optionInputBaseDir.value()).toAbsolutePath();
} else {
inputBasePath = Paths.get(".").toAbsolutePath();
printMessage("No input base dir is set. Assuming current directory '" + inputBasePath.toAbsolutePath().toString() + "'.");
printMessage("No input base dir is set. Assuming current directory '" + inputBasePath.toAbsolutePath() + "'.");
}
if (!inputBasePath.toFile().exists()) {
printMessage("Input path '" + inputBasePath.toAbsolutePath().toString() + "' does not exist. Exiting...");
printMessage("Input path '" + inputBasePath.toAbsolutePath() + "' does not exist. Exiting...");
System.exit(-1);
} else if (!inputBasePath.toFile().isDirectory()) {
printMessage("Input path '" + inputBasePath.toAbsolutePath().toString() + "' is not a directory. Exiting...");
printMessage("Input path '" + inputBasePath.toAbsolutePath() + "' is not a directory. Exiting...");
System.exit(-1);
}
......@@ -63,29 +74,29 @@ public abstract class RelAstProcessor extends AbstractCompiler {
}
if (outputBasePath.toFile().exists() && !outputBasePath.toFile().isDirectory()) {
printMessage("Output path '" + inputBasePath.toAbsolutePath().toString() + "' exists, but is not a directory. Exiting...");
printMessage("Output path '" + inputBasePath.toAbsolutePath() + "' exists, but is not a directory. Exiting...");
}
printMessage("Running " + getName());
// gather all files
Collection<Path> inputFiles = new ArrayList<>();
getConfiguration().getFiles().forEach(name -> relativizeFileName(inputBasePath, Paths.get(name)).ifPresent(inputFiles::add));
getConfiguration().getFiles().forEach(name -> checkFileName(inputBasePath, Paths.get(name)).ifPresent(inputFiles::add));
Program program = parseProgram(inputFiles);
Program program = parseProgram(inputBasePath, inputFiles);
return processGrammar(program, inputBasePath, outputBasePath);
}
protected abstract int processGrammar(Program program, Path inputBasePath, Path outputBasePath) throws CompilerException;
private Optional<Path> relativizeFileName(Path inputBasePath, Path filePath) {
private Optional<Path> checkFileName(Path inputBasePath, Path filePath) {
if (filePath.isAbsolute()) {
if (filePath.startsWith(inputBasePath)) {
return Optional.of(filePath.relativize(inputBasePath));
if (filePath.normalize().startsWith(inputBasePath.normalize())) {
return Optional.of(filePath);
} else {
printMessage("Path '" + filePath + "' is not contained in the base path '" + inputBasePath + "'.");
printMessage("Path '" + filePath + "' is not contained in the base path '" + inputBasePath + "', ignoring it.");
return Optional.empty();
}
} else {
......@@ -107,19 +118,18 @@ public abstract class RelAstProcessor extends AbstractCompiler {
}
}
private Program parseProgram(Collection<Path> inputFiles) {
private Program parseProgram(Path inputBasePath, Collection<Path> inputFiles) {
Program program = new Program();
RelAstParser parser = new RelAstParser();
inputFiles.stream().filter(path -> isGrammarFile(path.toString())).forEach(
inputFiles.stream().filter(this::isGrammarFile).forEach(
path -> {
try (BufferedReader reader = Files.newBufferedReader(path)) {
RelAstScanner scanner = new RelAstScanner(reader);
GrammarFile inputGrammar = (GrammarFile) parser.parse(scanner);
inputGrammar.setFileName(path.toString());
inputGrammar.setFileName(inputBasePath.relativize(path).toString());
program.addGrammarFile(inputGrammar);
inputGrammar.treeResolveAll();
} catch (IOException | beaver.Parser.Exception e) {
printMessage("Could not parse grammar file " + path);
e.printStackTrace();
......@@ -127,6 +137,8 @@ public abstract class RelAstProcessor extends AbstractCompiler {
}
);
program.treeResolveAll();
return program;
}
}
......
......@@ -22,12 +22,6 @@ public class RelastSourceToSourceCompiler extends RelAstProcessor {
}
}
@Override
protected boolean isGrammarFile(String fileName) {
String extension = fileName.subSequence(fileName.lastIndexOf("."), fileName.length()).toString();
return extension.equals(".relast") || extension.equals(".ast");
}
@Override
protected int processGrammar(Program program, Path inputBasePath, Path outputBasePath) throws CompilerException {
......@@ -36,7 +30,7 @@ public class RelastSourceToSourceCompiler extends RelAstProcessor {
for (GrammarFile grammarFile : program.getGrammarFileList()) {
printMessage("Writing output file " + grammarFile.getFileName());
// TODO decide and document what the file name should be, the full path or a simple name?
writeToFile(outputBasePath.resolve(inputBasePath.relativize(Paths.get(grammarFile.getFileName()))), grammarFile.generateAbstractGrammar());
writeToFile(outputBasePath.resolve(grammarFile.getFileName()), grammarFile.generateAbstractGrammar());
}
return 0;
}
......
- name: "dependencies between relast files"
args:
- "--inputBaseDir=in"
- "--outputBaseDir=out"
- "Rel.relast"
- "A.relast"
- "B.relast"
- "C.relast"
out: "out"
expected: "in"
compare: true
A ::= A1 A2;
A1 ::= B;
A2 ::= C;
B ::= B1 B2;
B1 ::= A;
B2 ::= C;
C ::= [C1] [C2];
C1 ::= A;
C2 ::= B;
rel A.b? -> B;
rel B.c? -> C;
rel C.a? -> A;
......@@ -4,6 +4,7 @@
- "--outputBaseDir=out"
- "Example.relast"
- "CommentInFront.relast"
- "DefaultTypeOfToken.ast"
out: "out"
expected: "in"
compare: true
A ::= <B>;