caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jonathan Roewen <jonathan.roewen@gmail.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] ocamllex+ocamlyacc and not parsing properly
Date: Mon, 8 Aug 2005 17:03:30 +1200	[thread overview]
Message-ID: <ad8cfe7e0508072203199f7a68@mail.gmail.com> (raw)
In-Reply-To: <ad8cfe7e05080721237a609e@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 536 bytes --]

Well, using a ref to maintain state seemed to fix things =) However, I
do have a question on how it manages to parse the last token in an IRC
string correctly.

Given the following input:

":journey PRIVMSG #bfos :\001ACTION dances a jig\001"

How does my irc_lexer.mll match the rule in param, and not the rule in message?

(My new irc_lexer.mll is attached).

BTW: A tutorial on these sorts of things (i.e. something a bit more
complicated than the calculator example) would be great to have as a
resource.

Jonathan

[-- Attachment #2: irc_lexer.mll --]
[-- Type: text/plain, Size: 1291 bytes --]

{
open Lexing
open Irc_parser
open Irc_types

type state = Header | Command | Params

let state = ref Header

let init () = state := Header (* this -must- be called before trying to lex a complete line *)
}

let letter = [^' ']
let digit = ['0'-'9']

rule param = parse
	| ':'((letter|' ')* as s)		{ STRING s }
	| (letter+) as s				{ STRING s }
	| [' ']+						{ param lexbuf }
	| eof							{ EOL }

and command = parse
	| (digit digit digit) as num	{ COMMAND (Numeric (int_of_string num)) }
	| "JOIN"						{ COMMAND JOIN }
	| "PART"						{ COMMAND PART }
	| "MODE"						{ COMMAND MODE }
	| "TOPIC"						{ COMMAND TOPIC }
	| "NAMES"						{ COMMAND NAMES }
	| "LIST"						{ COMMAND LIST }
	| "INVITE"						{ COMMAND INVITE }
	| "KICK"						{ COMMAND KICK }
	| "PRIVMSG"						{ COMMAND PRIVMSG }
	| "NOTICE"						{ COMMAND NOTICE }
	| "QUIT"						{ COMMAND QUIT }
	| "PING"						{ COMMAND PING }
	| eof							{ EOL }

and message = parse
	| ':'((letter+) as s)			{ if !state = Header then state := Command; STRING s }
	| [' ']*						{ if !state = Header || !state = Command then begin
										state := Params;
										command lexbuf
									end else begin
										state := Params;
										param lexbuf
									end }
	| eof							{ EOL }

  reply	other threads:[~2005-08-08  5:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-07 21:39 Jonathan Roewen
2005-08-07 21:54 ` Jonathan Roewen
2005-08-07 23:58 ` Jon Harrop
2005-08-08  2:17   ` Jonathan Roewen
2005-08-08  4:23     ` Jonathan Roewen
2005-08-08  5:03       ` Jonathan Roewen [this message]
2005-08-08  6:39         ` Jon Harrop
2005-08-08  6:47           ` Jonathan Roewen
2005-08-08  8:59       ` skaller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ad8cfe7e0508072203199f7a68@mail.gmail.com \
    --to=jonathan.roewen@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).