Updated Application overview (markdown)

Bartłomiej Przemysław Pluta
2020-03-30 15:54:48 +02:00
parent bc1823e549
commit c3307c016c

@@ -130,17 +130,21 @@ class AtomParser : Parser() {
terminal(TokenType.CLOSE_PAREN)
) { (_, expression) -> expression }
val literalParser = oneOf(
return oneOf(
parenthesesParser,
ComplexIdentifierParser(),
StaffParser(),
ListParser(),
LiteralParser(),
MapParser()
)
return literalParser.parse(input)
).parse(input)
}
}
```
In this example you can notice both `allOf()` and `oneOf()` helper methods. The first one returns success (and parsed node) if and only if all of its subparsers returns success as well. In contrast to that, the `oneOf()` method returns success with parsed node when any of its subparsers returns success. The `oneOf()` method seeks for the first parser that returns success. When it finds it, it immediately returns success with node returned from its subparser and does not execute further subparsers. Because the `oneOf()` method is only a proxy for other parsers, it does not need to do anything with returned nodes. In contrast to that, the `allOf()` method has to compose every node returned from its subparsers to new node. Thanks to that, we can obtain AST instead of CST (concrete syntax tree).
This parser implementation can be featured using following notation:
```
parenthesesExpr ::= '(' expr ')' ;
atom ::= parenthesesExpr | identifier | staff | list | map ;
```