Skip to content
Snippets Groups Projects
Commit 885b32be authored by dgelessus's avatar dgelessus
Browse files

Simplify handling of generated package names in templates further

parent caf79cd0
No related branches found
No related tags found
No related merge requests found
Showing
with 88 additions and 112 deletions
......@@ -24,7 +24,6 @@ public class GenAlts extends DepthFirstAdapter
private MacroExpander macros;
private ResolveAstIds ast_ids;
private File pkgDir;
private String pkgName;
private List<ElemInfo> elemList;
private String currentProd;
......@@ -46,7 +45,6 @@ public class GenAlts extends DepthFirstAdapter
}
pkgDir = new File(ast_ids.astIds.pkgDir, "node");
pkgName = ast_ids.astIds.pkgNameDot + "node";
if(!pkgDir.exists())
{
......@@ -132,7 +130,7 @@ public class GenAlts extends DepthFirstAdapter
}
}
macros.apply(file, "AlternativeHeader1", new String[] {pkgName});
macros.apply(file, "AlternativeHeader1", new String[] {ast_ids.astIds.pkgNameDot});
if(hasList)
{
......
......@@ -24,7 +24,6 @@ public class GenAnalyses extends DepthFirstAdapter
private MacroExpander macros;
private ResolveAstIds ast_ids;
private File pkgDir;
private String pkgName;
private List<ElemInfo> elemList;
private List<AltInfo> altList = new LinkedList<>();
private List<String> tokenList = new LinkedList<>();
......@@ -48,7 +47,6 @@ public class GenAnalyses extends DepthFirstAdapter
}
pkgDir = new File(ast_ids.astIds.pkgDir, "analysis");
pkgName = ast_ids.astIds.pkgNameDot + "analysis";
if(!pkgDir.exists())
{
......@@ -152,7 +150,7 @@ public class GenAnalyses extends DepthFirstAdapter
{
try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "Analysis.java"))))
{
macros.apply(file, "AnalysisHeader", new String[] {pkgName, ast_ids.astIds.pkgNameDot});
macros.apply(file, "AnalysisHeader", new String[] {ast_ids.astIds.pkgNameDot});
if(mainProduction != null)
{
......@@ -186,7 +184,7 @@ public class GenAnalyses extends DepthFirstAdapter
{
try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "AnalysisAdapter.java"))))
{
macros.apply(file, "AnalysisAdapterHeader", new String[] {pkgName, ast_ids.astIds.pkgNameDot});
macros.apply(file, "AnalysisAdapterHeader", new String[] {ast_ids.astIds.pkgNameDot});
if(mainProduction != null)
{
......@@ -218,7 +216,7 @@ public class GenAnalyses extends DepthFirstAdapter
{
try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "DepthFirstAdapter.java"))))
{
macros.apply(file, "DepthFirstAdapterHeader", new String[] {pkgName, ast_ids.astIds.pkgNameDot, mainProduction});
macros.apply(file, "DepthFirstAdapterHeader", new String[] {ast_ids.astIds.pkgNameDot, mainProduction});
for(AltInfo info : altList)
{
......@@ -267,7 +265,7 @@ public class GenAnalyses extends DepthFirstAdapter
{
try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "ReversedDepthFirstAdapter.java"))))
{
macros.apply(file, "ReversedDepthFirstAdapterHeader", new String[] {pkgName, ast_ids.astIds.pkgNameDot, mainProduction});
macros.apply(file, "ReversedDepthFirstAdapterHeader", new String[] {ast_ids.astIds.pkgNameDot, mainProduction});
for(AltInfo info : altList)
{
......
......@@ -30,7 +30,6 @@ public class GenLexer extends AnalysisAdapter
private MacroExpander macros;
private ResolveIds ids;
private File pkgDir;
private String pkgName;
private AcceptStates[] acceptStatesArray;
private Transitions transitions;
......@@ -50,7 +49,6 @@ public class GenLexer extends AnalysisAdapter
}
pkgDir = new File(ids.pkgDir, "lexer");
pkgName = ids.pkgNameDot + "lexer";
if(!pkgDir.exists())
{
......@@ -115,7 +113,7 @@ public class GenLexer extends AnalysisAdapter
{
try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "LexerException.java"))))
{
macros.apply(file, "LexerException", new String[] {pkgName});
macros.apply(file, "LexerException", new String[] {ids.pkgNameDot});
}
catch(IOException e)
{
......@@ -134,7 +132,7 @@ public class GenLexer extends AnalysisAdapter
startState = ids.stateList.getFirst();
}
macros.apply(file, "LexerHeader", new String[] {pkgName, ids.pkgNameDot, startState});
macros.apply(file, "LexerHeader", new String[] {ids.pkgNameDot, startState});
for(ListIterator<String> i = ids.tokenList.listIterator(); i.hasNext();)
{
......
......@@ -64,7 +64,6 @@ public class GenParser extends DepthFirstAdapter
private ComputeSimpleTermPosition CTP;
private File pkgDir;
private String pkgName;
private boolean hasProductions;
private String firstProductionName;
private boolean processInlining;
......@@ -116,7 +115,6 @@ public class GenParser extends DepthFirstAdapter
}
pkgDir = new File(ids.pkgDir, "parser");
pkgName = ids.pkgNameDot + "parser";
if(!pkgDir.exists())
{
......@@ -374,7 +372,7 @@ public class GenParser extends DepthFirstAdapter
Symbol[] nonterminals = Symbol.nonterminals();
Production[] productions = Production.productions();
macros.apply(file, "ParserHeader", new String[] {pkgName, ids.pkgNameDot});
macros.apply(file, "ParserHeader", new String[] {ids.pkgNameDot});
if(activateFilter && !grammarHasTransformations)
{
......@@ -732,7 +730,7 @@ public class GenParser extends DepthFirstAdapter
{
Symbol[] terminals = Symbol.terminals();
macros.apply(file, "TokenIndexHeader", new String[] {pkgName, ids.pkgNameDot});
macros.apply(file, "TokenIndexHeader", new String[] {ids.pkgNameDot});
for(int i = 0; i < (terminals.length - 2); i++)
{
......@@ -752,7 +750,7 @@ public class GenParser extends DepthFirstAdapter
{
try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "ParserException.java"))))
{
macros.apply(file, "ParserException", new String[] {pkgName, ids.pkgNameDot});
macros.apply(file, "ParserException", new String[] {ids.pkgNameDot});
}
catch(IOException e)
{
......@@ -765,7 +763,7 @@ public class GenParser extends DepthFirstAdapter
{
try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "State.java"))))
{
macros.apply(file, "State", new String[] {pkgName});
macros.apply(file, "State", new String[] {ids.pkgNameDot});
}
catch(IOException e)
{
......
......@@ -21,7 +21,6 @@ public class GenProds extends DepthFirstAdapter
private MacroExpander macros;
private ResolveAstIds ast_ids;
private File pkgDir;
private String pkgName;
public GenProds(ResolveAstIds ast_ids)
{
......@@ -39,7 +38,6 @@ public class GenProds extends DepthFirstAdapter
}
pkgDir = new File(ast_ids.astIds.pkgDir, "node");
pkgName = ast_ids.astIds.pkgNameDot + "node";
if(!pkgDir.exists())
{
......@@ -62,7 +60,7 @@ public class GenProds extends DepthFirstAdapter
{
try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, name + ".java"))))
{
macros.apply(file, "Production", new String[] {pkgName, name});
macros.apply(file, "Production", new String[] {ast_ids.astIds.pkgNameDot, name});
}
catch(IOException e)
{
......
......@@ -22,7 +22,6 @@ public class GenTokens extends DepthFirstAdapter
private MacroExpander macros;
private ResolveIds ids;
private File pkgDir;
private String pkgName;
// final GenTokens instance = this;
String text;
......@@ -43,7 +42,6 @@ public class GenTokens extends DepthFirstAdapter
}
pkgDir = new File(ids.pkgDir, "node");
pkgName = ids.pkgNameDot + "node";
if(!pkgDir.exists())
{
......@@ -101,13 +99,13 @@ public class GenTokens extends DepthFirstAdapter
{
ids.fixedTokens.put(node, false);
macros.apply(file, "VariableTextToken", new String[] {pkgName, ids.pkgNameDot, name});
macros.apply(file, "VariableTextToken", new String[] {ids.pkgNameDot, name});
}
else
{
ids.fixedTokens.put(node, true);
macros.apply(file, "FixedTextToken", new String[] {pkgName, ids.pkgNameDot, name, processText(text)});
macros.apply(file, "FixedTextToken", new String[] {ids.pkgNameDot, name, processText(text)});
ids.errorNames.put(node, "'" + text + "'");
}
......
......@@ -22,7 +22,6 @@ public class GenUtils extends DepthFirstAdapter
private MacroExpander macros;
private ResolveAstIds ast_ids;
private File pkgDir;
private String pkgName;
private String mainProduction;
public GenUtils(ResolveAstIds ast_ids)
......@@ -41,7 +40,6 @@ public class GenUtils extends DepthFirstAdapter
}
pkgDir = new File(ast_ids.astIds.pkgDir, "node");
pkgName = ast_ids.astIds.pkgNameDot + "node";
if(!pkgDir.exists())
{
......@@ -92,8 +90,7 @@ public class GenUtils extends DepthFirstAdapter
{
try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "Start.java"))))
{
macros.apply(file, "Start", new String[] {pkgName, ast_ids.astIds.pkgNameDot,
mainProduction, GenAlts.nodeName(mainProduction)});
macros.apply(file, "Start", new String[] {ast_ids.astIds.pkgNameDot, mainProduction, GenAlts.nodeName(mainProduction)});
}
catch(IOException e)
{
......@@ -106,7 +103,7 @@ public class GenUtils extends DepthFirstAdapter
{
try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "EOF.java"))))
{
macros.apply(file, "EOF", new String[] {pkgName, ast_ids.astIds.pkgNameDot});
macros.apply(file, "EOF", new String[] {ast_ids.astIds.pkgNameDot});
}
catch(IOException e)
{
......@@ -119,7 +116,7 @@ public class GenUtils extends DepthFirstAdapter
{
try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "Node.java"))))
{
macros.apply(file, "Node", new String[] {pkgName});
macros.apply(file, "Node", new String[] {ast_ids.astIds.pkgNameDot});
}
catch(IOException e)
{
......@@ -132,7 +129,7 @@ public class GenUtils extends DepthFirstAdapter
{
try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "Token.java"))))
{
macros.apply(file, "Token", new String[] {pkgName});
macros.apply(file, "Token", new String[] {ast_ids.astIds.pkgNameDot});
}
catch(IOException e)
{
......@@ -145,7 +142,7 @@ public class GenUtils extends DepthFirstAdapter
{
try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, cls + ".java"))))
{
macros.apply(file, cls, new String[] {pkgName});
macros.apply(file, cls, new String[] {ast_ids.astIds.pkgNameDot});
}
catch(IOException e)
{
......
......@@ -5,7 +5,6 @@ package org.sablecc.sablecc.node;
import de.hhu.stups.sablecc.patch.IToken;
import de.hhu.stups.sablecc.patch.SourcePosition;
public abstract class Token extends Node implements IToken
{
private String text;
......
......@@ -8,7 +8,7 @@
Macro:AlternativeHeader1
/* This file was generated by SableCC (http://www.sablecc.org/). */
package $0$;
package $0$node;
$
......
......@@ -8,9 +8,9 @@
Macro:AnalysisHeader
/* This file was generated by SableCC (http://www.sablecc.org/). */
package $0$;
package $0$analysis;
import $1$node.*;
import $0$node.*;
public interface Analysis extends Switch
{
......@@ -35,9 +35,9 @@ $
Macro:AnalysisAdapterHeader
/* This file was generated by SableCC (http://www.sablecc.org/). */
package $0$;
package $0$analysis;
import $1$node.*;
import $0$node.*;
public class AnalysisAdapter implements Analysis
{
......@@ -82,12 +82,12 @@ $
Macro:DepthFirstAdapterHeader
/* This file was generated by SableCC (http://www.sablecc.org/). */
package $0$;
package $0$analysis;
import java.util.ArrayList;
import java.util.List;
import $1$node.*;
import $0$node.*;
public class DepthFirstAdapter extends AnalysisAdapter
{
......@@ -115,7 +115,7 @@ public class DepthFirstAdapter extends AnalysisAdapter
public void caseStart(Start node)
{
inStart(node);
node.get$2$().apply(this);
node.get$1$().apply(this);
node.getEOF().apply(this);
outStart(node);
}
......@@ -125,13 +125,13 @@ $
Macro:ReversedDepthFirstAdapterHeader
/* This file was generated by SableCC (http://www.sablecc.org/). */
package $0$;
package $0$analysis;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import $1$node.*;
import $0$node.*;
public class ReversedDepthFirstAdapter extends AnalysisAdapter
{
......@@ -160,7 +160,7 @@ public class ReversedDepthFirstAdapter extends AnalysisAdapter
{
inStart(node);
node.getEOF().apply(this);
node.get$2$().apply(this);
node.get$1$().apply(this);
outStart(node);
}
......
......@@ -8,7 +8,7 @@
Macro:LexerException
/* This file was generated by SableCC (http://www.sablecc.org/). */
package $0$;
package $0$lexer;
@SuppressWarnings({"serial"})
public class LexerException extends Exception
......@@ -24,7 +24,7 @@ $
Macro:LexerHeader
/* This file was generated by SableCC (http://www.sablecc.org/). */
package $0$;
package $0$lexer;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
......@@ -39,13 +39,13 @@ import java.util.concurrent.LinkedBlockingQueue;
import de.hhu.stups.sablecc.patch.IToken;
import de.hhu.stups.sablecc.patch.ITokenListContainer;
import $1$node.*;
import $0$node.*;
@SuppressWarnings({"unused"})
public class Lexer implements ITokenListContainer
{
protected Token token;
protected State state = State.$2$;
protected State state = State.$1$;
private PushbackReader in;
protected int line;
......
......@@ -8,7 +8,7 @@
Macro:ParserHeader
/* This file was generated by SableCC (http://www.sablecc.org/). */
package $0$;
package $0$parser;
import java.io.DataInputStream;
import java.io.BufferedInputStream;
......@@ -26,8 +26,8 @@ import de.hhu.stups.sablecc.patch.IToken;
import de.hhu.stups.sablecc.patch.PositionedNode;
import de.hhu.stups.sablecc.patch.SourcecodeRange;
import $1$lexer.*;
import $1$node.*;
import $0$lexer.*;
import $0$node.*;
@SuppressWarnings({"rawtypes","unchecked","unused"})
public class Parser implements IParser
......@@ -580,10 +580,10 @@ $
Macro:TokenIndexHeader
/* This file was generated by SableCC (http://www.sablecc.org/). */
package $0$;
package $0$parser;
import $1$analysis.*;
import $1$node.*;
import $0$analysis.*;
import $0$node.*;
class TokenIndex extends AnalysisAdapter
{
......@@ -615,9 +615,9 @@ $
Macro:ParserException
/* This file was generated by SableCC (http://www.sablecc.org/). */
package $0$;
package $0$parser;
import $1$node.*;
import $0$node.*;
@SuppressWarnings("serial")
public class ParserException extends Exception
......@@ -654,7 +654,7 @@ $
Macro:State
/* This file was generated by SableCC (http://www.sablecc.org/). */
package $0$;
package $0$parser;
import java.util.List;
......
......@@ -8,7 +8,7 @@
Macro:Production
/* This file was generated by SableCC (http://www.sablecc.org/). */
package $0$;
package $0$node;
public abstract class $1$ extends Node
{
......
......@@ -5,92 +5,85 @@
* modification of SableCC. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// 0 : xxx.node
// 1 : xxx.analysis
// 2 : Txxx
Macro:VariableTextToken
/* This file was generated by SableCC (http://www.sablecc.org/). */
package $0$;
package $0$node;
import $1$analysis.*;
import $0$analysis.*;
public final class $2$ extends Token
public final class $1$ extends Token
{
public $2$(String text)
public $1$(String text)
{
super(text);
}
public $2$(String text, int line, int pos)
public $1$(String text, int line, int pos)
{
super(text, line, pos);
}
public $2$($2$ token)
public $1$($1$ token)
{
super(token);
}
@Override
public $2$ clone()
public $1$ clone()
{
return new $2$(this);
return new $1$(this);
}
@Override
public void apply(Switch sw)
{
((Analysis) sw).case$2$(this);
((Analysis) sw).case$1$(this);
}
}
$
// 0 : xxx.node
// 1 : xxx.analysis
// 2 : Txxx
// 3 : xxx
Macro:FixedTextToken
/* This file was generated by SableCC (http://www.sablecc.org/). */
package $0$;
package $0$node;
import $1$analysis.*;
import $0$analysis.*;
public final class $2$ extends Token
public final class $1$ extends Token
{
public $2$()
public $1$()
{
super("$3$");
super("$2$");
}
public $2$(int line, int pos)
public $1$(int line, int pos)
{
super("$3$", line, pos);
super("$2$", line, pos);
}
public $2$($2$ token)
public $1$($1$ token)
{
super(token);
}
@Override
public $2$ clone()
public $1$ clone()
{
return new $2$(this);
return new $1$(this);
}
@Override
public void apply(Switch sw)
{
((Analysis) sw).case$2$(this);
((Analysis) sw).case$1$(this);
}
@Override
public void setText(String text)
{
throw new RuntimeException("Cannot change $2$ text.");
throw new RuntimeException("Cannot change $1$ text.");
}
}
......
......@@ -8,13 +8,13 @@
Macro:Start
/* This file was generated by SableCC (http://www.sablecc.org/). */
package $0$;
package $0$node;
import $1$analysis.*;
import $0$analysis.*;
public final class Start extends Node
{
private $2$ _$3$_;
private $1$ _$2$_;
private EOF _eof_;
public Start()
......@@ -23,17 +23,17 @@ public final class Start extends Node
}
public Start(
$2$ _$3$_,
$1$ _$2$_,
EOF _eof_)
{
set$2$(_$3$_);
set$1$(_$2$_);
setEOF(_eof_);
}
public Start(Start node)
{
super(node);
set$2$(cloneNode(node._$3$_));
set$1$(cloneNode(node._$2$_));
setEOF(cloneNode(node._eof_));
}
......@@ -49,16 +49,16 @@ public final class Start extends Node
((Analysis) sw).caseStart(this);
}
public $2$ get$2$()
public $1$ get$1$()
{
return this._$3$_;
return this._$2$_;
}
public void set$2$($2$ node)
public void set$1$($1$ node)
{
if(this._$3$_ != null)
if(this._$2$_ != null)
{
this._$3$_.parent(null);
this._$2$_.parent(null);
}
if(node != null)
......@@ -71,7 +71,7 @@ public final class Start extends Node
node.parent(this);
}
this._$3$_ = node;
this._$2$_ = node;
}
public EOF getEOF()
......@@ -102,9 +102,9 @@ public final class Start extends Node
@Override
void removeChild(Node child)
{
if(this._$3$_ == child)
if(this._$2$_ == child)
{
this._$3$_ = null;
this._$2$_ = null;
return;
}
......@@ -120,9 +120,9 @@ public final class Start extends Node
@Override
void replaceChild(Node oldChild, Node newChild)
{
if(this._$3$_ == oldChild)
if(this._$2$_ == oldChild)
{
set$2$(($2$) newChild);
set$1$(($1$) newChild);
return;
}
......@@ -139,7 +139,7 @@ public final class Start extends Node
public String toString()
{
return "" +
toString(this._$3$_) +
toString(this._$2$_) +
toString(this._eof_);
}
}
......@@ -149,9 +149,9 @@ $
Macro:EOF
/* This file was generated by SableCC (http://www.sablecc.org/). */
package $0$;
package $0$node;
import $1$analysis.*;
import $0$analysis.*;
public final class EOF extends Token
{
......@@ -188,12 +188,11 @@ $
Macro:Token
/* This file was generated by SableCC (http://www.sablecc.org/). */
package $0$;
package $0$node;
import de.hhu.stups.sablecc.patch.IToken;
import de.hhu.stups.sablecc.patch.SourcePosition;
public abstract class Token extends Node implements IToken
{
private String text;
......@@ -323,7 +322,7 @@ $
Macro:Node
/* This file was generated by SableCC (http://www.sablecc.org/). */
package $0$;
package $0$node;
import java.util.LinkedList;
import java.util.List;
......@@ -418,7 +417,7 @@ $
Macro:Switch
/* This file was generated by SableCC (http://www.sablecc.org/). */
package $0$;
package $0$node;
public interface Switch
{
......@@ -430,7 +429,7 @@ $
Macro:Switchable
/* This file was generated by SableCC (http://www.sablecc.org/). */
package $0$;
package $0$node;
public interface Switchable
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment