Commit 254965d3 authored by Custom2043's avatar Custom2043
Browse files

gne

parent c1807e2c
No preview for this file type
JMP TODO :
All token :
truc * truc
Not token :
truc !truc truc
si aucun token n'est trouvé, ne passe pas
!"az"
lit 2 caractère
& array
{ truc&}
=> { !truc } truc
ignores :
truc ignore truc
force an ignore
truc name:[ignore] truc
name an ignore
truc !ignore truc
no ignore here
\ No newline at end of file
package compiler; package compiler;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import javax.tools.SimpleJavaFileObject;
import parser.ParserString; import parser.ParserString;
import parser.Token; import parser.Token;
import tokens.*; import tokens.*;
...@@ -28,7 +34,6 @@ public class Compiler ...@@ -28,7 +34,6 @@ public class Compiler
"ArraySearch", "BracketSearch", "Builder", "OptionalSearch", "OrSearch", "ParserString", "Result", "Search" "ArraySearch", "BracketSearch", "Builder", "OptionalSearch", "OrSearch", "ParserString", "Result", "Search"
}; };
private static boolean continu, enabled; private static boolean continu, enabled;
private static List<Info> infos; private static List<Info> infos;
static List<HashMap<String, SearchNameMemory>> linesPaths; static List<HashMap<String, SearchNameMemory>> linesPaths;
...@@ -94,7 +99,7 @@ public class Compiler ...@@ -94,7 +99,7 @@ public class Compiler
if (continu) if (continu)
Generator.generate(lines); Generator.generate(lines);
} }
private static HashMap<String, SearchNameMemory> compileLine(Line currentLine, List<Line> lines) private static HashMap<String, SearchNameMemory> compileLine(Line currentLine, List<Line> lines)
{ {
boolean first = true; boolean first = true;
...@@ -291,3 +296,18 @@ class SearchNameMemory ...@@ -291,3 +296,18 @@ class SearchNameMemory
return t; return t;
} }
} }
class JavaSourceFromFile extends SimpleJavaFileObject
{
public JavaSourceFromFile(File file)
{
super(file.toURI(), Kind.SOURCE);
}
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException
{
return new String(Files.readAllBytes(Paths.get(this.toUri())));
}
}
...@@ -9,6 +9,7 @@ import java.io.FileOutputStream; ...@@ -9,6 +9,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import main.Main; import main.Main;
...@@ -42,6 +43,7 @@ public class Generator ...@@ -42,6 +43,7 @@ public class Generator
* The repertory containing parser and tokens packages * The repertory containing parser and tokens packages
*/ */
private static String outputDirectory; private static String outputDirectory;
public static LinkedList<String> generatedClasses = new LinkedList<>();
public static void generate(List<Line> lines) public static void generate(List<Line> lines)
{ {
try try
...@@ -60,6 +62,7 @@ public class Generator ...@@ -60,6 +62,7 @@ public class Generator
String ss = new String(getContentFromClass("parser/"+s+".java", true)); String ss = new String(getContentFromClass("parser/"+s+".java", true));
fos.write(ss.replace("parser;", Main.pack+"parser;").getBytes()); fos.write(ss.replace("parser;", Main.pack+"parser;").getBytes());
fos.close(); fos.close();
generatedClasses.add(outputDirectory + "/" + "parser/"+s+".java");
} }
int i=0; int i=0;
...@@ -89,10 +92,11 @@ public class Generator ...@@ -89,10 +92,11 @@ public class Generator
if (f.exists()) if (f.exists())
prepareToFill(false, "tokens/"+l.header.id.getName()+".java", ClassGenerator.getTokenString(l, lines, lineIndex, true)); prepareToFill(false, "tokens/"+l.header.id.getName()+".java", ClassGenerator.getTokenString(l, lines, lineIndex, true));
else else
{ {
OutputStream out = new BufferedOutputStream(new FileOutputStream(outputDirectory+"/tokens/"+l.header.id.getName()+".java")); OutputStream out = new BufferedOutputStream(new FileOutputStream(outputDirectory+"/tokens/"+l.header.id.getName()+".java"));
out.write(ClassGenerator.getTokenString(l, lines, lineIndex, false).getBytes()); out.write(ClassGenerator.getTokenString(l, lines, lineIndex, false).getBytes());
out.close(); out.close();
Generator.generatedClasses.add(outputDirectory+"/tokens/"+l.header.id.getName()+".java");
} }
} }
...@@ -171,6 +175,7 @@ public class Generator ...@@ -171,6 +175,7 @@ public class Generator
out.write(previousContent, end + ending.length(), previousContent.length - end - ending.length()); out.write(previousContent, end + ending.length(), previousContent.length - end - ending.length());
out.close(); out.close();
generatedClasses.add(outputDirectory+"/"+path);
} }
public static String getLineJump() public static String getLineJump()
{ {
......
...@@ -32,7 +32,6 @@ public class IgnoreGenerator ...@@ -32,7 +32,6 @@ public class IgnoreGenerator
ignoreBuilder.append(","); ignoreBuilder.append(",");
ignoreBuilder.append(Generator.getLineJump()); ignoreBuilder.append(Generator.getLineJump());
} }
public static String getString() public static String getString()
{ {
......
...@@ -23,6 +23,9 @@ public class ParserStringGenerator ...@@ -23,6 +23,9 @@ public class ParserStringGenerator
public static int generateParserString(StringToken s, String name, int lineIndex) public static int generateParserString(StringToken s, String name, int lineIndex)
{ {
if (name != null && name.equals("ignore"))
name = null;
Token[] charTokens = s.charTokens == null ? new Token[]{s.singleChar} : s.charTokens; Token[] charTokens = s.charTokens == null ? new Token[]{s.singleChar} : s.charTokens;
ParserCharacter[] chars = new ParserCharacter[charTokens.length]; ParserCharacter[] chars = new ParserCharacter[charTokens.length];
LinkedList<Integer> charIndexes = new LinkedList<>(); LinkedList<Integer> charIndexes = new LinkedList<>();
......
...@@ -10,7 +10,7 @@ import parser.Parser; ...@@ -10,7 +10,7 @@ import parser.Parser;
public class Main public class Main
{ {
public static String languageFile, pack = "", srcDest, vis = "public"; public static String languageFile, pack = "", srcDest, vis = "public", test = null;
public static void main(String[] args) throws Exception public static void main(String[] args) throws Exception
{ {
readCommand(args); readCommand(args);
......
...@@ -166,7 +166,7 @@ public class Parser ...@@ -166,7 +166,7 @@ public class Parser
if (Parser.moreToRead()) if (Parser.moreToRead())
correct = ParserString.getString(stringIndex)[indexCheck].isCharCorrect(Parser.read()); correct = ParserString.getString(stringIndex)[indexCheck].isCharCorrect(Parser.read());
else else
correct = ParserString.getString(stringIndex)[indexCheck].isOpposite(); correct = ParserString.getString(stringIndex)[indexCheck] == ParserCharacter.none;
if (!correct) if (!correct)
break; break;
......
...@@ -163,8 +163,8 @@ public class TokenBuilder extends Builder ...@@ -163,8 +163,8 @@ public class TokenBuilder extends Builder
} }
else else
{ {
if (results[position] == null) if (results[position].getArray() == null)
ignoredResults.add(null); ignoredResults.add(new Result(this.ignore.getRealSearch(), new Result[0]));
else else
ignoredResults.add(results[position].getArray()[0]); ignoredResults.add(results[position].getArray()[0]);
} }
......
quote = "\""
singleQuote = "\'"
backslash = "\\"
#NumberChar = "0" (base:"b" {value:'0-1'})|(base:"x" {value:'0-9|A-F'})|(base:"d" {value:digit})
#SingleChar = (backslash backslash:("b"|"r"|"t"|"n"|backslash|quote|singleQuote)) | anyChar
CharacterToken = singleQuote [notToken:notToken] {|orToken character1:(NumberChar|SingleChar) ["-" character2:(NumberChar|SingleChar)]} singleQuote
StringToken = (quote {charTokens:(CharacterToken | SingleChar)} quote) | singleChar:CharacterToken
letter = 'a-z|A-Z'
digit = '0-9'
exprOpen = "("
exprClose = ")"
optionOpen = "["
optionClose = "]"
arrayOpen = "{"
arrayClose = "}"
notToken = "!"
orToken = "|"
transientToken = "#"
equals = "="
Jump = "\r\n"|"\r"|"\n"
Space = " "|"\t"
Identifier = firstLetter:letter [{idName:(letter|digit)}]
ignore = {Space|Jump}
SearchName = id:Identifier ":"
LineHeader = [trans:transientToken] id:Identifier equals
TokenSearchToken = ([trans:transientToken] id:Identifier)|string:StringToken|any:"*"
ArraySearchToken = [{minSize:digit} "-"] arrayOpen [orToken left:SearchToken] {searches:SearchToken} [right:SearchToken orToken] arrayClose ["-" {maxSize:digit}]
OptionalSearchToken = optionOpen {searches:SearchToken} optionClose
BracketSearchToken = exprOpen {searches:SearchToken} exprClose
OrSearchToken = 2-{searches:#SearchToken orToken|}
#SearchToken = ([searchName:SearchName] searchToken:(TokenSearchToken|ArraySearchToken|OptionalSearchToken|BracketSearchToken)) | searchToken:OrSearchToken
Line = header:LineHeader {searchTokens:SearchToken}
anyChar = '*'
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment