aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/fixture.ml2
-rw-r--r--lib/lexer.mll13
-rw-r--r--test/test_parser.ml25
3 files changed, 21 insertions, 19 deletions
diff --git a/lib/fixture.ml b/lib/fixture.ml
index 31a6e9c..189d2fb 100644
--- a/lib/fixture.ml
+++ b/lib/fixture.ml
@@ -22,6 +22,8 @@ let names =
let random_name () = List.nth names (Random.int (List.length names))
let%test "random_name" = List.mem (random_name ()) names
+(* Support arbitrary amount *)
+(* Support names *)
type t =
| Name of string
| Uuidv4 of string
diff --git a/lib/lexer.mll b/lib/lexer.mll
index 41a2abc..769192b 100644
--- a/lib/lexer.mll
+++ b/lib/lexer.mll
@@ -10,19 +10,20 @@ let exp = ['e' 'E'] ['-' '+']? digit+
let float = digit* frac? exp?
let white = [' ' '\t']+
let newline = '\r' | '\n' | "\r\n"
-let id = ['a'-'z' 'A'-'Z' '_']*
-
+let id = ['a'-'z' 'A'-'Z' '-']*
+let newline = '\r' | '\n' | "\r\n"
+let many_newline = newline+
rule read =
parse
- | white { read lexbuf }
| id { IDENTIFIER (Lexing.lexeme lexbuf) }
- | "uuidv4" { UUIDV4 }
- | "name" { NAME }
+ | "_uuidv4" { UUIDV4 }
+ | "_name" { NAME }
+ | white { read lexbuf }
| ":" { COLON }
| ";" { SEMICOLON }
| "," { COMMA }
- | "\n" { NEWLINE }
+ | many_newline { NEWLINE }
| "." { DOT }
| eof { EOF }
| _ as c { failwith (Printf.sprintf "unexpected character: %C" c) }
diff --git a/test/test_parser.ml b/test/test_parser.ml
index 405219e..c677869 100644
--- a/test/test_parser.ml
+++ b/test/test_parser.ml
@@ -12,28 +12,27 @@ let test_parse s () =
check bool "Parses" (Option.is_some ast) true
-let table_suite =
- [ "Can use underscore for table names", `Quick, test_parse "user_all: name uuidv4" ]
-
-
let rows_suite =
- [ "Can parse uuidv4", `Quick, test_parse "user: id uuidv4"
+ [ "Can parse uuidv4", `Quick, test_parse "user: id _uuidv4"
; ( "Can parse multiple tables"
, `Quick
- , test_parse "user: id uuidv4\npurchases: id uuidv4" )
- ; "Resolves conflicting names", `Quick, test_parse "purchases: name uuidv4"
+ , test_parse "user: id _uuidv4\npurchases: id _uuidv4" )
+ ; "Resolves conflicting names", `Quick, test_parse "purchases: name _uuidv4"
+ ; "Supports names", `Quick, test_parse "purchases: name _name"
]
let relations_suite =
[ ( "Can reference other tables"
, `Quick
- , test_parse "user: id uuidv4\npurchases: id uuidv4, user_id user.id" )
- ; "Can use ; as a separator", `Quick, test_parse "user: id uuidv4; purchases: id uuidv4"
+ , test_parse "user: id _uuidv4\npurchases: id _uuidv4, userid user.id" )
+ ; ( "Can use ; as a separator"
+ , `Quick
+ , test_parse "user: id _uuidv4; purchases: id _uuidv4" )
+ ; ( "Supports multiple newlines"
+ , `Quick
+ , test_parse "user: id _uuidv4\n\n\n\n\npurchases: id _uuidv4" )
]
-let () =
- Alcotest.run
- "Parsing"
- [ "Tables", table_suite; "Rows", rows_suite; "Relations", relations_suite ]
+let () = Alcotest.run "Parsing" [ "Rows", rows_suite; "Relations", relations_suite ]