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

Commit 270df00

Browse files
committed
skeleton for lang_lisp/
test plan: ./pfff -tokens_lisp tests/lisp/foo.lisp currently raise a Todo but will be fixed soon.
1 parent 0e58a2b commit 270df00

16 files changed

Lines changed: 416 additions & 1 deletion

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,4 @@ external/ocamlbdb/libcamlbdb.a
234234
/visual/Visual.out
235235
/lang_php/analyze/database_php_storage.ml
236236

237+
/lang_lisp/parsing/lexer_lisp.ml

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ LIBS= commons/commons.cma \
164164
lang_ml/analyze/lib.cma \
165165
lang_nw/parsing/lib.cma \
166166
lang_nw/analyze/lib.cma \
167+
lang_lisp/parsing/lib.cma \
168+
lang_lisp/analyze/lib.cma \
167169
lang_php/parsing/lib.cma \
168170
lang_php/analyze/basic/lib.cma \
169171
lang_php/analyze/foundation/lib.cma \
@@ -200,6 +202,8 @@ MAKESUBDIRS=commons \
200202
lang_ml/analyze \
201203
lang_nw/parsing \
202204
lang_nw/analyze \
205+
lang_lisp/parsing \
206+
lang_lisp/analyze \
203207
lang_php/parsing \
204208
lang_php/mini \
205209
lang_php/matcher \

lang_lisp/analyze/Makefile

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
TOP=../..
2+
##############################################################################
3+
# Variables
4+
##############################################################################
5+
TARGET=lib
6+
7+
SRC= \
8+
highlight_lisp.ml \
9+
test_analyze_lisp.ml
10+
11+
-include $(TOP)/Makefile.config
12+
13+
SYSLIBS= str.cma unix.cma $(PCRECMA)
14+
LIBS=$(TOP)/commons/commons.cma \
15+
$(TOP)/h_program-lang/lib.cma \
16+
$(TOP)/h_version-control/lib.cma \
17+
../parsing/lib.cma \
18+
19+
MAKESUBDIRS=
20+
21+
INCLUDEDIRS= $(TOP)/commons \
22+
$(TOP)/commons/ocollection $(TOP)/commons/ocamlextra \
23+
$(TOP)/commons/lib-json \
24+
$(TOP)/external/ocamlpcre/lib \
25+
$(TOP)/h_program-lang $(TOP)/h_version-control \
26+
$(TOP)/globals \
27+
../parsing \
28+
29+
##############################################################################
30+
# Generic variables
31+
##############################################################################
32+
-include $(TOP)/Makefile.common
33+
34+
35+
##############################################################################
36+
# Top rules
37+
##############################################################################
38+
all:: rec $(TARGET).cma
39+
all.opt:: rec.opt $(TARGET).cmxa
40+
41+
rec:
42+
set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i all || exit 1; done
43+
44+
rec.opt:
45+
set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i all.opt || exit 1; done
46+
47+
clean::
48+
set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i clean; done
49+
depend::
50+
set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i depend; done
51+
52+
53+
$(TARGET).cma: $(OBJS)
54+
$(OCAMLC) -a -o $(TARGET).cma $(OBJS)
55+
56+
$(TARGET).cmxa: $(OPTOBJS) $(LIBS:.cma=.cmxa)
57+
$(OCAMLOPT) -a -o $(TARGET).cmxa $(OPTOBJS)
58+
59+
$(TARGET).top: $(OBJS) $(LIBS)
60+
$(OCAMLMKTOP) -o $(TARGET).top $(SYSLIBS) $(LIBS) $(OBJS)
61+
62+
clean::
63+
rm -f $(TARGET).top
64+
65+
66+
##############################################################################
67+
# Literate Programming rules
68+
##############################################################################
69+

lang_lisp/analyze/highlight_lisp.ml

Whitespace-only changes.

lang_lisp/analyze/test_analyze_lisp.ml

Whitespace-only changes.

lang_lisp/parsing/Makefile

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
TOP=../..
2+
##############################################################################
3+
# Variables
4+
##############################################################################
5+
TARGET=lib
6+
7+
-include $(TOP)/Makefile.config
8+
9+
SRC= flag_parsing_lisp.ml \
10+
ast_lisp.ml \
11+
ast_scheme.ml \
12+
parser_lisp.ml lexer_lisp.ml \
13+
parse_lisp.ml \
14+
test_parsing_lisp.ml
15+
16+
# unparse_js.ml \
17+
# meta_ast_js.ml \
18+
# export_ast_js.ml \
19+
# visitor_js.ml lib_parsing_js.ml \
20+
21+
22+
SYSLIBS= str.cma unix.cma
23+
24+
# globals.cma is used only for Config.patch in test_parse_nw
25+
LIBS=$(TOP)/commons/commons.cma \
26+
$(TOP)/globals/globals.cma \
27+
$(TOP)/h_program-lang/lib.cma \
28+
29+
INCLUDEDIRS= $(TOP)/commons $(TOP)/commons/ocamlextra \
30+
$(TOP)/commons/lib-sexp $(TOP)/commons/lib-json \
31+
$(TOP)/globals \
32+
$(TOP)/h_program-lang \
33+
34+
##############################################################################
35+
# Generic variables
36+
##############################################################################
37+
38+
-include $(TOP)/Makefile.common
39+
40+
##############################################################################
41+
# Top rules
42+
##############################################################################
43+
all:: $(TARGET).cma
44+
all.opt:: $(TARGET).cmxa
45+
46+
$(TARGET).cma: $(OBJS)
47+
$(OCAMLC) -a -o $(TARGET).cma $(OBJS)
48+
49+
$(TARGET).cmxa: $(OPTOBJS) $(LIBS:.cma=.cmxa)
50+
$(OCAMLOPT) -a -o $(TARGET).cmxa $(OPTOBJS)
51+
52+
$(TARGET).top: $(OBJS) $(LIBS)
53+
$(OCAMLMKTOP) -o $(TARGET).top $(SYSLIBS) $(LIBS) $(OBJS)
54+
55+
clean::
56+
rm -f $(TARGET).top
57+
58+
59+
lexer_lisp.ml: lexer_lisp.mll
60+
$(OCAMLLEX) $<
61+
clean::
62+
rm -f lexer_lisp.ml
63+
beforedepend:: lexer_lisp.ml
64+
65+
66+
#parser_nw.ml parser_nw.mli: parser_nw.mly
67+
# $(OCAMLYACC) $<
68+
#clean::
69+
# rm -f parser_nw.ml parser_nw.mli parser_nw.output
70+
#beforedepend:: parser_nw.ml parser_nw.mli
71+
#
72+
#
73+
#visitor_nw.cmo: visitor_nw.ml
74+
# $(OCAMLC) -w y -c $<
75+
76+
##############################################################################
77+
# Generic rules
78+
##############################################################################
79+
80+
##############################################################################
81+
# Literate Programming rules
82+
##############################################################################

lang_lisp/parsing/ast_lisp.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
type info = Parse_info.info
3+
4+
type toplevel = unit
5+
(*
6+
| TopSexp of sexp
7+
| NotParsedCorrectly of info list
8+
| FinalDef of info (* EOF *)
9+
*)
10+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
3+
let verbose_lexing = ref false
4+
let verbose_parsing = ref false

lang_lisp/parsing/lexer_lisp.mll

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
(* Yoann Padioleau
3+
*
4+
* Copyright (C) 2010 Facebook
5+
*
6+
* This library is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public License
8+
* version 2.1 as published by the Free Software Foundation, with the
9+
* special exception on linking described in file license.txt.
10+
*
11+
* This library is distributed in the hope that it will be useful, but
12+
* WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file
14+
* license.txt for more details.
15+
*)
16+
17+
open Common
18+
19+
module Flag = Flag_parsing_lisp
20+
21+
open Parser_lisp
22+
23+
(*****************************************************************************)
24+
(* Prelude *)
25+
(*****************************************************************************)
26+
27+
(*****************************************************************************)
28+
(* Wrappers *)
29+
(*****************************************************************************)
30+
let pr2, pr2_once = Common.mk_pr2_wrappers Flag.verbose_lexing
31+
32+
(*****************************************************************************)
33+
(* Helpers *)
34+
(*****************************************************************************)
35+
exception Lexical of string
36+
37+
(* ---------------------------------------------------------------------- *)
38+
let tok lexbuf =
39+
Lexing.lexeme lexbuf
40+
let tokinfo lexbuf =
41+
Parse_info.tokinfo_str_pos (Lexing.lexeme lexbuf) (Lexing.lexeme_start lexbuf)
42+
43+
}
44+
45+
(*****************************************************************************)
46+
47+
let letter = ['a'-'z''A'-'Z']
48+
let digit = ['0'-'9']
49+
50+
(*****************************************************************************)
51+
rule sexp = parse
52+
53+
(* ----------------------------------------------------------------------- *)
54+
(* spacing/comments *)
55+
(* ----------------------------------------------------------------------- *)
56+
| ";" [^'\n' '\r']* {
57+
TComment(tokinfo lexbuf)
58+
}
59+
| [' ''\t'] { TCommentSpace (tokinfo lexbuf) }
60+
| "\n" { TCommentNewline (tokinfo lexbuf) }
61+
62+
(* ----------------------------------------------------------------------- *)
63+
(* Symbols *)
64+
(* ----------------------------------------------------------------------- *)
65+
66+
| '(' { TOParen (tokinfo lexbuf) }
67+
| ')' { TCParen (tokinfo lexbuf) }
68+
69+
(* ----------------------------------------------------------------------- *)
70+
(* Keywords and ident *)
71+
(* ----------------------------------------------------------------------- *)
72+
73+
(* ----------------------------------------------------------------------- *)
74+
(* Constant *)
75+
(* ----------------------------------------------------------------------- *)
76+
77+
| digit+ {
78+
TNumber(tok lexbuf, tokinfo lexbuf)
79+
}
80+
81+
(* ----------------------------------------------------------------------- *)
82+
| eof { EOF (tokinfo lexbuf +> Parse_info.rewrap_str "") }
83+
| _ {
84+
if !Flag.verbose_lexing
85+
then pr2_once ("LEXER:unrecognised symbol, in token rule:"^tok lexbuf);
86+
TUnknown (tokinfo lexbuf)
87+
}

lang_lisp/parsing/parse_lisp.ml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
(* Yoann Padioleau
2+
*
3+
* Copyright (C) 2010 Facebook
4+
*
5+
* This program is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU General Public License (GPL)
7+
* version 2 as published by the Free Software Foundation.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* file license.txt for more details.
13+
*)
14+
15+
open Common
16+
17+
module Ast = Ast_lisp
18+
module Flag = Flag_parsing_lisp
19+
20+
module PI = Parse_info
21+
22+
23+
(*****************************************************************************)
24+
(* Prelude *)
25+
(*****************************************************************************)
26+
27+
(*****************************************************************************)
28+
(* Types *)
29+
(*****************************************************************************)
30+
31+
type program2 = toplevel2 list
32+
and toplevel2 = Ast_lisp.toplevel * info_item
33+
(* the token list contains also the comment-tokens *)
34+
and info_item = (string * Parser_lisp.token list)
35+
36+
let program_of_program2 xs =
37+
xs +> List.map fst
38+
39+
(*****************************************************************************)
40+
(* Wrappers *)
41+
(*****************************************************************************)
42+
let pr2_err, pr2_once = Common.mk_pr2_wrappers Flag.verbose_parsing
43+
44+
(*****************************************************************************)
45+
(* Helpers *)
46+
(*****************************************************************************)
47+
let lexbuf_to_strpos lexbuf =
48+
(Lexing.lexeme lexbuf, Lexing.lexeme_start lexbuf)
49+
50+
(*****************************************************************************)
51+
(* Lexing only *)
52+
(*****************************************************************************)
53+
54+
let tokens2 file =
55+
let table = PI.full_charpos_to_pos_large file in
56+
57+
raise Todo
58+
59+
let tokens a =
60+
Common.profile_code "Parse_lisp.tokens" (fun () -> tokens2 a)
61+
62+
(*****************************************************************************)
63+
(* Main entry point *)
64+
(*****************************************************************************)
65+
66+
let parse2 filename =
67+
68+
let stat = Parse_info.default_stat filename in
69+
let toks_orig = tokens filename in
70+
71+
(* TODO *)
72+
[(), ("", toks_orig)], stat
73+
74+
let parse a =
75+
Common.profile_code "Parse_lisp.parse" (fun () -> parse2 a)
76+
77+
let parse_program file =
78+
let (ast2, _stat) = parse file in
79+
program_of_program2 ast2

0 commit comments

Comments
 (0)