File tree Expand file tree Collapse file tree 2 files changed +10
-8
lines changed
commonMain/kotlin/eu/yeger/cyk/parser
commonTest/kotlin/eu/yeger/cyk/parser Expand file tree Collapse file tree 2 files changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -49,14 +49,15 @@ private fun String.splitIntoComponents(): Result<List<String>> {
4949}
5050
5151private fun List<String>.asProductionRule (startSymbol : StartSymbol ): Result <ProductionRule > {
52- val inputSymbol = when (val inputString = get(0 )) {
53- startSymbol.symbol -> startSymbol
54- else -> RegularNonTerminalSymbol (inputString)
55- }
56- return when (size) {
57- 3 -> asNonTerminatingProductionRule(inputSymbol)
58- 2 -> asTerminatingProductionRule(inputSymbol)
59- else -> fail(" Invalid amount of symbols on the right side! Must be 1 for terminal or 2 for non terminal production rules. ($lastIndex )" )
52+ return when (val inputString = get(0 )) {
53+ startSymbol.symbol -> startSymbol.asSuccess()
54+ else -> inputString.parseNonTerminalSymbol()
55+ }.andThen { inputSymbol ->
56+ when (size) {
57+ 3 -> asNonTerminatingProductionRule(inputSymbol)
58+ 2 -> asTerminatingProductionRule(inputSymbol)
59+ else -> fail(" Invalid amount of symbols on the right side! Must be 1 for terminal or 2 for non terminal production rules. ($lastIndex )" )
60+ }
6061 }
6162}
6263
Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ class ParserTests {
5454 " S -> a b c" ,
5555 " S -> A b" ,
5656 " S -> a B" ,
57+ " s -> A B" ,
5758 ).forEach { productionRule ->
5859 assertTrue {
5960 grammar(" S" ) {
You can’t perform that action at this time.
0 commit comments