[antlr-interest] wiki-like grammar problem
Norbert Sándor
developer at erinors.com
Sun Jun 15 13:56:53 PDT 2008
Hello!
I'm very new to antlr and grammars in general, so sorry in advance if I
made a usual newbie mistake :).
I try to create a simple wiki-like grammar (absolutely for
learning/practising purpose).
My first goal was very simple: the parser should parse multi-line text
with either plain text or bold text (with the syntax **bold text**).
The grammar is at the bottom of this message. The reason I chose gated
semantic predicate is because later I want to handle italic, underlined,
etc. text markup in the same rule (at least I think so now ;) ).
I have two problems:
1. It doesn't work :) - I get "FailedPredicateException(text1,
{!text1::bold}?)" message in the AntlrWorks interpreter. What is the
correct way to write such a grammar (with the ability to easily add
italic, underlined, etc. markup later)?
2. For some reason the generated code is invalid if I use "text" as rule
name. Why is this?
One more question:
3. Is there a grammar available for parsing a wiki-like text? I saw the
grammar for Wiki Creole but I don't like it, it handles bold, etc. texts
in a non-natural way.
Thanks for your help in advance!
Regards:
Norbi
--- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8
--- >8 ---
grammar Text;
options {
language = Java;
}
STAR : '*';
BOLD_MARKUP
: STAR STAR;
TEXT_CHAR
: 'a'..'z' | ' ';
NEWLINE : ( CR )? LF | CR;
fragment CR : '\r';
fragment LF : '\n';
page : text1* (NEWLINE | EOF);
text1
scope
{
boolean bold;
}
@init
{
$text1::bold=false;
}
:
{!$text1::bold}?=> BOLD_MARKUP {$text1::bold=true;} text1
BOLD_MARKUP {$text1::bold=false;}
| TEXT_CHAR+
;
More information about the antlr-interest
mailing list