Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

erlang: basic lexer

  • Loading branch information...
commit 30b92d9688598c996bd9df73282813732f56e68d 1 parent b324f85
@aryx aryx authored
View
2  .gitignore
@@ -260,3 +260,5 @@ external/ocamlbdb/libcamlbdb.a
/lang_php/meta/ffi
/lang_php/meta/gen_code
/DB_LIGHT.marshall
+/lang_erlang/parsing/parse_erlang.ml
+/lang_erlang/parsing/parse_erlang.mli
View
3  Makefile
@@ -150,6 +150,7 @@ BASICLIBS=commons/commons.cma \
lang_java/parsing/lib.cma \
lang_python/parsing/lib.cma \
lang_csharp/parsing/lib.cma \
+ lang_erlang/parsing/lib.cma \
BASICSYSLIBS=nums.cma bigarray.cma str.cma unix.cma
@@ -199,6 +200,7 @@ LIBS= commons/commons.cma \
lang_python/analyze/lib.cma \
lang_csharp/parsing/lib.cma \
lang_csharp/analyze/lib.cma \
+ lang_erlang/parsing/lib.cma \
MAKESUBDIRS=commons \
$(BDBDIR) $(REGEXPDIR) $(MPIDIR) \
@@ -232,6 +234,7 @@ MAKESUBDIRS=commons \
lang_python/analyze \
lang_csharp/parsing \
lang_csharp/analyze \
+ lang_erlang/parsing \
lang_php/analyze \
lang_php/analyze/basic \
lang_php/analyze/foundation \
View
60 lang_erlang/parsing/ast_erlang.ml
@@ -0,0 +1,60 @@
+(* 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
+
+
+(*****************************************************************************)
+(* Prelude *)
+(*****************************************************************************)
+
+(*
+ *)
+
+(*****************************************************************************)
+(* The AST related types *)
+(*****************************************************************************)
+
+(* ------------------------------------------------------------------------- *)
+(* Token/info *)
+(* ------------------------------------------------------------------------- *)
+type info = Parse_info.info
+and tok = info
+
+(* a shortcut to annotate some information with token/position information *)
+and 'a wrap = 'a * info
+
+(* ------------------------------------------------------------------------- *)
+(* Names *)
+(* ------------------------------------------------------------------------- *)
+
+(* ------------------------------------------------------------------------- *)
+(* Expressions *)
+(* ------------------------------------------------------------------------- *)
+
+(* ------------------------------------------------------------------------- *)
+(* Class *)
+(* ------------------------------------------------------------------------- *)
+
+(* ------------------------------------------------------------------------- *)
+(* Toplevel phrases *)
+(* ------------------------------------------------------------------------- *)
+
+type toplevel = unit
+
+type program = unit
+
+(*****************************************************************************)
+(* Wrappers *)
+(*****************************************************************************)
View
5 lang_erlang/parsing/flag_parsing_erlang.ml
@@ -0,0 +1,5 @@
+
+let verbose_lexing = ref false
+let verbose_parsing = ref false
+
+let debug_lexer = ref false
View
222 lang_erlang/parsing/lexer_erlang.mll
@@ -0,0 +1,222 @@
+{
+(* 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 Ast = Ast_erlang
+module Flag = Flag_parsing_erlang
+
+open Parser_erlang
+
+
+(*****************************************************************************)
+(* Prelude *)
+(*****************************************************************************)
+
+(*
+ * http://www.erlang.org/download/erl_spec47.ps.gz appendix E
+ * and erlang-otp/lib/compiler/src/core_scan.erl
+ *)
+
+(*****************************************************************************)
+(* 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 keyword_table = Common.hash_of_list [
+ (* real keywords *)
+ "if", (fun ii -> Tif ii);
+ "cond", (fun ii -> Tcond ii);
+ "when", (fun ii -> Twhen ii);
+ "case", (fun ii -> Tcase ii);
+ "begin", (fun ii -> Tbegin ii);
+ "end", (fun ii -> Tend ii);
+ "let", (fun ii -> Tlet ii);
+ "of", (fun ii -> Tof ii);
+ "fun", (fun ii -> Tfun ii);
+ "after", (fun ii -> Tafter ii);
+ "query", (fun ii -> Tquery ii);
+ "catch", (fun ii -> Tcatch ii);
+ "receive", (fun ii -> Treceive ii);
+
+ (* operators *)
+ "div", (fun ii -> Tdiv ii);
+ "rem", (fun ii -> Trem ii);
+ "or", (fun ii -> Tor ii);
+ "xor", (fun ii -> Txor ii);
+ "bor", (fun ii -> Tbor ii);
+ "bxor", (fun ii -> Tbxor ii);
+ "bsl", (fun ii -> Tbsl ii);
+ "bsr", (fun ii -> Tbsr ii);
+ "and", (fun ii -> Tand ii);
+ "band", (fun ii -> Tband ii);
+ "not", (fun ii -> Tnot ii);
+ "bnot", (fun ii -> Tbnot ii);
+]
+
+}
+(*****************************************************************************)
+
+let letter = ['A'-'Z' 'a'-'z']
+let digit = ['0'-'9']
+
+let lowercase = ['a'-'z']
+let uppercase = ['A'-'Z']
+
+let newline = '\n'
+let space = [' ' '\t']
+
+let nonzerodigit = ['1'-'9']
+let octdigit = ['0'-'7']
+let hexdigit = digit | ['a'-'f'] | ['A'-'F']
+
+(* TODO, was copied from python *)
+let decimalinteger = nonzerodigit digit* | '0'
+let octinteger = '0' octdigit+
+let hexinteger = '0' ('x' | 'X') hexdigit+
+
+let integer = (decimalinteger | octinteger | hexinteger)
+
+(* TODO, was in csharp *)
+let escapeseq =
+ ( '\\' '^' _ |
+ '\\' ['\'' '"' '\\' 'b' 'd' 'e' 'f' 'n' 'r' 's' 't' 'v'] |
+ '\\' octdigit |
+ '\\' octdigit octdigit |
+ '\\' octdigit octdigit octdigit
+ )
+
+let namechars = (letter | digit | '@' | '_')+
+
+let atom = lowercase namechars*
+let variable = (uppercase namechars* | '_' namechars+)
+
+(*****************************************************************************)
+
+rule token = parse
+
+ (* ----------------------------------------------------------------------- *)
+ (* spacing/comments *)
+ (* ----------------------------------------------------------------------- *)
+
+ | "%" [^ '\n']* { TComment (tokinfo lexbuf) }
+
+ | newline { TCommentNewline (tokinfo lexbuf) }
+ | space+ { TCommentSpace (tokinfo lexbuf) }
+
+ (* ----------------------------------------------------------------------- *)
+ (* symbols *)
+ (* ----------------------------------------------------------------------- *)
+
+ | "(" { TOParen(tokinfo lexbuf) } | ")" { TCParen(tokinfo lexbuf) }
+ | "{" { TOBrace(tokinfo lexbuf) } | "}" { TCBrace(tokinfo lexbuf) }
+ | "[" { TOBracket(tokinfo lexbuf) } | "]" { TCBracket(tokinfo lexbuf) }
+
+ | "." { TDot(tokinfo lexbuf) }
+ | ":" { TColon(tokinfo lexbuf) }
+ | ";" { TSemiColon(tokinfo lexbuf) }
+ | "," { TComma(tokinfo lexbuf) }
+ | "?" { TQuestion(tokinfo lexbuf) }
+
+ | "|" { TPipe(tokinfo lexbuf) }
+ | "||" { TPipe(tokinfo lexbuf) }
+ | "->" { TArrow(tokinfo lexbuf) }
+ | "#" { TSharp(tokinfo lexbuf) }
+
+ | "+" { TPlus(tokinfo lexbuf) } | "-" { TMinus(tokinfo lexbuf) }
+ | "*" { TStar(tokinfo lexbuf) } | "/" { TDiv(tokinfo lexbuf) }
+
+ | "=" { TEq (tokinfo lexbuf) } | "==" { TEqEq(tokinfo lexbuf) }
+ | "/=" { TSlashEq(tokinfo lexbuf) }
+ | "=:=" { TEqColonEq (tokinfo lexbuf) }
+ | "=/=" { TEqSlashEq(tokinfo lexbuf) }
+ | "<" { TLess(tokinfo lexbuf) } | ">" { TMore(tokinfo lexbuf) }
+ | "=<" { TLessEq(tokinfo lexbuf) } | ">=" { TMoreEq(tokinfo lexbuf) }
+
+ | "++" { TInc(tokinfo lexbuf) }
+ | "--" { TDec(tokinfo lexbuf) }
+
+ | "!" { TBang(tokinfo lexbuf) }
+ | "<-" { TAssign(tokinfo lexbuf) }
+
+ (* ----------------------------------------------------------------------- *)
+ (* Keywords and ident *)
+ (* ----------------------------------------------------------------------- *)
+ | atom {
+ let info = tokinfo lexbuf in
+ let s = tok lexbuf in
+ match Common.optionise (fun () -> Hashtbl.find keyword_table s) with
+ | Some f -> f info
+ | None -> TIdent (s, info)
+ }
+ | variable { TVariable (tok lexbuf, tokinfo lexbuf) }
+
+ | '_' { TUnderscore (tokinfo lexbuf) }
+
+ (* ----------------------------------------------------------------------- *)
+ (* Constant *)
+ (* ----------------------------------------------------------------------- *)
+ | integer { TInt (tok lexbuf, tokinfo lexbuf) }
+
+ (* TODO: TChar ? TFloat ? *)
+
+ (* ----------------------------------------------------------------------- *)
+ (* Strings *)
+ (* ----------------------------------------------------------------------- *)
+
+ | '"' {
+ let info = tokinfo lexbuf in
+ let s = string_double_quote lexbuf in
+ TString (s, info +> Parse_info.tok_add_s (s ^ "\""))
+ }
+
+ (* ----------------------------------------------------------------------- *)
+ (* Misc *)
+ (* ----------------------------------------------------------------------- *)
+
+ (* ----------------------------------------------------------------------- *)
+ (* eof *)
+ (* ----------------------------------------------------------------------- *)
+ | eof { EOF (tokinfo lexbuf) }
+
+ | _ {
+ if !Flag.verbose_lexing
+ then pr2_once ("LEXER:unrecognised symbol, in token rule:"^tok lexbuf);
+ TUnknown (tokinfo lexbuf)
+ }
+
+(*****************************************************************************)
+
+and string_double_quote = parse
+ | '"' { "" }
+
+ | [^ '\\' '\"' '\n']* {
+ let s = tok lexbuf in s ^ string_double_quote lexbuf
+ }
+ | escapeseq { let s = tok lexbuf in s ^ string_double_quote lexbuf }
+
+
+ | eof { pr2 "LEXER: end of file in string_double_quote"; "'"}
+ | _ { let s = tok lexbuf in
+ pr2 ("LEXER: unrecognised symbol in string_double_quote:"^s);
+ s ^ string_double_quote lexbuf
+ }
View
53 lang_erlang/parsing/lib_parsing_erlang.ml
@@ -0,0 +1,53 @@
+(* 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
+
+open Ast_erlang
+
+module Ast = Ast_erlang
+module Flag = Flag_parsing_erlang
+
+(* module V = Visitor_erlang *)
+
+(*****************************************************************************)
+(* Wrappers *)
+(*****************************************************************************)
+
+(*****************************************************************************)
+(* Filemames *)
+(*****************************************************************************)
+
+let find_erlang_files_of_dir_or_files xs =
+ Common.files_of_dir_or_files_no_vcs_nofilter xs
+ +> List.filter (fun filename ->
+ let ftype = File_type.file_type_of_file filename in
+ match ftype with
+ | File_type.PL (File_type.Erlang) -> true
+ | _ -> false
+ ) |> Common.sort
+
+(*****************************************************************************)
+(* Extract infos *)
+(*****************************************************************************)
+
+(*****************************************************************************)
+(* Max min, range *)
+(*****************************************************************************)
+
+(*****************************************************************************)
+(* AST helpers *)
+(*****************************************************************************)
+
View
132 lang_erlang/parsing/parser_erlang.mly
@@ -0,0 +1,132 @@
+%{
+(* 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.
+ *)
+
+(*
+ * src: http://www.erlang.org/download/erl_spec47.ps.gz appendix E
+ * and erlang-otp/lib/compiler/src/core_parse.yrl
+ *)
+open Common
+
+open Ast_erlang
+
+%}
+
+/*(*************************************************************************)*/
+/*(* tokens *)*/
+/*(*************************************************************************)*/
+
+/*(*-----------------------------------------*)*/
+/*(* the comment tokens *)*/
+/*(*-----------------------------------------*)*/
+
+/*(* coupling: Token_helpers.is_real_comment *)*/
+%token <Ast_erlang.info> TCommentSpace TCommentNewline TComment
+%token <Ast_erlang.info> TCommentMisc
+
+/*(*-----------------------------------------*)*/
+/*(* the normal tokens *)*/
+/*(*-----------------------------------------*)*/
+
+/*(* tokens with "values" *)*/
+%token <string * Ast_erlang.info> TInt
+%token <string * Ast_erlang.info> TFloat
+%token <string * Ast_erlang.info> TChar
+%token <string * Ast_erlang.info> TString
+
+/*(* they call atom TIdent, but I prefer TIdent for consistency *)*/
+%token <string * Ast_erlang.info> TIdent TVariable
+
+/*(* keywords tokens *)*/
+%token <Ast_erlang.info>
+ Tif Tcond Twhen Tcase
+ Tbegin Tend
+ Tlet Tof
+ Tfun
+ Tafter
+ Tquery Tcatch Treceive
+
+/*(* syntax *)*/
+%token <Ast_erlang.info> TOParen TCParen
+%token <Ast_erlang.info> TOBracket TCBracket
+%token <Ast_erlang.info> TOBrace TCBrace
+
+%token <Ast_erlang.info>
+ TDot TColon TSemiColon TComma TQuestion
+ TPipe TPipePipe TArrow TSharp
+ TUnderscore
+
+/*(* operators *)*/
+%token <Ast_erlang.info>
+ TPlus TMinus TStar TDiv
+ Tdiv Trem Tor Txor Tbor Tbxor Tbsl Tbsr Tand Tband Tnot Tbnot
+ TEqEq TSlashEq
+ TEqColonEq TEqSlashEq
+ TLess TMore
+ TLessEq TMoreEq
+ TInc TDec
+ TEq TBang TAssign
+
+/*(*-----------------------------------------*)*/
+/*(* extra tokens: *)*/
+/*(*-----------------------------------------*)*/
+
+/*(* classic *)*/
+%token <Ast_erlang.info> TUnknown
+%token <Ast_erlang.info> EOF
+
+/*(*-----------------------------------------*)*/
+/*(* priorities *)*/
+/*(*-----------------------------------------*)*/
+
+/*(*************************************************************************)*/
+/*(* Rules type declaration *)*/
+/*(*************************************************************************)*/
+
+%start main
+%type <Ast_erlang.program> main
+
+%%
+
+/*(*************************************************************************)*/
+/*(* TOC *)*/
+/*(*************************************************************************)*/
+
+/*(*************************************************************************)*/
+/*(* Toplevel, compilation units *)*/
+/*(*************************************************************************)*/
+
+main: EOF { () }
+
+/*(*************************************************************************)*/
+/*(* Names *)*/
+/*(*************************************************************************)*/
+
+/*(*************************************************************************)*/
+/*(* Expressions *)*/
+/*(*************************************************************************)*/
+
+/*(*************************************************************************)*/
+/*(* Classes *)*/
+/*(*************************************************************************)*/
+
+/*(*************************************************************************)*/
+/*(* Misc *)*/
+/*(*************************************************************************)*/
+
+/*(*************************************************************************)*/
+/*(* xxx_opt, xxx_list *)*/
+/*(*************************************************************************)*/
+
View
51 lang_erlang/parsing/test_parsing_erlang.ml
@@ -0,0 +1,51 @@
+open Common
+
+open Ast_erlang
+module Ast = Ast_erlang
+module Flag = Flag_parsing_erlang
+
+open OUnit
+
+(*****************************************************************************)
+(* Subsystem testing *)
+(*****************************************************************************)
+
+let test_tokens_erlang file =
+ if not (file =~ ".*\\.py")
+ then pr2 "warning: seems not a python file";
+
+ Flag.verbose_lexing := true;
+ Flag.verbose_parsing := true;
+
+ let toks = Parse_erlang.tokens file in
+ toks +> List.iter (fun x -> pr2_gen x);
+ ()
+
+let test_parse_erlang xs =
+
+ let fullxs = Lib_parsing_erlang.find_erlang_files_of_dir_or_files xs in
+ let stat_list = ref [] in
+
+ fullxs +> List.iter (fun file ->
+ pr2 ("PARSING: " ^ file);
+
+ let (xs, stat) = Parse_erlang.parse file in
+ Common.push2 stat stat_list;
+ );
+ Parse_info.print_parsing_stat_list !stat_list;
+ ()
+
+(*****************************************************************************)
+(* Unit tests *)
+(*****************************************************************************)
+
+(*****************************************************************************)
+(* Main entry for Arg *)
+(*****************************************************************************)
+
+let actions () = [
+ "-tokens_erlang", " <file>",
+ Common.mk_action_1_arg test_tokens_erlang;
+ "-parse_erlang", " <files or dirs>",
+ Common.mk_action_n_arg test_parse_erlang;
+]
View
10 lang_erlang/parsing/test_parsing_erlang.mli
@@ -0,0 +1,10 @@
+
+
+(* Print the set of tokens in a .py file *)
+val test_tokens_erlang : Common.filename -> unit
+
+(* This makes accessible the different test_xxx functions above from
+ * the command line, e.g. '$ pfff -parse_erlang foo.py will call the
+ * test_parse_erlang function.
+ *)
+val actions : unit -> Common.cmdline_actions
View
141 lang_erlang/parsing/token_helpers_erlang.ml
@@ -0,0 +1,141 @@
+(* 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
+
+open Parser_erlang
+
+module Ast = Ast_erlang
+module PI = Parse_info
+
+(*****************************************************************************)
+(* Token Helpers *)
+(*****************************************************************************)
+
+let is_eof = function
+ | EOF _ -> true
+ | _ -> false
+
+let is_comment = function
+ | TComment _ | TCommentSpace _ | TCommentNewline _ -> true
+ | TCommentMisc _ -> true
+ | _ -> false
+
+let is_just_comment = function
+ | TComment _ -> true
+ | _ -> false
+
+(*****************************************************************************)
+(* Visitors *)
+(*****************************************************************************)
+
+let visitor_info_of_tok f = function
+ | TCommentSpace ii -> TCommentSpace (f ii)
+ | TCommentNewline ii -> TCommentNewline (f ii)
+ | TComment ii -> TComment (f ii)
+ | TCommentMisc ii -> TCommentMisc (f ii)
+
+ | TInt (s, ii) -> TInt (s, f ii)
+ | TFloat (s, ii) -> TFloat (s, f ii)
+ | TChar (s, ii) -> TChar (s, f ii)
+ | TString (s, ii) -> TString (s, f ii)
+ | TIdent (s, ii) -> TIdent (s, f ii)
+ | TVariable (s, ii) -> TVariable (s, f ii)
+
+ | Tif (ii) -> Tif (f ii)
+ | Tcond (ii) -> Tcond (f ii)
+ | Twhen (ii) -> Twhen (f ii)
+ | Tcase (ii) -> Tcase (f ii)
+ | Tbegin (ii) -> Tbegin (f ii)
+ | Tend (ii) -> Tend (f ii)
+ | Tlet (ii) -> Tlet (f ii)
+ | Tof (ii) -> Tof (f ii)
+ | Tfun (ii) -> Tfun (f ii)
+ | Tafter (ii) -> Tafter (f ii)
+ | Tquery (ii) -> Tquery (f ii)
+ | Tcatch (ii) -> Tcatch (f ii)
+ | Treceive (ii) -> Treceive (f ii)
+ | TOParen (ii) -> TOParen (f ii)
+ | TCParen (ii) -> TCParen (f ii)
+ | TOBracket (ii) -> TOBracket (f ii)
+ | TCBracket (ii) -> TCBracket (f ii)
+ | TOBrace (ii) -> TOBrace (f ii)
+ | TCBrace (ii) -> TCBrace (f ii)
+ | TDot (ii) -> TDot (f ii)
+ | TColon (ii) -> TColon (f ii)
+ | TSemiColon (ii) -> TSemiColon (f ii)
+ | TComma (ii) -> TComma (f ii)
+ | TQuestion (ii) -> TQuestion (f ii)
+ | TPipe (ii) -> TPipe (f ii)
+ | TPipePipe (ii) -> TPipePipe (f ii)
+ | TArrow (ii) -> TArrow (f ii)
+ | TSharp (ii) -> TSharp (f ii)
+ | TUnderscore (ii) -> TUnderscore (f ii)
+ | TPlus (ii) -> TPlus (f ii)
+ | TMinus (ii) -> TMinus (f ii)
+ | TStar (ii) -> TStar (f ii)
+ | TDiv (ii) -> TDiv (f ii)
+ | Tdiv (ii) -> Tdiv (f ii)
+ | Trem (ii) -> Trem (f ii)
+ | Tor (ii) -> Tor (f ii)
+ | Txor (ii) -> Txor (f ii)
+ | Tbor (ii) -> Tbor (f ii)
+ | Tbxor (ii) -> Tbxor (f ii)
+ | Tbsl (ii) -> Tbsl (f ii)
+ | Tbsr (ii) -> Tbsr (f ii)
+ | Tand (ii) -> Tand (f ii)
+ | Tband (ii) -> Tband (f ii)
+ | Tnot (ii) -> Tnot (f ii)
+ | Tbnot (ii) -> Tbnot (f ii)
+ | TEqEq (ii) -> TEqEq (f ii)
+ | TSlashEq (ii) -> TSlashEq (f ii)
+ | TEqColonEq (ii) -> TEqColonEq (f ii)
+ | TEqSlashEq (ii) -> TEqSlashEq (f ii)
+ | TLess (ii) -> TLess (f ii)
+ | TMore (ii) -> TMore (f ii)
+ | TLessEq (ii) -> TLessEq (f ii)
+ | TMoreEq (ii) -> TMoreEq (f ii)
+ | TInc (ii) -> TInc (f ii)
+ | TDec (ii) -> TDec (f ii)
+ | TEq (ii) -> TEq (f ii)
+ | TBang (ii) -> TBang (f ii)
+ | TAssign (ii) -> TAssign (f ii)
+
+
+ | TUnknown ii -> TUnknown (f ii)
+ | EOF ii -> EOF (f ii)
+
+
+let info_of_tok tok =
+ let res = ref None in
+ visitor_info_of_tok (fun ii -> res := Some ii; ii) tok +> ignore;
+ Common.some !res
+
+(*****************************************************************************)
+(* Accessors *)
+(*****************************************************************************)
+
+let linecol_of_tok tok =
+ let info = info_of_tok tok in
+ PI.line_of_info info, PI.col_of_info info
+
+let col_of_tok x = snd (linecol_of_tok x)
+let line_of_tok x = fst (linecol_of_tok x)
+
+let str_of_tok x = PI.str_of_info (info_of_tok x)
+let file_of_tok x = PI.file_of_info (info_of_tok x)
+let pos_of_tok x = PI.pos_of_info (info_of_tok x)
+
+let pinfo_of_tok x = Parse_info.pinfo_of_info (info_of_tok x)
View
16 lang_erlang/parsing/token_helpers_erlang.mli
@@ -0,0 +1,16 @@
+
+val is_eof : Parser_erlang.token -> bool
+val is_comment : Parser_erlang.token -> bool
+
+val info_of_tok :
+ Parser_erlang.token -> Ast_erlang.info
+val visitor_info_of_tok :
+ (Ast_erlang.info -> Ast_erlang.info) -> Parser_erlang.token -> Parser_erlang.token
+
+val line_of_tok : Parser_erlang.token -> int
+val str_of_tok : Parser_erlang.token -> string
+val file_of_tok : Parser_erlang.token -> Common.filename
+val pos_of_tok : Parser_erlang.token -> int
+
+(*val pos_of_tok : Parser_erlang.token -> int*)
+val pinfo_of_tok : Parser_erlang.token -> Parse_info.token
View
1  main.ml
@@ -76,6 +76,7 @@ let all_actions () =
Test_parsing_python.actions()++
Test_parsing_csharp.actions()++
Test_parsing_java.actions()++
+ Test_parsing_erlang.actions()++
Test_mini_php.actions()++
Test_analyze_cpp.actions () ++
View
10 tests/erlang/hw.erl
@@ -0,0 +1,10 @@
+-module(hello).
+-export([hello_world/0]).
+
+hello_world()->
+ io:format("Hello World ~n").
+
+%-----------------------------------------------------------------------
+%And Executing:
+%
+%hello:hello_world().
Please sign in to comment.
Something went wrong with that request. Please try again.