[erlang-questions] leex and yecc spotting double newline

jm <>
Mon Mar 30 05:46:30 CEST 2009


Thanks for taking the time to look at this. This is more of a learning 
exercise for me at the moment for some of the things I wish to do 
further down the track. Though related to my current project of a 
postfix policy daemon. The current method of parsing requests is a hand 
written parser which works for this task, but my ability to write such 
parsers doesn't scale as well as leex and yecc. The postfix policy 
daemon one of those projects I've tried to start about three or four 
times previously but never seem to finish.

Robert Virding wrote:
> Hello again,
>
> I have done a quick test and the suggestion I made seems to work. It 
> does however demand that even the final request end with a double 
> newline. I have some comments and questions:
>
> - Do you really want to keep the whitespace tokens in your output? (in 
> words)
I'm not sure how significant the whitespace is. I've only ever seen it 
used in the replies from the policy server, eg "action=REJECT Don't spam 
me buddy"

> - If you want to get all the tokens until the end of file you can do
>     io:request(InFile, {get_until, prompt, 
> postfix_policy_lexer,tokens, [1]})
see comments below.
> - Yecc is very picky and demands that you give it all the tokens it 
> needs and only the tokens it needs, so you would probably have to add 
> a rule
>
> requests -> request : ['$1'].
> requests -> requests request : '$1' ++ ['$2'].

Another question to add to the list: How do I get the line numbers to 
increment or do I have to track these manually?


Doing at the erl prompt ('>')

 > {ok, ExRequestBin} = file:read_file("src/postfix_policy_example.txt").
 > ExRequest = binary_to_list(ExRequestBin).
 > {ok, Toks, _} = postfix_policy_lexer:string(ExRequest).
 > postfix_policy_parser:parse(ExRequest).                           
** exception error: bad argument
     in function  postfix_policy_parser:yeccpars1/5

gives the above error. Toks seems to be a valid list of tokens with the 
expected values. How do I work out what is causing this error?

calling

  play:parse("src/postfix_policy_example.txt").

gives

  Token: {word,1,"recipient"} EndLine: 1
  Token: {eq,1,"="} EndLine: 1
  ** exception exit: scanning_error
      in function  play:loop/2
      in call from play:parse/1

yet the previous attempt at the erl prompt got further.  Changing token 
to tokens as suggested above gives,

    ...
        {eq,24,"="},
        {nl,24,"\n"},
        {nl,25,"\n"}] EndLine: 26
** exception error: bad argument
     in function  postfix_policy_parser:yeccpars1/5

so it gets further, but gives the same error as the first example.
> Hope this helps. Get back to me if it doesn't or you have more questions.
Oh, many questions :-). I've attached the source files to avoid a case 
of "chinese wispers".

Jeff.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: postfix_policy_lexer.xrl
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090330/95dca6a3/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: postfix_policy_parser.yrl
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090330/95dca6a3/attachment-0001.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: play.erl
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090330/95dca6a3/attachment-0002.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: postfix_policy_example.txt
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090330/95dca6a3/attachment.txt>


More information about the erlang-questions mailing list