Base Generator by composant
This commit is contained in:
parent
7565b3ad78
commit
ef587d389f
2 changed files with 258 additions and 0 deletions
85
java.pc
Normal file
85
java.pc
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
annotation(
|
||||||
|
[@]
|
||||||
|
{name}= -> name
|
||||||
|
[(](
|
||||||
|
:end,
|
||||||
|
value() -> val
|
||||||
|
[)]=,
|
||||||
|
:content
|
||||||
|
);
|
||||||
|
|
||||||
|
content:
|
||||||
|
:value -> values
|
||||||
|
[)]=;
|
||||||
|
value:
|
||||||
|
{name}
|
||||||
|
[=]
|
||||||
|
value(
|
||||||
|
:end,
|
||||||
|
[,]
|
||||||
|
:value
|
||||||
|
) -> add(value);
|
||||||
|
|
||||||
|
end:[)]=
|
||||||
|
)
|
||||||
|
|
||||||
|
modifier({modifier}*= -> concat(mod))
|
||||||
|
|
||||||
|
class(
|
||||||
|
annotation(
|
||||||
|
:mod,
|
||||||
|
:class
|
||||||
|
),
|
||||||
|
mod:modifier(
|
||||||
|
:class
|
||||||
|
),
|
||||||
|
class:[class],
|
||||||
|
type(
|
||||||
|
:end,
|
||||||
|
:implements,
|
||||||
|
:extends
|
||||||
|
) -> name;
|
||||||
|
implements:[implements](
|
||||||
|
imp:type() -> add(implement)(
|
||||||
|
[,]
|
||||||
|
:imp,
|
||||||
|
:end
|
||||||
|
)
|
||||||
|
)
|
||||||
|
extends:[extends](
|
||||||
|
type() -> extend(
|
||||||
|
:implements,
|
||||||
|
:end
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
end:[{]=
|
||||||
|
)
|
||||||
|
|
||||||
|
import(
|
||||||
|
[import](
|
||||||
|
:static,
|
||||||
|
:normal
|
||||||
|
);
|
||||||
|
static:[static](
|
||||||
|
:normal
|
||||||
|
);
|
||||||
|
normal:[!;]* -> concat(import)
|
||||||
|
[;]=;
|
||||||
|
|
||||||
|
import,
|
||||||
|
class
|
||||||
|
)
|
||||||
|
|
||||||
|
package(
|
||||||
|
[package]
|
||||||
|
[!;]* -> concat(package)
|
||||||
|
[;]=;
|
||||||
|
|
||||||
|
import,
|
||||||
|
class
|
||||||
|
)
|
||||||
|
|
||||||
|
main(
|
||||||
|
package
|
||||||
|
)
|
|
@ -0,0 +1,173 @@
|
||||||
|
package be.jeffcheasey88.peeratcode.parser.state.generator;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.Parser;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.TokenType;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.Tokenizer;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.state.RedirectStateTree;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.state.StateTree;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.state.generator.ParserComposantGenerator.Element.SynthaxeComposant;
|
||||||
|
|
||||||
|
public class ParserComposantGenerator {
|
||||||
|
|
||||||
|
private BufferedReader reader;
|
||||||
|
|
||||||
|
public ParserComposantGenerator(BufferedReader reader){
|
||||||
|
this.reader = reader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void generate() throws Exception{
|
||||||
|
SynthaxeComposant synthax = load();
|
||||||
|
}
|
||||||
|
|
||||||
|
private SynthaxeComposant load() throws Exception{
|
||||||
|
SynthaxeComposant composant = new SynthaxeComposant();
|
||||||
|
Parser<Element> parser = new Parser<Element>(){
|
||||||
|
{
|
||||||
|
StateTree<Element> validator = new StateTree<>();
|
||||||
|
StateTree<Element> modifiers = new StateTree<>();
|
||||||
|
modifiers.end(null);
|
||||||
|
StateTree<Element> end = modifiers.then((v) -> v.validate(
|
||||||
|
(t) -> t.getValue().equals("="),
|
||||||
|
(bag,t) -> bag.set("end", true)));
|
||||||
|
StateTree<Element> loop = modifiers.then((v) -> v.validate(
|
||||||
|
(t) -> t.getValue().equals("*"),
|
||||||
|
(bag,t) -> bag.set("loop", true)));
|
||||||
|
loop.then(end);
|
||||||
|
loop.end(null);
|
||||||
|
end.end(null);
|
||||||
|
|
||||||
|
StateTree<Element> simpleAction = validator
|
||||||
|
.then((v) -> v.validate((t) -> t.getValue().equals("[")))
|
||||||
|
.then((v) -> v.validate((t) -> true, (bag, t) -> bag.set(t)))
|
||||||
|
.then((v) -> v.validate((t) -> t.getValue().equals("]")));
|
||||||
|
StateTree<Element> customAction = validator
|
||||||
|
.then((v) -> v.validate((t) -> t.getValue().equals("{")))
|
||||||
|
.then((v) -> v.validate((t) -> true, (bag, t) -> bag.set(t)))
|
||||||
|
.then((v) -> v.validate((t) -> t.getValue().equals("}")));
|
||||||
|
simpleAction.then(modifiers);
|
||||||
|
customAction.then(modifiers);
|
||||||
|
|
||||||
|
StateTree<Element> namedValidator = new StateTree<>();
|
||||||
|
StateTree<Element> leftSide = namedValidator
|
||||||
|
.then(new RedirectStateTree<>(validator, (bag) -> "validator"))
|
||||||
|
.then((v) -> v.validate((t) -> t.getValue().equals("-")) && v.validate((t) -> t.getValue().equals(">")))
|
||||||
|
.then((v) -> v.validate(
|
||||||
|
(t) -> t.getType().equals(TokenType.NAME),
|
||||||
|
(bag, t) -> bag.set(t)));
|
||||||
|
leftSide.end(null);
|
||||||
|
|
||||||
|
StateTree<Element> redirection = new StateTree<>();
|
||||||
|
redirection.then((v) -> v.validate((t) -> t.getType().equals(TokenType.NAME)));
|
||||||
|
|
||||||
|
StateTree<Element> main = new StateTree<>();
|
||||||
|
|
||||||
|
StateTree<Element> composant = main.then((v) -> v.validate(
|
||||||
|
(token) -> token.getType().equals(TokenType.NAME),
|
||||||
|
(bag, token) -> bag.set("name", token)
|
||||||
|
));
|
||||||
|
|
||||||
|
setTokenizer(new Tokenizer());
|
||||||
|
setStateTree(main);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return composant;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Element{
|
||||||
|
|
||||||
|
public Element(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SynthaxeComposant extends Element{
|
||||||
|
|
||||||
|
private List<Composant> composants;
|
||||||
|
|
||||||
|
public SynthaxeComposant(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class Composant extends Element{
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
private List<Element> path;
|
||||||
|
private List<Element> declared;
|
||||||
|
private List<Element> next;
|
||||||
|
|
||||||
|
public Composant(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Validator extends Element{
|
||||||
|
|
||||||
|
private String action;
|
||||||
|
private boolean end;
|
||||||
|
private boolean loop;
|
||||||
|
|
||||||
|
public Validator(){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class NamedValidator extends Validator{
|
||||||
|
|
||||||
|
private String logic;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public NamedValidator(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Redirection extends Element{
|
||||||
|
|
||||||
|
private String target;
|
||||||
|
|
||||||
|
public Redirection(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class NamedRedirection extends Redirection{
|
||||||
|
|
||||||
|
private String logic;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public NamedRedirection(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ComposantCall extends Element{
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public ComposantCall(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class NamedComposantCall extends ComposantCall{
|
||||||
|
|
||||||
|
private String logic;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public NamedComposantCall(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue