Package org.eolang.parser
Class EoSyntax
java.lang.Object
org.eolang.parser.EoSyntax
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("[args] > app\n 42 > @").parsed();
2. Parse EO code from a file:
XML xmir = new EoSyntax(
new InputOf(new File("src/main/eo/fibonacci.eo"))
).parsed();
3. Parse with custom transformations:
XML xmir = new EoSyntax(
"[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 "/object/errors" XPath. If no errors are present, the parsed program is valid EO code.
- Since:
- 0.1
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
EoSyntax
Ctor.- Parameters:
ipt- The EO program to parse
-
EoSyntax
Ctor.- Parameters:
ipt- The EO program to parsetransform- Transform XMIR after parsing
-
EoSyntax
public EoSyntax(org.cactoos.Input ipt) Ctor.- Parameters:
ipt- The EO program to parse
-
-
Method Details
-
parsed
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 /object/errors XPath.
- Returns:
- Parsed XML
- Throws:
IOException- If fails
-