Skip to content

Instantly share code, notes, and snippets.

@ELLIOTTCABLE
Created July 18, 2018 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ELLIOTTCABLE/ddc409618472e6b2649f76cbed9b3629 to your computer and use it in GitHub Desktop.
Save ELLIOTTCABLE/ddc409618472e6b2649f76cbed9b3629 to your computer and use it in GitHub Desktop.
❯ wrange master* menhir src/parser.mly && ocamllex src/lexer.mll
Warning: 4 states have an end-of-stream conflict.
File "src/parser.mly", line 12, characters 5-21:
Warning: production doc -> rev_records is never reduced.
Warning: in total, 1 productions are never reduced.
9 states, 264 transitions, table size 1110 bytes
{
open Lexing
open Parser
exception SyntaxError of string
let next_line lexbuf =
let pos = lexbuf.lex_curr_p in
lexbuf.lex_curr_p <-
{ pos with pos_bol = lexbuf.lex_curr_pos;
pos_lnum = pos.pos_lnum + 1
}
}
let sep = ['|' ',' ' ']
let white = " " | "\t"
let spaced_sep = white* sep white*
let value = [^ '|' ',' ' ' '\r' '\n']
let newline = '\r' | '\n' | "\r\n"
rule read =
parse
| newline { next_line lexbuf; NL }
| spaced_sep { SEP }
| value { VAL (Lexing.lexeme lexbuf) }
| _ { raise (SyntaxError ("Unexpected char: " ^ Lexing.lexeme lexbuf)) }
| eof { EOF }
%token SEP
%token <string> VAL
%token NL
%token EOF
%start <Person.t list> doc
%%
doc:
| it = rev_records { it }
| EOF { [] }
;
rev_records:
| rest = rev_records; re = record; NL { re :: rest }
| rest = rev_records; re = record; EOF { re :: rest }
| (* base-case: empty *) { [] }
;
record:
last_name = VAL; SEP; first_name = VAL; SEP; gender = VAL; SEP;
favourite_colour = VAL; SEP; birthday = VAL
{ Person.of_record_exn ~last_name ~first_name ~gender ~favourite_colour ~birthday }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment