@@ -39,38 +39,63 @@ let tok lexbuf =
3939 Lexing. lexeme lexbuf
4040let tokinfo lexbuf =
4141 Parse_info. tokinfo_str_pos (Lexing. lexeme lexbuf) (Lexing. lexeme_start lexbuf)
42-
4342}
4443
4544(* ****************************************************************************)
46-
4745let letter = ['a' - 'z''A' - 'Z' ]
4846let digit = ['0' - '9' ]
4947
48+ let symbol =
49+ ['-' '+' '=' '~' '.' ',' '/' ':' '<' '>' '*' ';' '#'
50+ '_' '?' '^' '|' '!' '&' ]
51+ (*
52+ '\''
53+ '\\'
54+ '@'
55+ '"'
56+ '`'
57+ *)
58+
5059(* ****************************************************************************)
51- rule sexp = parse
60+ rule token = parse
5261
5362 (* ----------------------------------------------------------------------- *)
5463 (* spacing/comments *)
5564 (* ----------------------------------------------------------------------- *)
5665 | " ;" [^ '\n' '\r' ]* {
5766 TComment (tokinfo lexbuf)
5867 }
59- | [' ''\t' ] { TCommentSpace (tokinfo lexbuf) }
68+ | [' ''\t' ]+ { TCommentSpace (tokinfo lexbuf) }
6069 | " \n " { TCommentNewline (tokinfo lexbuf) }
6170
6271 (* ----------------------------------------------------------------------- *)
6372 (* Symbols *)
6473 (* ----------------------------------------------------------------------- *)
6574
66- | '(' { TOParen (tokinfo lexbuf) }
67- | ')' { TCParen (tokinfo lexbuf) }
75+ | '(' { TOParen (tokinfo lexbuf) } | ')' { TCParen (tokinfo lexbuf) }
76+ | " [ " { TOBracket (tokinfo lexbuf) } | " ] " { TCBracket (tokinfo lexbuf) }
6877
6978 (* ----------------------------------------------------------------------- *)
70- (* Keywords and ident *)
79+ (* Strings *)
7180 (* ----------------------------------------------------------------------- *)
81+ | '"' {
82+ (* opti: use Buffer because some autogenerated files can
83+ * contains huge strings
84+ *)
85+ let info = tokinfo lexbuf in
86+ let buf = Buffer. create 100 in
87+ string buf lexbuf;
88+ let s = Buffer. contents buf in
89+ TString (s, info +> Parse_info. tok_add_s (s ^ " \" " ))
90+ }
7291
7392 (* ----------------------------------------------------------------------- *)
93+ (* Keywords and ident *)
94+ (* ----------------------------------------------------------------------- *)
95+ | (letter | symbol) (letter | digit | symbol)* {
96+ TIdent (tok lexbuf, tokinfo lexbuf)
97+ }
98+ (* ----------------------------------------------------------------------- *)
7499 (* Constant *)
75100 (* ----------------------------------------------------------------------- *)
76101
@@ -85,3 +110,25 @@ rule sexp = parse
85110 then pr2_once (" LEXER:unrecognised symbol, in token rule:" ^ tok lexbuf);
86111 TUnknown (tokinfo lexbuf)
87112 }
113+
114+ (* ****************************************************************************)
115+
116+ and string buf = parse
117+ | '"' { Buffer. add_string buf " " }
118+ (* opti: *)
119+ | [^ '"' '\\' ]+ {
120+ Buffer. add_string buf (tok lexbuf);
121+ string buf lexbuf
122+ }
123+
124+ | (" \\ " (_ as v)) as x {
125+ (* todo: check char ? *)
126+ (match v with
127+ | _ -> ()
128+ );
129+ Buffer. add_string buf x;
130+ string buf lexbuf
131+ }
132+ | eof {
133+ pr2 " LEXER: WIERD end of file in double quoted string" ;
134+ }
0 commit comments