Class PhiSyntax
- java.lang.Object
-
- org.eolang.parser.PhiSyntax
-
public final class PhiSyntax extends Object
Syntax parser that converts Phi-calculus notation to XMIR (XML-based Intermediate Representation) using ANTLR4. PhiSyntax parses Phi-calculus code and transforms it into structured XML that represents the program in a normalized form.The Phi-calculus is a formal model of computation that serves as the theoretical foundation for the EO language. This parser converts Phi-calculus notation with its specialized symbols (like ⟦, ⟧, ↦, ⤍, etc.) into XMIR that can be further processed.
The parsing process includes lexical analysis, syntax analysis, and XML transformations: 1. Phi code is tokenized by the PhiLexer 2. Then parsed by the ANTLR-generated PhiParser 3. Finally transformed into canonical XMIR through a series of XSL transformations
Usage examples:
1. Parse basic Phi-calculus notation:
XML xmir = new PhiSyntax("{⟦obj ↦ ⟦x ↦ Φ.org.eolang.int⟧⟧}").parsed();
2. Parse with a program name and add extra directives:
XML xmir = new PhiSyntax( "factorial", () -> "{⟦fact ↦ ⟦n ↦ Φ.org.eolang.int⟧⟧}", new Directives().xpath("/program").attr("version", "1.0") ).parsed();
3. Parse with custom transformations:
XML xmir = new PhiSyntax( "{⟦x ↦ ⟦y ↦ Φ.org.eolang.float⟧⟧}", new TrClasspath<>( "/org/eolang/parser/unphi/specialized-transform.xsl" ) ).parsed();
After parsing, any syntax errors can be found in the XML at the "/program/errors" XPath. If no errors are present, the parsed program is valid Phi-calculus notation.
- Since:
- 0.34.0
-
-
Constructor Detail
-
PhiSyntax
public PhiSyntax(String input)
Ctor for the tests.- Parameters:
input
- Input
-
PhiSyntax
public PhiSyntax(org.cactoos.Text input)
Ctor for the tests.- Parameters:
input
- Input
-
-
Method Detail
-
parsed
public com.jcabi.xml.XML parsed() throws IOException
- Throws:
IOException
-
-