Skip to content

Commit

Permalink
Reorganize code tree
Browse files Browse the repository at this point in the history
  • Loading branch information
proninis committed Mar 31, 2014
1 parent 92a315a commit be81a10
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 88 deletions.
18 changes: 2 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
*.class
*.tokens
class/*.class
src-g4/grammar/*
*.txt
*.swp
*.bkp
*.png
*.html
*.dm
byond2Parser.java
byond2Lexer.java
byond2ParserBaseListener.java
byond2ParserListener.java
byond2Preproc.java
byond2PreprocLexer.java
byond2PreprocBaseListener.java
byond2PreprocListener.java
output.dm
byond2ParserBaseVisitor.java
byond2ParserVisitor.java
byond2PreprocBaseVisitor.java
byond2PreprocVisitor.java
byond2Common.java
57 changes: 33 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
#!/bin/sh

IGNORE = \
byond2Parser.java\
byond2Lexer.java\
byond2ParserBaseListener.java\
byond2ParserListener.java\
byond2Preproc.java\
byond2PreprocLexer.java\
byond2PreprocBaseListener.java\
byond2PreprocListener.java
Parser.java\
Lexer.java\
ParserBaseListener.java\
ParserListener.java\
Preproc.java\
PreprocLexer.java\
PreprocBaseListener.java\
PreprocListener.java

grammars = \
byond2Lexer.g4\
byond2Parser.g4\
byond2PreprocLexer.g4\
byond2Preproc.g4
DMLexer.g4\
DMParser.g4\
PreprocLexer.g4\
Preproc.g4

sources = $(grammars:.g4=.java)
classes = $(grammars:.g4=.class)
classes_g4 = $(grammars:.g4=.class)

SRCS = $(wildcard *.java)
SRCF = $(filter-out $(IGNORE), $(SRCS))
CLS = $(SRCF:.java=.class)
sources = $(wildcard src/*.java)
classes = $(sources:.java=.class)

all: $(classes) $(CLS)
all: $(classes_g4) $(classes)

%.class: %.java
javac -cp .:/media/usb3/media/download/antlr-4.2.1-complete.jar $<
%.class: src-g4/grammar/%.java
javac -cp src:src-g4/grammar:/media/usb3/media/download/antlr-4.2.1-complete.jar \
-d class $<

%.java: %.g4
java -jar /media/usb3/media/download/antlr-4.2.1-complete.jar $?
src/%.class: src/%.java
javac -cp src:src-g4/grammar:/media/usb3/media/download/antlr-4.2.1-complete.jar \
-d class $<

src-g4/grammar/%.java: grammar/%.g4
java -jar /media/usb3/media/download/antlr-4.2.1-complete.jar \
-o src-g4 -lib src-g4/grammar $?

clean:
-rm byond2Parser.java
Expand All @@ -44,8 +48,13 @@ clean:
-rm byond2PreprocBaseVisitor.java
-rm byond2ParserBaseVisitor.java
-rm byond2ParserVisitor.java
-rm *.class
-rm *.tokens
-rm byond2Common.java
-rm class/*.class
-rm -rf src-g4/grammar/*
-rm byondp.jar

jar:
@jar cf byondp.jar class/*.class

test:
@./test.sh
Expand Down
2 changes: 1 addition & 1 deletion byond2Common.g4 → grammar/Common.g4
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lexer grammar byond2Common;
lexer grammar Common;

////////////////////////////////////////////////////////////////////////////////
// string
Expand Down
4 changes: 2 additions & 2 deletions byond2Lexer.g4 → grammar/DMLexer.g4
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
lexer grammar byond2Lexer;
import byond2Common;
lexer grammar DMLexer;
import Common;

////////////////////////////////////////////////////////////////////////////////
// token flow control
Expand Down
30 changes: 15 additions & 15 deletions byond2Parser.g4 → grammar/DMParser.g4
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
parser grammar byond2Parser;
parser grammar DMParser;

options
{
tokenVocab = byond2Lexer;
tokenVocab = DMLexer;
}


Expand Down Expand Up @@ -276,29 +276,29 @@ opNew
;

opAssign
: expr EQ <assoc=right> expr
: expr EQ expr
;

opOpAssign
: expr
( EQPLUS <assoc=right>
| EQMINUS <assoc=right>
| EQMUL <assoc=right>
| EQSLASH <assoc=right>
| EQMOD <assoc=right>
| EQBITOR <assoc=right>
| EQBITAND <assoc=right>
| EQBITRSH <assoc=right>
| EQBITLSH <assoc=right>
| EQBITXOR <assoc=right>)
( EQPLUS
| EQMINUS
| EQMUL
| EQSLASH
| EQMOD
| EQBITOR
| EQBITAND
| EQBITRSH
| EQBITLSH
| EQBITXOR )
expr
;

statement
: path
( procDef
| newline? block
| listDef? EQ <assoc=right> expr)?
| listDef* EQ expr)?
| statVar
;

Expand Down Expand Up @@ -332,7 +332,7 @@ expr
| BITNOT expr
| (INC | DEC) expr
| expr (INC | DEC)
| expr POW <assoc=right> expr
| expr POW expr
| expr (WS? SLASH WS? | MUL | MOD) expr
| expr (PLUS | MINUS) expr
| expr (LT | LTEQ | GT | GTEQ ) expr
Expand Down
4 changes: 2 additions & 2 deletions byond2Preproc.g4 → grammar/Preproc.g4
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
parser grammar byond2Preproc;
parser grammar Preproc;

options
{
tokenVocab = byond2PreprocLexer;
tokenVocab = PreprocLexer;
}

macro
Expand Down
4 changes: 2 additions & 2 deletions byond2PreprocLexer.g4 → grammar/PreprocLexer.g4
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
lexer grammar byond2PreprocLexer;
import byond2WhiteSpace, byond2Common;
lexer grammar PreprocLexer;
import WhiteSpace, Common;

////////////////////////////////////////////////////////////////////////////////
// plain mode
Expand Down
2 changes: 1 addition & 1 deletion byond2WhiteSpace.g4 → grammar/WhiteSpace.g4
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lexer grammar byond2WhiteSpace;
lexer grammar WhiteSpace;

@lexer::members
{
Expand Down
4 changes: 2 additions & 2 deletions byond2ErrorListener.java → src/ErrorListener.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import org.antlr.v4.runtime.*;

class byond2ErrorListener extends BaseErrorListener
class ErrorListener extends BaseErrorListener
{
interface GetSourceName
{
Expand All @@ -9,7 +9,7 @@ interface GetSourceName

private GetSourceName getSourceName;

byond2ErrorListener(GetSourceName sn)
ErrorListener(GetSourceName sn)
{
this.getSourceName = sn;
}
Expand Down
12 changes: 6 additions & 6 deletions byond2MacroEval.java → src/MacroEval.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import org.antlr.v4.runtime.tree.*;
import java.util.ArrayList;

class byond2MacroEval
class MacroEval
{
private String name;

private byond2ErrorListener errorListener;
private ErrorListener errorListener;

byond2MacroEval(byond2ErrorListener el)
MacroEval(ErrorListener el)
{
errorListener = el;
}
Expand All @@ -17,17 +17,17 @@ public String eval(ArrayList<Token> macro)
{
ListTokenSource macroStream = new ListTokenSource(macro);
CommonTokenStream macroTokens = new CommonTokenStream(macroStream);
byond2Preproc parser = new byond2Preproc(macroTokens);
Preproc parser = new Preproc(macroTokens);
//parser.setBuildParseTree(false);
parser.removeErrorListeners();
parser.addErrorListener(errorListener);
//parser.removeParseListeners();
//parser.addParseListener(new byond2MacroListener());
//parser.addParseListener(new MacroListener());
RuleContext tree = parser.macro();

ParseTreeWalker walker = new ParseTreeWalker();

byond2MacroListener listener = new byond2MacroListener();
MacroListener listener = new MacroListener();
walker.walk(listener, tree);

if (listener.result instanceof IncludeRel)
Expand Down
4 changes: 2 additions & 2 deletions byond2MacroListener.java → src/MacroListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class IncludeRel
String name;
}

class byond2MacroListener extends byond2PreprocBaseListener
class MacroListener extends PreprocBaseListener
{
Object result;

@Override
public void enterMacroIncludeRel(byond2Preproc.MacroIncludeRelContext ctx)
public void enterMacroIncludeRel(Preproc.MacroIncludeRelContext ctx)
{
String text = ctx.getText().substring(7);
text = text.replace("\\", "/");
Expand Down
8 changes: 4 additions & 4 deletions Main.java → src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ else if (opt.startsWith("-I"))
cs = new ANTLRInputStream(pipe);
}

byond2Lexer lexer = new byond2Lexer(cs);
DMLexer lexer = new DMLexer(cs);
lexer.removeErrorListeners();
lexer.addErrorListener(new byond2ErrorListener(
lexer.addErrorListener(new ErrorListener(
() -> lexer.getSourceName()));

TokenStream tokens = new CommonTokenStream(lexer);

byond2Parser parser = new byond2Parser(tokens);
parser.setErrorHandler(new byond2ReportError());
DMParser parser = new DMParser(tokens);
parser.setErrorHandler(new ReportError());
parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
parser.setBuildParseTree(optionShowTree);
parser.removeParseListeners();
Expand Down
2 changes: 1 addition & 1 deletion MyParserListener.java → src/MyParserListener.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.antlr.v4.runtime.*;
import java.util.Calendar;

class MyParserListener extends byond2ParserBaseListener
class MyParserListener extends DMParserBaseListener
{
private long inputLength;
private long offset_prev = 0;
Expand Down
12 changes: 6 additions & 6 deletions Preprocessor.java → src/Preprocessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class FileState
File file;
InputStream fs;
long offset;
byond2PreprocLexer lexer;
PreprocLexer lexer;
String name;
static BaseErrorListener errorListener;

Expand All @@ -29,9 +29,9 @@ class FileState
}

// Each lexer store state for every included file
private byond2PreprocLexer lexerFactory()
private PreprocLexer lexerFactory()
{
byond2PreprocLexer lexer = new byond2PreprocLexer(
PreprocLexer lexer = new PreprocLexer(
new UnbufferedCharStream(fs));
lexer.setTokenFactory(new CommonTokenFactory(true));
lexer.removeErrorListeners();
Expand Down Expand Up @@ -71,7 +71,7 @@ class Preprocessor implements Runnable

private ArrayList<String> paths = new ArrayList<String>();

private byond2ErrorListener errorListener = new byond2ErrorListener(
private ErrorListener errorListener = new ErrorListener(
() -> file.name );

Preprocessor(InputStream is) throws IOException
Expand Down Expand Up @@ -135,7 +135,7 @@ private void include(String name)

private void evalMacro()
{
byond2MacroEval e = new byond2MacroEval(errorListener);
MacroEval e = new MacroEval(errorListener);
String name = e.eval(macro);
if (name != null)
{
Expand All @@ -159,7 +159,7 @@ private boolean consume() throws IOException

switch (type)
{
//case byond2PreprocLexer.ID:
//case PreprocLexer.ID:
//token = new CommonToken(token.getType(),
//"[:ID[" + token.getText() + "]:]");

Expand Down
2 changes: 1 addition & 1 deletion byond2ReportError.java → src/ReportError.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import org.antlr.v4.runtime.*;

class byond2ReportError extends DefaultErrorStrategy
class ReportError extends DefaultErrorStrategy
{
public void reportError(Parser recognizer,
RecognitionException e)
Expand Down
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ exec 2>errors.txt

find /media/usb3/Baystation12/Baystation12/code \
-name '*.dm' -type f -print | while read fname; do echo $fname 1>&2; \
java -Xmx512M -cp .:/media/usb3/media/download/\
java -Xmx512M -cp class:/media/usb3/media/download/\
antlr-4.2.1-complete.jar Main "$fname" > /dev/null ; done
4 changes: 2 additions & 2 deletions testf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#java -Xmx512M -cp .:/media/usb3/media/download/antlr-4.2-complete.jar Main $1

java -Xmx768M -cp .:/media/usb3/media/download/antlr-4.2.1-complete.jar Main \
-t -I"/media/usb3/Baystation12/Baystation12" "code/world.dm"
java -Xmx768M -cp class:/media/usb3/media/download/antlr-4.2.1-complete.jar Main \
-I"/media/usb3/Baystation12/Baystation12" "baystation12.dme"
#"/media/usb3/Baystation12/Baystation12/code/world.dm"
#"/media/usb3/byond-port/test.dm"
#"/media/usb3/byond-port/test.pre"

0 comments on commit be81a10

Please sign in to comment.