}
}
+ private void add_content_string (string str) {
+ var text = peek () as Text;
+ if (text == null) {
+ push (text = _factory.create_text ());
+ }
+ text.content += str;
+ }
+
private void init_rules () {
// Inline rules
run.set_name ("Run");
TokenType.Action add_text = (token) => {
- var text = peek () as Text;
- if (text == null) {
- push (text = _factory.create_text ());
- }
- text.content += token.to_string ();
+ add_content_string (token.to_string ());
};
TokenType word = TokenType.any_word ().action (add_text);
Rule.many ({
Rule.one_of ({
word,
+ TokenType.BREAK.action ((token) => { add_content_string ("\n"); }),
TokenType.LESS_THAN.action (add_text),
TokenType.GREATER_THAN.action (add_text),
TokenType.ALIGN_RIGHT.action (add_text),
break;
case '<':
- emit_token (TokenType.LESS_THAN);
+ if (!look_for ("<<BR>>", TokenType.BREAK)) {
+ emit_token (TokenType.LESS_THAN);
+ }
break;
case '>':
emit_token (one);
}
}
+
+ private bool look_for (string str, TokenType type) throws ParserError {
+ for (int i = 1; i < str.length; i++) {
+ if (get_next_char (i) != str[i]) {
+ return false;
+ }
+ }
+
+ emit_token (type);
+ _skip = (int) (str.length - 1);
+ return true;
+ }
}
public static TokenType ANY_NUMBER;
public static TokenType EOF;
public static TokenType EOL;
+ public static TokenType BREAK;
public static TokenType AROBASE;
public static TokenType SPACE;
public static TokenType TAB;
ANY_NUMBER = new TokenType.basic ("<any-number>");
EOF = new TokenType.basic ("\0", "<end-of-file>");
EOL = new TokenType.basic ("\n", "<end-of-line>");
+ BREAK = new TokenType.basic ("<<BR>>");
AROBASE = new TokenType.basic ("@");
SPACE = new TokenType.basic (" ", "<space>");
TAB = new TokenType.basic ("\t", "<tab>");