Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

skeleton for lang_lisp/

test plan: ./pfff -tokens_lisp tests/lisp/foo.lisp
currently raise a Todo but will be fixed soon.
  • Loading branch information...
commit 270df0000a13b9cbb24b60ae335421e431285211 1 parent 0e58a2b
pad authored
View
1  .gitignore
@@ -234,3 +234,4 @@ external/ocamlbdb/libcamlbdb.a
/visual/Visual.out
/lang_php/analyze/database_php_storage.ml
+/lang_lisp/parsing/lexer_lisp.ml
View
4 Makefile
@@ -164,6 +164,8 @@ LIBS= commons/commons.cma \
lang_ml/analyze/lib.cma \
lang_nw/parsing/lib.cma \
lang_nw/analyze/lib.cma \
+ lang_lisp/parsing/lib.cma \
+ lang_lisp/analyze/lib.cma \
lang_php/parsing/lib.cma \
lang_php/analyze/basic/lib.cma \
lang_php/analyze/foundation/lib.cma \
@@ -200,6 +202,8 @@ MAKESUBDIRS=commons \
lang_ml/analyze \
lang_nw/parsing \
lang_nw/analyze \
+ lang_lisp/parsing \
+ lang_lisp/analyze \
lang_php/parsing \
lang_php/mini \
lang_php/matcher \
View
69 lang_lisp/analyze/Makefile
@@ -0,0 +1,69 @@
+TOP=../..
+##############################################################################
+# Variables
+##############################################################################
+TARGET=lib
+
+SRC= \
+ highlight_lisp.ml \
+ test_analyze_lisp.ml
+
+-include $(TOP)/Makefile.config
+
+SYSLIBS= str.cma unix.cma $(PCRECMA)
+LIBS=$(TOP)/commons/commons.cma \
+ $(TOP)/h_program-lang/lib.cma \
+ $(TOP)/h_version-control/lib.cma \
+ ../parsing/lib.cma \
+
+MAKESUBDIRS=
+
+INCLUDEDIRS= $(TOP)/commons \
+ $(TOP)/commons/ocollection $(TOP)/commons/ocamlextra \
+ $(TOP)/commons/lib-json \
+ $(TOP)/external/ocamlpcre/lib \
+ $(TOP)/h_program-lang $(TOP)/h_version-control \
+ $(TOP)/globals \
+ ../parsing \
+
+##############################################################################
+# Generic variables
+##############################################################################
+-include $(TOP)/Makefile.common
+
+
+##############################################################################
+# Top rules
+##############################################################################
+all:: rec $(TARGET).cma
+all.opt:: rec.opt $(TARGET).cmxa
+
+rec:
+ set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i all || exit 1; done
+
+rec.opt:
+ set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i all.opt || exit 1; done
+
+clean::
+ set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i clean; done
+depend::
+ set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i depend; done
+
+
+$(TARGET).cma: $(OBJS)
+ $(OCAMLC) -a -o $(TARGET).cma $(OBJS)
+
+$(TARGET).cmxa: $(OPTOBJS) $(LIBS:.cma=.cmxa)
+ $(OCAMLOPT) -a -o $(TARGET).cmxa $(OPTOBJS)
+
+$(TARGET).top: $(OBJS) $(LIBS)
+ $(OCAMLMKTOP) -o $(TARGET).top $(SYSLIBS) $(LIBS) $(OBJS)
+
+clean::
+ rm -f $(TARGET).top
+
+
+##############################################################################
+# Literate Programming rules
+##############################################################################
+
View
0  lang_lisp/analyze/highlight_lisp.ml
No changes.
View
0  lang_lisp/analyze/test_analyze_lisp.ml
No changes.
View
82 lang_lisp/parsing/Makefile
@@ -0,0 +1,82 @@
+TOP=../..
+##############################################################################
+# Variables
+##############################################################################
+TARGET=lib
+
+-include $(TOP)/Makefile.config
+
+SRC= flag_parsing_lisp.ml \
+ ast_lisp.ml \
+ ast_scheme.ml \
+ parser_lisp.ml lexer_lisp.ml \
+ parse_lisp.ml \
+ test_parsing_lisp.ml
+
+# unparse_js.ml \
+# meta_ast_js.ml \
+# export_ast_js.ml \
+# visitor_js.ml lib_parsing_js.ml \
+
+
+SYSLIBS= str.cma unix.cma
+
+# globals.cma is used only for Config.patch in test_parse_nw
+LIBS=$(TOP)/commons/commons.cma \
+ $(TOP)/globals/globals.cma \
+ $(TOP)/h_program-lang/lib.cma \
+
+INCLUDEDIRS= $(TOP)/commons $(TOP)/commons/ocamlextra \
+ $(TOP)/commons/lib-sexp $(TOP)/commons/lib-json \
+ $(TOP)/globals \
+ $(TOP)/h_program-lang \
+
+##############################################################################
+# Generic variables
+##############################################################################
+
+-include $(TOP)/Makefile.common
+
+##############################################################################
+# Top rules
+##############################################################################
+all:: $(TARGET).cma
+all.opt:: $(TARGET).cmxa
+
+$(TARGET).cma: $(OBJS)
+ $(OCAMLC) -a -o $(TARGET).cma $(OBJS)
+
+$(TARGET).cmxa: $(OPTOBJS) $(LIBS:.cma=.cmxa)
+ $(OCAMLOPT) -a -o $(TARGET).cmxa $(OPTOBJS)
+
+$(TARGET).top: $(OBJS) $(LIBS)
+ $(OCAMLMKTOP) -o $(TARGET).top $(SYSLIBS) $(LIBS) $(OBJS)
+
+clean::
+ rm -f $(TARGET).top
+
+
+lexer_lisp.ml: lexer_lisp.mll
+ $(OCAMLLEX) $<
+clean::
+ rm -f lexer_lisp.ml
+beforedepend:: lexer_lisp.ml
+
+
+#parser_nw.ml parser_nw.mli: parser_nw.mly
+# $(OCAMLYACC) $<
+#clean::
+# rm -f parser_nw.ml parser_nw.mli parser_nw.output
+#beforedepend:: parser_nw.ml parser_nw.mli
+#
+#
+#visitor_nw.cmo: visitor_nw.ml
+# $(OCAMLC) -w y -c $<
+
+##############################################################################
+# Generic rules
+##############################################################################
+
+##############################################################################
+# Literate Programming rules
+##############################################################################
View
10 lang_lisp/parsing/ast_lisp.ml
@@ -0,0 +1,10 @@
+
+type info = Parse_info.info
+
+type toplevel = unit
+ (*
+ | TopSexp of sexp
+ | NotParsedCorrectly of info list
+ | FinalDef of info (* EOF *)
+ *)
+
View
4 lang_lisp/parsing/flag_parsing_lisp.ml
@@ -0,0 +1,4 @@
+
+
+let verbose_lexing = ref false
+let verbose_parsing = ref false
View
87 lang_lisp/parsing/lexer_lisp.mll
@@ -0,0 +1,87 @@
+{
+(* Yoann Padioleau
+ *
+ * Copyright (C) 2010 Facebook
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation, with the
+ * special exception on linking described in file license.txt.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file
+ * license.txt for more details.
+ *)
+
+open Common
+
+module Flag = Flag_parsing_lisp
+
+open Parser_lisp
+
+(*****************************************************************************)
+(* Prelude *)
+(*****************************************************************************)
+
+(*****************************************************************************)
+(* Wrappers *)
+(*****************************************************************************)
+let pr2, pr2_once = Common.mk_pr2_wrappers Flag.verbose_lexing
+
+(*****************************************************************************)
+(* Helpers *)
+(*****************************************************************************)
+exception Lexical of string
+
+(* ---------------------------------------------------------------------- *)
+let tok lexbuf =
+ Lexing.lexeme lexbuf
+let tokinfo lexbuf =
+ Parse_info.tokinfo_str_pos (Lexing.lexeme lexbuf) (Lexing.lexeme_start lexbuf)
+
+}
+
+(*****************************************************************************)
+
+let letter = ['a'-'z''A'-'Z']
+let digit = ['0'-'9']
+
+(*****************************************************************************)
+rule sexp = parse
+
+ (* ----------------------------------------------------------------------- *)
+ (* spacing/comments *)
+ (* ----------------------------------------------------------------------- *)
+ | ";" [^'\n' '\r']* {
+ TComment(tokinfo lexbuf)
+ }
+ | [' ''\t'] { TCommentSpace (tokinfo lexbuf) }
+ | "\n" { TCommentNewline (tokinfo lexbuf) }
+
+ (* ----------------------------------------------------------------------- *)
+ (* Symbols *)
+ (* ----------------------------------------------------------------------- *)
+
+ | '(' { TOParen (tokinfo lexbuf) }
+ | ')' { TCParen (tokinfo lexbuf) }
+
+ (* ----------------------------------------------------------------------- *)
+ (* Keywords and ident *)
+ (* ----------------------------------------------------------------------- *)
+
+ (* ----------------------------------------------------------------------- *)
+ (* Constant *)
+ (* ----------------------------------------------------------------------- *)
+
+ | digit+ {
+ TNumber(tok lexbuf, tokinfo lexbuf)
+ }
+
+ (* ----------------------------------------------------------------------- *)
+ | eof { EOF (tokinfo lexbuf +> Parse_info.rewrap_str "") }
+ | _ {
+ if !Flag.verbose_lexing
+ then pr2_once ("LEXER:unrecognised symbol, in token rule:"^tok lexbuf);
+ TUnknown (tokinfo lexbuf)
+ }
View
79 lang_lisp/parsing/parse_lisp.ml
@@ -0,0 +1,79 @@
+(* Yoann Padioleau
+ *
+ * Copyright (C) 2010 Facebook
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License (GPL)
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * file license.txt for more details.
+ *)
+
+open Common
+
+module Ast = Ast_lisp
+module Flag = Flag_parsing_lisp
+
+module PI = Parse_info
+
+
+(*****************************************************************************)
+(* Prelude *)
+(*****************************************************************************)
+
+(*****************************************************************************)
+(* Types *)
+(*****************************************************************************)
+
+type program2 = toplevel2 list
+ and toplevel2 = Ast_lisp.toplevel * info_item
+ (* the token list contains also the comment-tokens *)
+ and info_item = (string * Parser_lisp.token list)
+
+let program_of_program2 xs =
+ xs +> List.map fst
+
+(*****************************************************************************)
+(* Wrappers *)
+(*****************************************************************************)
+let pr2_err, pr2_once = Common.mk_pr2_wrappers Flag.verbose_parsing
+
+(*****************************************************************************)
+(* Helpers *)
+(*****************************************************************************)
+let lexbuf_to_strpos lexbuf =
+ (Lexing.lexeme lexbuf, Lexing.lexeme_start lexbuf)
+
+(*****************************************************************************)
+(* Lexing only *)
+(*****************************************************************************)
+
+let tokens2 file =
+ let table = PI.full_charpos_to_pos_large file in
+
+ raise Todo
+
+let tokens a =
+ Common.profile_code "Parse_lisp.tokens" (fun () -> tokens2 a)
+
+(*****************************************************************************)
+(* Main entry point *)
+(*****************************************************************************)
+
+let parse2 filename =
+
+ let stat = Parse_info.default_stat filename in
+ let toks_orig = tokens filename in
+
+ (* TODO *)
+ [(), ("", toks_orig)], stat
+
+let parse a =
+ Common.profile_code "Parse_lisp.parse" (fun () -> parse2 a)
+
+let parse_program file =
+ let (ast2, _stat) = parse file in
+ program_of_program2 ast2
View
14 lang_lisp/parsing/parse_lisp.mli
@@ -0,0 +1,14 @@
+
+type program2 = toplevel2 list
+ and toplevel2 = Ast_lisp.toplevel * info_item
+ (* the token list contains also the comment-tokens *)
+ and info_item = (string * Parser_lisp.token list)
+
+(* This is the main function *)
+val parse:
+ Common.filename -> (program2 * Parse_info.parsing_stat)
+
+
+(* internal *)
+val tokens: Common.filename -> Parser_lisp.token list
+
View
13 lang_lisp/parsing/parser_lisp.ml
@@ -0,0 +1,13 @@
+
+type token =
+ | TComment of (Ast_lisp.info)
+ | TCommentSpace of (Ast_lisp.info)
+ | TCommentNewline of (Ast_lisp.info)
+
+ | TNumber of (string * Ast_lisp.info)
+ | TOParen of (Ast_lisp.info)
+ | TCParen of (Ast_lisp.info)
+
+ | TUnknown of (Ast_lisp.info)
+ | EOF of (Ast_lisp.info)
+
View
35 lang_lisp/parsing/test_parsing_lisp.ml
@@ -0,0 +1,35 @@
+open Common
+
+open Ast_lisp
+module Ast = Ast_lisp
+module Flag = Flag_parsing_lisp
+
+open OUnit
+
+(*****************************************************************************)
+(* Subsystem testing *)
+(*****************************************************************************)
+
+let test_tokens_lisp file =
+ if not (file =~ ".*\\.nw")
+ then pr2 "warning: seems not a noweb file";
+
+ Flag.verbose_lexing := true;
+ Flag.verbose_parsing := true;
+
+ let toks = Parse_lisp.tokens file in
+ toks +> List.iter (fun x -> pr2_gen x);
+ ()
+
+(*****************************************************************************)
+(* Unit tests *)
+(*****************************************************************************)
+
+(*****************************************************************************)
+(* Main entry for Arg *)
+(*****************************************************************************)
+
+let actions () = [
+ "-tokens_lisp", " <file>",
+ Common.mk_action_1_arg test_tokens_lisp;
+]
View
9 lang_lisp/parsing/test_parsing_lisp.mli
@@ -0,0 +1,9 @@
+
+(* Print the set of tokens in a .lisp file *)
+val test_tokens_lisp : Common.filename -> unit
+
+(* This makes accessible the different test_xxx functions above from
+ * the command line, e.g. '$ pfff -parse_lisp foo.lisp will call the
+ * test_parse_lisp function.
+ *)
+val actions : unit -> Common.cmdline_actions
View
3  main.ml
@@ -57,8 +57,9 @@ let all_actions () =
Test_parsing_ml.actions()++
Test_parsing_php.actions()++
Test_parsing_js.actions()++
- Test_parsing_nw.actions()++
Test_parsing_cpp.actions()++
+ Test_parsing_nw.actions()++
+ Test_parsing_lisp.actions()++
Test_mini_php.actions()++
Test_analyze_cpp.actions () ++
View
7 tests/lisp/foo.lisp
@@ -0,0 +1,7 @@
+;;;***************************************************************************
+;;; Prelude
+;;;***************************************************************************
+
+(setq debug-on-error t) ;or --debug-init
+
+(defun h(s) (concat (getenv "HOME") "/" s))

0 comments on commit 270df00

Please sign in to comment.
Something went wrong with that request. Please try again.