finally refactored the parser to use proper nice scala functions. As a result it is unreadable now but also beautiful