我为 ParseKit 写了一个 C 语法,它确实工作得很好,但让我抓狂的是预处理器语句。预处理器语句的正确符号定义是什么?
这是我尝试过的简短示例...
@reportsCommentTokens = YES;
@commentState = '/';
@singleLineComments = '//';
@multiLineComments = '/*' '*/';
@commentState.fallbackState = delimitState;
@delimitState.fallbackState = symbolState;
@start = Empty | comments | preprocessor;
comments = comment*;
comment = Comment;
@symbols = '#include';
preprocessor = preprocessorIncludes;
preprocessorIncludes = preprocessorIncludeStatement*;
preprocessorIncludeStatement = preprocessorInclude quotedFileName*;
preprocessorInclude = '#include';
quotedFileName = QuotedString;
...但它不起作用。将其作为简化的语法示例来捕获注释并包含带引号的语句(而不是 < >)。我在这个简单的文件上尝试了这个语法......
/*
* Cryptographic API.
*
* RIPEMD-256 - RACE Integrity Primitives Evaluation Message Digest.
*
* Based on the reference implementation by Antoon Bosselaers, ESAT-COSIC
*
* Copyright (c) 2008 Adrian-Ken Rueegsegger <ken@codelabs.ch>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
*/
// Here's one line comment
/* One line multiline comment */
#include "ripemd.h"
/* 2nd one line multiline comment */
...它以 /* 一行多行注释 */ 结束,将其报告为注释标记,然后它静默失败。
所以我试图将'#include'符号分开......
@symbolState = '#' '#';
@symbol = '#';
numSymbol = '#';
preprocessorInclude = numSymbol 'include';
......但它仍然没有帮助。
也许托德可以提供帮助,但处理“#include”等“符号”的正确方法是什么?