X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.graphviz%2Fsrc%2Forg%2Fsimantics%2Fgraphviz%2Finternal%2Fparser%2FDotParser.jj;h=6b2766cb2a316f51ec2252658e7ec11e418427df;hb=131be5c413e1f9dc652b6b46c763625b30ad8350;hp=8ea0a84ed5c870e9f0e82105a2e7c651a2872875;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.graphviz/src/org/simantics/graphviz/internal/parser/DotParser.jj b/bundles/org.simantics.graphviz/src/org/simantics/graphviz/internal/parser/DotParser.jj index 8ea0a84ed..6b2766cb2 100644 --- a/bundles/org.simantics.graphviz/src/org/simantics/graphviz/internal/parser/DotParser.jj +++ b/bundles/org.simantics.graphviz/src/org/simantics/graphviz/internal/parser/DotParser.jj @@ -1,76 +1,76 @@ -options { - JDK_VERSION = "1.6"; - STATIC = false; - IGNORE_CASE = true; -} - -PARSER_BEGIN(DotParser) -package org.simantics.graphviz.internal.parser; - -import org.simantics.graphviz.*; -import java.util.Map; -import java.util.HashMap; - -public class DotParser { - AbstractAttributeContainer defaultNode = new AbstractAttributeContainer(); - AbstractAttributeContainer defaultEdge = new AbstractAttributeContainer(); - Map connectors = new HashMap(); - -} -PARSER_END(DotParser) - -/*** Lexer *********************************************************/ - -SKIP: -{ -| -| -} - -TOKEN: -{ "=" | "->" | "--" | ":" | "{" | "}" | "[" | "]" | "," -| "subgraph" | "digraph" | "graph" | "node" | "edge" | "strict" | ";" -| - { matchedToken.image = matchedToken.image.substring(1,matchedToken.image.length()-1); } -| "] | "<" (~["<",">","\""] | "\"" (~["\"", "\\"] | "\\" ~[])* "\"")* ">" )* ">"> -| -| -} - -/*** Parser ********************************************************/ - -Graph document() : { Graph graph = new Graph(); } -{ ("strict")? ("graph" | "digraph") "{" (statement(graph))* "}" { return graph; } -} - -void statement(IGraph graph) : {} -{ { String id1, id2; } - id1=id() ( LOOKAHEAD(1) - { Node node = new Node(graph); connectors.put(id1, node); } attributes(node) - | "->" id2=id() { - Edge edge = new Edge(connectors.get(id1.split(":")[0]), - connectors.get(id2.split(":")[0])); - } attributes(edge) - ) -| "graph" attributes(graph) -| "node" attributes(defaultNode) -| "edge" attributes(defaultEdge) -| { Subgraph subgraph; String id; } - "subgraph" id=id() { subgraph = new Subgraph(graph); connectors.put(id, subgraph); } - "{" (statement(subgraph))* "}" -} - -void attributes(IAttributeContainer el) : {} -{ ("[" attribute(el) ( (",")? attribute(el) )* "]")? ";" {} -} - -void attribute(IAttributeContainer el) : { String key, value=""; } -{ key=id() ("=" value=id())? { el.set(key, value); } -} - -String id() : {} -{ { return token.image; } -| { return token.image; } -| { return token.image; } -| { return token.image; } +options { + JDK_VERSION = "1.6"; + STATIC = false; + IGNORE_CASE = true; +} + +PARSER_BEGIN(DotParser) +package org.simantics.graphviz.internal.parser; + +import org.simantics.graphviz.*; +import java.util.Map; +import java.util.HashMap; + +public class DotParser { + AbstractAttributeContainer defaultNode = new AbstractAttributeContainer(); + AbstractAttributeContainer defaultEdge = new AbstractAttributeContainer(); + Map connectors = new HashMap(); + +} +PARSER_END(DotParser) + +/*** Lexer *********************************************************/ + +SKIP: +{ +| +| +} + +TOKEN: +{ "=" | "->" | "--" | ":" | "{" | "}" | "[" | "]" | "," +| "subgraph" | "digraph" | "graph" | "node" | "edge" | "strict" | ";" +| + { matchedToken.image = matchedToken.image.substring(1,matchedToken.image.length()-1); } +| "] | "<" (~["<",">","\""] | "\"" (~["\"", "\\"] | "\\" ~[])* "\"")* ">" )* ">"> +| +| +} + +/*** Parser ********************************************************/ + +Graph document() : { Graph graph = new Graph(); } +{ ("strict")? ("graph" | "digraph") "{" (statement(graph))* "}" { return graph; } +} + +void statement(IGraph graph) : {} +{ { String id1, id2; } + id1=id() ( LOOKAHEAD(1) + { Node node = new Node(graph); connectors.put(id1, node); } attributes(node) + | "->" id2=id() { + Edge edge = new Edge(connectors.get(id1.split(":")[0]), + connectors.get(id2.split(":")[0])); + } attributes(edge) + ) +| "graph" attributes(graph) +| "node" attributes(defaultNode) +| "edge" attributes(defaultEdge) +| { Subgraph subgraph; String id; } + "subgraph" id=id() { subgraph = new Subgraph(graph); connectors.put(id, subgraph); } + "{" (statement(subgraph))* "}" +} + +void attributes(IAttributeContainer el) : {} +{ ("[" attribute(el) ( (",")? attribute(el) )* "]")? ";" {} +} + +void attribute(IAttributeContainer el) : { String key, value=""; } +{ key=id() ("=" value=id())? { el.set(key, value); } +} + +String id() : {} +{ { return token.image; } +| { return token.image; } +| { return token.image; } +| { return token.image; } } \ No newline at end of file