From cb707e2942860976af350630dc6db6e7693c098b Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Thu, 14 Mar 2024 12:35:21 +0100 Subject: [PATCH] fixed errors in Dot grammar --- src/org/rascalmpl/library/lang/dot/Dot.rsc | 37 ++++---- .../rascalmpl/library/lang/dot/syntax/Dot.rsc | 93 +++++++++---------- src/org/rascalmpl/library/util/Test.rsc | 2 - src/org/rascalmpl/library/util/Webserver.rsc | 1 - 4 files changed, 60 insertions(+), 73 deletions(-) diff --git a/src/org/rascalmpl/library/lang/dot/Dot.rsc b/src/org/rascalmpl/library/lang/dot/Dot.rsc index 65d7d83ee49..9d731bf486c 100644 --- a/src/org/rascalmpl/library/lang/dot/Dot.rsc +++ b/src/org/rascalmpl/library/lang/dot/Dot.rsc @@ -12,23 +12,20 @@ import String; import Set; import Map; -public alias Id = str; +alias Id = str; @synopsis{Abstract Data Type of Dot language} +data DotGraph = graph(Id id, Stms stmts) | digraph(Id id, Stms stmts); -public data DotGraph = graph(Id id, Stms stmts) | digraph(Id id, Stms stmts); +alias Stms = list[Stm]; -public alias Stms = list[Stm]; +alias NodeId = tuple[Id, PortId]; -public alias NodeId = tuple[Id, PortId]; +alias PortId = tuple[Id, CompassPt]; -public alias PortId = tuple[Id, CompassPt]; +data CompassPt = N()|NE()|E()|SE()|S()|SW()|W()|NW()|C()|_(); -public data CompassPt = N()|NE()|E()|SE()|S()|SW()|W()|NW()|C()|_(); - - - -public data Stm +data Stm = N(Id id, Attrs attrs) | N(Id id) | N(NodeId nid, Attrs attrs) @@ -59,30 +56,30 @@ public data Stm | EDGE(Attrs attrs) ; -public alias Attr = tuple[str prop, Id val]; +alias Attr = tuple[str prop, Id val]; -public alias Attrs = list[Attr]; +alias Attrs = list[Attr]; -public alias Outline = map[int key, list[str] args]; +alias Outline = map[int key, list[str] args]; -public alias Dotline = tuple[DotGraph graph, Outline outline]; +alias Dotline = tuple[DotGraph graph, Outline outline]; @synopsis{Dummy function call needed to tag initialized global variables of type DotGraph. It is possible to select that variable on the outline menu of the Rascal Editor. An application is for example to display dotgraphs.} -public DotGraph export(DotGraph g) {return g;} +DotGraph export(DotGraph g) {return g;} -public Dotline export(Dotline g) {return g;} +Dotline export(Dotline g) {return g;} -public bool hasOutline(Dotline _) {return true;} +bool hasOutline(Dotline _) {return true;} -public bool hasOutline(DotGraph _) {return false;} +bool hasOutline(DotGraph _) {return false;} -public Outline currentOutline; +Outline currentOutline; -public void setCurrentOutline(Dotline current) { +void setCurrentOutline(Dotline current) { currentOutline = current.outline; } diff --git a/src/org/rascalmpl/library/lang/dot/syntax/Dot.rsc b/src/org/rascalmpl/library/lang/dot/syntax/Dot.rsc index a1da8c18d51..7fcf9b98ca7 100644 --- a/src/org/rascalmpl/library/lang/dot/syntax/Dot.rsc +++ b/src/org/rascalmpl/library/lang/dot/syntax/Dot.rsc @@ -9,29 +9,47 @@ module lang::dot::\syntax::Dot -start syntax DOT = LAYOUT* Graph Id "{" StatementList "}" "\n"?; - -keyword Reserved = "graph"|"digraph"|"node"|"edge"|"subgraph"; - -syntax Graph = "graph"|"digraph"|AttrTag; - -syntax AttrTag = "node"|"edge"|"graph"; - -syntax Nod = NodeId|Subgraph; - -lexical Id = ([A-Z a-z 0-9 _] !<< [A-Z a-z 0-9 _]+ !<< [a-z A-Z 0-9 _][a-z A-Z 0-9 _]* !>> [0-9 A-Z _ a-z]) \ Reserved - | [\"] (![\"] | "\\\"")* [\"] - | [\-]? "." [0-9]+ - | [\-]? [0-9]+ "." [0-9]* - ; +start syntax DOT = Graph Id "{" StatementList "}" "\n"?; + +keyword Reserved + = "graph" + | "digraph" + | "node" + | "edge" + | "subgraph" + ; + +syntax Graph + = "graph" + | "digraph" + | AttrTag + ; + +syntax AttrTag + = "node" + | "edge" + | "graph" + ; + +syntax Nod + = NodeId + | Subgraph + ; + +lexical Id + = ([A-Z a-z 0-9 _] !<< [a-z A-Z 0-9 _][a-z A-Z 0-9 _]* !>> [0-9 A-Z _ a-z]) \ Reserved + | [\"] (![\"] | "\\\"")* [\"] + | [\-]? "." [0-9]+ + | [\-]? [0-9]+ "." [0-9]* + ; syntax StatementList = StatementOptional*; - -syntax Statement = NodeStatement - |EdgeStatement - |AttrStatement - >Id "=" Id - ; +syntax Statement + = NodeStatement + | EdgeStatement + | AttrStatement + | Id "=" Id + ; syntax StatementOptional = Statement ";"?; @@ -45,9 +63,10 @@ syntax EdgeOp = "-\>" | "--"; syntax EdgeRhs = Edg+; -syntax NodeId = Id - | Id Port - ; +syntax NodeId + = Id + | Id Port + ; syntax Port = ":" Id Id? // | ":" Id @@ -77,29 +96,3 @@ layout LAYOUTLIST = LAYOUT* !>> [\ \t\n\r] !>> "//" !>> "/*" lexical LAYOUT = Whitespace: [\ \t\n\r] | @category="Comment" Comment ; - - -/* -graph : [ strict ] (graph | digraph) [ ID ] '{' stmt_list '}' - - -stmt_list : [ stmt [ ';' ] [ stmt_list ] ] -stmt : node_stmt - | edge_stmt - | attr_stmt - | ID '=' ID - | subgraph - - -attr_stmt : (graph | node | edge) attr_list -attr_list : '[' [ a_list ] ']' [ attr_list ] -a_list : ID [ '=' ID ] [ ',' ] [ a_list ] -edge_stmt : (node_id | subgraph) edgeRHS [ attr_list ] -edgeRHS : edgeop (node_id | subgraph) [ edgeRHS ] -node_stmt : node_id [ attr_list ] -node_id : ID [ port ] -port : ':' ID [ ':' compass_pt ] - | ':' compass_pt -subgraph : [ subgraph [ ID ] ] '{' stmt_list '}' -compass_pt : (n | ne | e | se | s | sw | w | nw | c | _) -*/ diff --git a/src/org/rascalmpl/library/util/Test.rsc b/src/org/rascalmpl/library/util/Test.rsc index 37924c77f77..2c3097775af 100644 --- a/src/org/rascalmpl/library/util/Test.rsc +++ b/src/org/rascalmpl/library/util/Test.rsc @@ -12,8 +12,6 @@ with tests, but also to query larger volumes of failing tests. } module util::Test -extend Message; - data TestResult = \testResult(str name, bool success, loc src, str message = "", list[value] exceptions = []); @synopsis{Run all tests for the given module name} diff --git a/src/org/rascalmpl/library/util/Webserver.rsc b/src/org/rascalmpl/library/util/Webserver.rsc index c82165ece9a..fe1bdf007a9 100644 --- a/src/org/rascalmpl/library/util/Webserver.rsc +++ b/src/org/rascalmpl/library/util/Webserver.rsc @@ -2,7 +2,6 @@ module util::Webserver extend Content; -import IO; @javaClass{org.rascalmpl.library.util.Webserver} java void serve(loc server, Response (Request) callback, bool asDaemon = true);