-
-
Save ELLIOTTCABLE/ddc409618472e6b2649f76cbed9b3629 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
❯ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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