开发者

Scala StandardTokenParsers vs JavaTokenParsers

开发者 https://www.devze.com 2023-01-15 02:02 出处:网络
What exactly is the difference between StandardTokenParsers and JavaTokenParsers? What is one good for and what is the other good for?

What exactly is the difference between StandardTokenParsers and JavaTokenParsers? What is one good for and what is the other good for?

In StandardTokenParsers I can define my keywords using lexical.reserved, but how exactly does that help开发者_运维技巧 me?

BR Troels


The body of JavaTokenParsers is actually fairly simple and gives you a good feel for what's going on. Specifically, JavaTokenParsers inherits from the RegexParsers which gives you a lot of flexibility in defining matches; the JavaTokenParsers defines a few sample regexes for matching identifiers, numbers, etc. I don't use the StandardTokenParsers much, as the RegexParsers give me more sanity... You need to more or less define hard character matches with them, as opposed to using Regular Expressions.


There is another important difference. StandardTokenParsers parses Token instances, whereas JavaTokenParsers parses Char. You'll see that in the error messages when parsing fails. StandardTokenParsers reports the complete offending Token, JavaTokenParsers only the first character.

0

精彩评论

暂无评论...
验证码 换一张
取 消