好的,我自己解决了这个问题,在这里回答后代。
在 StdLexical 中,您已经能够在词法分析器中指定空格。您所要做的就是适当地覆盖您的令牌方法。这是一些示例代码(删除了不相关的位)
override def token: CeeLexer.Parser[Token] = controlLine
// | ... (where ... is whatever you want to keep of the original method)
def controlLine = hashInclude
def hashInclude : CeeLexer.Parser[HashInclude] =
('#' ~ word("include") ~ rep(nonEolws)~'\"' ~ rep(chrExcept('\"', '\n', EofCh)) ~ '\"' ~ '\n' |
'#' ~ word("include") ~ rep(nonEolws)~'<' ~ rep(chrExcept('>', '\n', EofCh)) ~ '>' ~ '\n' ) ^^ {
case hash~include~whs~openQ~fname~closeQ~eol => // code to handle #include
}