[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What is wrong?



Hi Paul-Rene,

You've put "text" before "word".  If a token matches the regular expression
of both "text" and "word", SableCC will select "text" as it appears first in
the list of tokens.

See attached file for debugging your lexer.

Etienne

paul-rene.jorgensen@telenor.com wrote:
I'm trying to parse..

### BEGIN TEXT
Metro Principle - Quick Start
h3. 1. Introduction
*Important!!* Take note of the following before reading the rest of this document
### END TEXT

with this parser...

### BEGIN GRAMMAR
Package confluence.compiler;

Helpers
	unicode_input_character = [0..0xffff];
	tab = 9;
	lf = 10;
	cr = 12;
	space = ' ';
	nl = lf | cr | lf cr;
	input_character = [unicode_input_character-[cr+lf]];
	input_character_nospace = [input_character-space];

Tokens
	strong = '*';
	emphasis = '_';
	citation = '??';
	deleted = '-';
	inserted = '+';
	superscript = '^';
	subscript = '~';
	span = '%';
	monospaced_begin = '{{';
	monospaced_end = '}}';
	blockquote = 'bq.';
	text = input_character+;
	word = input_character_nospace+;
	new_line = nl;
	space = space;

Productions

	content = {content} component+;
	
	component =
		{paragraph} paragraph+ new_line+;
	
	paragraph = word optional_word*;
	
	optional_word = space+ word;
### END GRAMMAR

and get this "confluence.compiler.parser.ParserException: [1,1] expecting: word"

Why isn't it matching word?



--
Etienne M. Gagnon, Ph.D.             http://www.info.uqam.ca/~egagnon/
SableVM:                                       http://www.sablevm.org/
SableCC:                                       http://www.sablecc.org/
package confluence.compiler;

import confluence.compiler.parser.*;
import confluence.compiler.lexer.*;
import confluence.compiler.node.*;

import java.io.*;

public class Main
{
    public static void main(String[] args) throws Exception
    {
	Node ast =
	    new Parser
	    (new DebugLexer
	     (new PushbackReader
	      (new BufferedReader
	       (new FileReader(args[0])),
	       1024)))
	    .parse();

    }
}

class DebugLexer extends Lexer
{
    DebugLexer(PushbackReader reader)
    {
	super(reader);
    }
    
    protected void filter()
    {
	System.out.println(token.getClass() +
			   ", state : " + state.id() +
			   ", text : [" + token.getText() + "]");
    }
}