I'm trying to get my simple program working and I keep running into
errors.

 

In my JavaScript.g file I've set the language=Python;

 

I have a @members section like:

 

@members

{

                insideFunction = False;

                

def prettyPrint(type, text):

                text = text.replace("\r", '') //to remove carriage
returns in my javascript file (mt.js)

                text = text.replace("\n", '') // to remove new lines

                if len(text) > 55:

                                start = text[:40]

                                end = text[-10:]

                                text = start+' ... '+end

                print type+' -> '+text

}

 

 

In a JavaScript.G file I have in the functionBody section:

 

functionBody

                :  '{' {insideFunction=True;) LT!* sourceElements LT!*
'}' {insideFunction=False;}

                ;

 

In sourceElement section I have:

sourceElement

                : f=functionDeclaration { prettyPrint("FUNCTION ",
$f.text.toString()); }

                | s=statement { prettyPrint("STATEMENT ",
$s.text.toString()); }

                ;

 

Then in python I'm doing:

import antlr3

from JavaScriptLexer import JavaScriptLexer

from JavaScriptParser import JavaScriptParser

 

char_stream = antlr3.ANTLRFileStream("mt.js")

lexer = JavaScriptLexer(char_stream)

tokens = antlr3.CommonTokenStream(lexer)

parser = JavaScriptParser(tokens)

parser.program()

 

it barfs:

 

prettyPrint("STATEMENT", ((s is not None) and
[self.input.toString(s.start, s.stop)] or [None])[0].toString());

NameError: global name 'prettyPrint' is not defined

 

I'm trying, but failing. Can anyone with python experience help me out?

 

Thank you in advance.

 

Thomas J. Raef

 


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to