Created
November 28, 2023 11:30
-
-
Save koral--/16db13ef54f6950850b66f15111ec373 to your computer and use it in GitHub Desktop.
ARB parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
final input = stdin.readLineSync(); | |
final result = PatternDefinition().build().parse(input ?? ''); | |
if (result is Success) { | |
print('Pattern found, result: ${result.value}'); | |
} else { | |
print('Pattern not found'); | |
} | |
} | |
class PatternDefinition extends GrammarDefinition<int?> { | |
@override | |
Parser<int?> start() => ref0(value).end(); // 1 | |
Parser<int?> value() => seq3( // 2 | |
char('{').trim(), // 2a | |
digit().plus().flatten(), // 2b | |
char('}').trim(), // 2c | |
).map3((_, digits, __) => int.tryParse(digits)); // 3 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment