Skip to content

Commit 2bef188

Browse files
committed
added a FaR analyzer
1 parent 95a76f6 commit 2bef188

File tree

1 file changed

+73
-3
lines changed

1 file changed

+73
-3
lines changed
Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,76 @@
11
package org.polystat.cli
2+
3+
import cats.effect.Sync
4+
import cats.effect.IO
5+
import fs2.io.file.Path
6+
import higherkindness.droste.data.Fix
27
import org.polystat.far.FaR
8+
import org.polystat.odin.analysis.ASTAnalyzer
9+
import org.polystat.odin.analysis.EOOdinAnalyzer.OdinAnalysisResult
10+
import org.polystat.odin.core.ast.EOExpr
11+
import org.polystat.odin.core.ast.EOProg
12+
import org.eolang.parser.Syntax
13+
import org.eolang.parser.Xsline
14+
import org.eolang.parser.Spy
15+
import org.cactoos.io.OutputTo
16+
import org.cactoos.io.InputOf
17+
import org.cactoos.Func
18+
import com.jcabi.xml.XMLDocument
19+
import com.jcabi.xml.XML
20+
import org.polystat.cli.InputUtils.replaceExt
21+
import java.nio.file.Path as JPath
22+
import scala.jdk.CollectionConverters.*
23+
24+
object Far:
25+
26+
private def program(xml: JPath): Func[String, XML] = new Func[String, XML]:
27+
def apply(locator: String): XML =
28+
val parts = locator.split("\\.")
29+
val name = parts(1)
30+
var obj: XML =
31+
new XMLDocument(xml).nodes("/program/objects").get(0)
32+
33+
for idx <- 1 until parts.length do
34+
val objs = obj.nodes(s"o[@name='${parts(idx)}']")
35+
obj = objs.get(0);
36+
37+
obj
38+
39+
def runFar(pathToXml: JPath)(
40+
locator: String
41+
): IO[java.util.Collection[String]] =
42+
IO.delay(new FaR().errors(program(pathToXml), locator))
43+
44+
def analyze(pathToTmpDir: Path)(
45+
pathToCode: Path
46+
): IO[OdinAnalysisResult] =
47+
val codeFileName: Path = pathToCode.fileName
48+
val codeFileNameNoExt: String =
49+
codeFileName.toString.splitAt(codeFileName.toString.indexOf("."))._1
50+
val pathToXml: JPath =
51+
(pathToTmpDir / codeFileName.replaceExt(".xml")).toNioPath
52+
println(pathToXml)
353

4-
object Far {
5-
6-
}
54+
for
55+
// parse EO to XMIR
56+
_ <- IO.delay(
57+
new Syntax(
58+
codeFileNameNoExt,
59+
new InputOf(pathToCode.toNioPath),
60+
new OutputTo(pathToXml),
61+
).parse()
62+
)
63+
// run XSLT stuff
64+
_ <- IO.delay(
65+
new Xsline(
66+
new XMLDocument(pathToXml),
67+
new OutputTo(pathToXml),
68+
new Spy.None(),
69+
).pass()
70+
)
71+
errors <- runFar(pathToXml)("Q." + codeFileNameNoExt)
72+
.handleErrorWith(_ =>
73+
runFar(pathToXml)("Q.class__" + codeFileNameNoExt)
74+
)
75+
result = OdinAnalysisResult.fromErrors("FaR")(errors.asScala.toList)
76+
yield result

0 commit comments

Comments
 (0)