Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
relast-preprocessor
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JastAdd
relast-preprocessor
Commits
2850be7f
Commit
2850be7f
authored
3 years ago
by
René Schöne
Browse files
Options
Downloads
Patches
Plain Diff
import command line messages
- fix handling of absolute input files - see #5
parent
86d0d611
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/org/jastadd/relast/compiler/Mustache.java
+1
-0
1 addition, 0 deletions
src/main/java/org/jastadd/relast/compiler/Mustache.java
src/main/java/org/jastadd/relast/compiler/RelAstProcessor.java
+12
-12
12 additions, 12 deletions
...ain/java/org/jastadd/relast/compiler/RelAstProcessor.java
with
13 additions
and
12 deletions
src/main/java/org/jastadd/relast/compiler/Mustache.java
+
1
−
0
View file @
2850be7f
...
...
@@ -43,6 +43,7 @@ public class Mustache {
Template
template
=
handlebars
.
compile
(
templateFileName
);
try
(
Writer
w
=
new
FileWriter
(
outputFileName
))
{
System
.
out
.
println
(
"Writing "
+
outputFileName
);
template
.
apply
(
context
,
w
);
w
.
flush
();
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/org/jastadd/relast/compiler/RelAstProcessor.java
+
12
−
12
View file @
2850be7f
...
...
@@ -55,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
);
}
...
...
@@ -74,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
->
relativize
FileName
(
inputBasePath
,
Paths
.
get
(
name
)).
ifPresent
(
inputFiles:
:
add
));
getConfiguration
().
getFiles
().
forEach
(
name
->
check
FileName
(
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
>
relativize
FileName
(
Path
inputBasePath
,
Path
filePath
)
{
private
Optional
<
Path
>
check
FileName
(
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
{
...
...
@@ -118,7 +118,7 @@ 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
();
...
...
@@ -128,7 +128,7 @@ public abstract class RelAstProcessor extends AbstractCompiler {
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
);
}
catch
(
IOException
|
beaver
.
Parser
.
Exception
e
)
{
printMessage
(
"Could not parse grammar file "
+
path
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment