caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] ocamllex+ocamlyacc and not parsing properly
@ 2005-08-07 21:39 Jonathan Roewen
  2005-08-07 21:54 ` Jonathan Roewen
  2005-08-07 23:58 ` Jon Harrop
  0 siblings, 2 replies; 9+ messages in thread
From: Jonathan Roewen @ 2005-08-07 21:39 UTC (permalink / raw)
  To: caml-list

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

Hi,

I'm having some trouble with a lexer+parser I've written to parse IRC
strings. Just about all strings are parsed correctly, but I'm having a
few minor issues.

Here are two strings that fail to parse correctly:
:Sovereign.Wyldryde.org 254 dst 112 :holodeck programs running

:Sovereign.Wyldryde.org 333 dst #bfos Helio 112025589

My irc_lexer.mll & irc_parser.mly are attached :-) (don't wanna spam
the list with huge lines of code)

Used in ircii.ml as:

let input_line = IO.read_line instream in
  try match (Irc_parser.args Irc_lexer.message (Lexing.from_string
input_line)) with

If someone can highlight what's going wrong, I'd really appreciate it
(though, it doesn't currently affect any received irc commands of
great significance at the moment).

BTW: As an aside, if the lexer doesn't cover all the bases, it doesn't
throw an exception, just screws up my OS (Bounds check error, followed
by seg-fault).

Jonathan

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

{
open Lexing
open Irc_parser
open Irc_types
}

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 }
	| [' ']*							{ param lexbuf } (* this means we won't get a command, and parsing will fail *)
	| eof								{ EOL } (* this will raise a parsing error *)

and message = parse
	| ':'((letter+) as s)				{ STRING s }
	| [' ']*							{ command lexbuf }
	| eof								{ EOL } (* and this will also raise a parsing error *)

[-- Attachment #3: irc_parser.mly --]
[-- Type: text/plain, Size: 335 bytes --]

%token EOL
%token <string> STRING /* this is for parameters */
%token <Irc_types.command> COMMAND

%start args
%type <string option * Irc_types.command * string list> args
%%

params:
	| STRING params { $1 :: $2 }
	| EOL { [] }
	
args:
	| STRING COMMAND params { (Some $1, $2, $3) }
	| COMMAND params { (None, $1, $2) }

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-08-08  8:59 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-07 21:39 [Caml-list] ocamllex+ocamlyacc and not parsing properly 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
2005-08-08  6:39         ` Jon Harrop
2005-08-08  6:47           ` Jonathan Roewen
2005-08-08  8:59       ` skaller

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).