Skip to content
This repository was archived by the owner on Jun 4, 2019. It is now read-only.

Commit fe5281a

Browse files
committed
lang_lisp: can now lex my .emacs and backquote.lisp
1 parent dd50723 commit fe5281a

7 files changed

Lines changed: 44 additions & 11 deletions

File tree

commons/file_type.ml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ type file_type =
3737
and pl_type =
3838
| ML of string (* mli, ml, mly, mll *)
3939
| Haskell of string
40+
| Lisp of lisp_type
4041
| Makefile
4142
| Script of string (* sh, csh, awk, sed, etc *)
4243
| C | Cplusplus | Java | Csharp
43-
| Scheme | Lisp
44-
| Elisp
4544
| Perl | Python | Ruby
4645
| Erlang
4746
| Beta
@@ -51,6 +50,8 @@ type file_type =
5150
| Thrift
5251
| MiscPL of string
5352

53+
and lisp_type = CommonLisp | Elisp | Scheme
54+
5455
and webpl_type =
5556
| Php of string (* php or phpt or script *)
5657
| Js
@@ -113,10 +114,10 @@ let file_type_of_file2 file =
113114

114115
| "thrift" -> PL Thrift
115116

116-
| "scm" | "rkt" -> PL Scheme
117-
| "lisp" -> PL Lisp
117+
| "scm" | "rkt" -> PL (Lisp Scheme)
118+
| "lisp" -> PL (Lisp CommonLisp)
119+
| "el" -> PL (Lisp Elisp)
118120

119-
| "el" -> PL Elisp
120121
| "pl" | "perl" -> PL Perl (* could be prolog too *)
121122
| "py" -> PL Python
122123
| "rb" -> PL Ruby

commons/file_type.mli

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ type file_type =
1010
| Other of string
1111

1212
and pl_type =
13-
| ML of string | Haskell of string
13+
| ML of string | Haskell of string | Lisp of lisp_type
1414
| Makefile
1515
| Script of string
1616
| C | Cplusplus | Java | Csharp
17-
| Scheme | Lisp
18-
| Elisp
1917
| Perl | Python | Ruby
2018
| Erlang
2119
| Beta
@@ -25,6 +23,8 @@ type file_type =
2523
| Thrift
2624
| MiscPL of string
2725

26+
and lisp_type = CommonLisp | Elisp | Scheme
27+
2828
and webpl_type =
2929
| Php of string
3030
| Js

lang_lisp/parsing/lexer_lisp.mll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ let symbol =
4949
['-' '+' '=' '~' '.' ',' '/' ':' '<' '>' '*' ';' '#'
5050
'_' '?' '^' '|' '!' '&' ]
5151
(*
52-
'\''
5352
'\\'
5453
'@'
5554
'"'
@@ -75,6 +74,15 @@ rule token = parse
7574
| '(' { TOParen (tokinfo lexbuf) } | ')' { TCParen (tokinfo lexbuf) }
7675
| "[" { TOBracket(tokinfo lexbuf) } | "]" { TCBracket(tokinfo lexbuf) }
7776

77+
| '\'' { TQuote (tokinfo lexbuf) }
78+
(* special rule for symbols e.g. 'foo ? or because '(foo) is also
79+
* valid just let the parser differentiate those different quoted
80+
* things ?
81+
*)
82+
| '`' { TBackQuote (tokinfo lexbuf) }
83+
| ',' { TComma (tokinfo lexbuf) }
84+
| '@' { TAt (tokinfo lexbuf) }
85+
7886
(* ----------------------------------------------------------------------- *)
7987
(* Strings *)
8088
(* ----------------------------------------------------------------------- *)

lang_lisp/parsing/parse_lisp.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ module TH = Parser_lisp
2828
(* Prelude *)
2929
(*****************************************************************************)
3030

31+
(*
32+
* alt:
33+
* - Could reuse the parser in ocamlsexp ? but they just have Atom | Sexp
34+
* and I need to differentiate numbers in the highlighter, and
35+
* also handling quoted, anti-quoted and other lisp special things.
36+
*)
37+
3138
(*****************************************************************************)
3239
(* Types *)
3340
(*****************************************************************************)

lang_lisp/parsing/parser_lisp.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ type token =
3333
| TOBracket of (Ast_lisp.info)
3434
| TCBracket of (Ast_lisp.info)
3535

36+
| TQuote of (Ast_lisp.info)
37+
(* anti-quote expressions tokens, as in `(foo ,v ,@xs) *)
38+
| TBackQuote of (Ast_lisp.info)
39+
| TComma of (Ast_lisp.info)
40+
| TAt of (Ast_lisp.info)
41+
3642
| TUnknown of (Ast_lisp.info)
3743
| EOF of (Ast_lisp.info)
3844

@@ -69,6 +75,11 @@ let visitor_info_of_tok f = function
6975
| TOBracket ii -> TOBracket (f ii)
7076
| TCBracket ii -> TCBracket (f ii)
7177

78+
| TQuote ii -> TQuote (f ii)
79+
| TBackQuote ii -> TBackQuote (f ii)
80+
| TComma ii -> TComma (f ii)
81+
| TAt ii -> TAt (f ii)
82+
7283
| TUnknown ii -> TUnknown (f ii)
7384
| EOF ii -> EOF (f ii)
7485

lang_lisp/parsing/test_parsing_lisp.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ open OUnit
1111
(*****************************************************************************)
1212

1313
let test_tokens_lisp file =
14-
if not (file =~ ".*\\.nw")
15-
then pr2 "warning: seems not a noweb file";
14+
(match File_type.file_type_of_file file with
15+
| File_type.PL (File_type.Lisp _) -> ()
16+
| _ -> pr2 "warning: seems not a lisp file";
17+
);
1618

1719
Flag.verbose_lexing := true;
1820
Flag.verbose_parsing := true;

tests/lisp/backquote.lisp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
(setq bar '(1 2 3))
3+
4+
(setq foo `(this is a ,bar and ,@bar))

0 commit comments

Comments
 (0)