Package org.eolang.parser
Class EoSyntax
- java.lang.Object
-
- org.eolang.parser.EoSyntax
-
public final class EoSyntax extends Object
Syntax parser that converts EO code to XMIR (XML-based Intermediate Representation) using ANTLR4. EoSyntax parses EO source code, generates a structured XML representation, and applies a series of transformations to produce canonical XMIR.The parsing process includes lexical analysis, syntax analysis, and XML transformation: 1. EO code is first processed by the EoIndentLexer 2. Then parsed by ANTLR-generated parser 3. Finally transformed into XMIR through a series of XSL transformations
Usage examples:
1. Parse EO code from a string:
XML xmir = new EoSyntax("my-program", "[args] > app\n 42 > @").parsed();
2. Parse EO code from a file:
XML xmir = new EoSyntax( "fibonacci", new InputOf(new File("src/main/eo/fibonacci.eo")) ).parsed();
3. Parse with custom transformations:
XML xmir = new EoSyntax( "custom-transform", "[x] > f\n x > @", new TrClasspath<>( "/org/eolang/parser/pack/validation.xsl", "/org/eolang/parser/pack/transform.xsl" ) ).parsed();
After parsing, errors can be found in the XML at the "/program/errors" XPath. If no errors are present, the parsed program is valid EO code.
- Since:
- 0.1
-
-
Constructor Summary
Constructors Constructor Description EoSyntax(String ipt)
Ctor.EoSyntax(String nme, String ipt)
Ctor.EoSyntax(String nme, String ipt, com.yegor256.xsline.Train<com.yegor256.xsline.Shift> transform)
Ctor.EoSyntax(String nme, org.cactoos.Input ipt)
Ctor.EoSyntax(org.cactoos.Input ipt)
Ctor.
-
-
-
Constructor Detail
-
EoSyntax
public EoSyntax(org.cactoos.Input ipt)
Ctor.- Parameters:
ipt
- The EO program to parse
-
EoSyntax
public EoSyntax(String ipt)
Ctor.- Parameters:
ipt
- The EO program to parse
-
EoSyntax
public EoSyntax(String nme, String ipt)
Ctor.- Parameters:
nme
- The name of the EO program being parsedipt
- The EO program to parse
-
EoSyntax
public EoSyntax(String nme, String ipt, com.yegor256.xsline.Train<com.yegor256.xsline.Shift> transform)
Ctor.- Parameters:
nme
- The name of the EO program being parsedipt
- The EO program to parsetransform
- Transform XMIR after parsing
-
EoSyntax
public EoSyntax(String nme, org.cactoos.Input ipt)
Ctor.- Parameters:
nme
- The name of the EO program being parsedipt
- The EO program to parse
-
-
Method Detail
-
parsed
public com.jcabi.xml.XML parsed() throws IOException
Compile it to XML and save.No exception will be thrown if the syntax is invalid. In any case, XMIR will be generated and saved. Read it in order to find the errors, at /program/errors XPath.
- Returns:
- Parsed XML
- Throws:
IOException
- If fails
-
-