Permalink
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...
1 parent 0e58a2b commit 270df0000a13b9cbb24b60ae335421e431285211 pad committed Oct 21, 2010
View
@@ -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
@@ -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
@@ -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
+##############################################################################
+
No changes.
No changes.
View
@@ -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
+##############################################################################
@@ -0,0 +1,10 @@
+
+type info = Parse_info.info
+
+type toplevel = unit
+ (*
+ | TopSexp of sexp
+ | NotParsedCorrectly of info list
+ | FinalDef of info (* EOF *)
+ *)
+
@@ -0,0 +1,4 @@
+
+
+let verbose_lexing = ref false
+let verbose_parsing = ref false
@@ -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)
+ }
@@ -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
@@ -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
+
@@ -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)
+
Oops, something went wrong.

0 comments on commit 270df00

Please sign in to comment.