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

Commit

Permalink
* lang_erlang/parsing/parse_erlang.ml: cleanup, remove program2
Browse files Browse the repository at this point in the history
  • Loading branch information
aryx committed Aug 5, 2015
1 parent b1bae75 commit 5b4e9d6
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 105 deletions.
6 changes: 3 additions & 3 deletions code_map/parsing2.ml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type ast =
| ML of Parse_ml.program_and_tokens
| Hs of Parse_hs.program_and_tokens
| Lisp of Parse_lisp.program_and_tokens
| Erlang of Parse_erlang.program2
| Erlang of Parse_erlang.program_and_tokens

| Html of Parse_html.program2
| Js of Parse_js.program_and_tokens
Expand Down Expand Up @@ -298,8 +298,8 @@ let tokens_with_categ_of_file file hentities =
tokens_with_categ_of_file_helper
{ parse = (parse_cache
(fun file -> Erlang (Parse_erlang.parse file +> fst))
(function Erlang x -> x | _ -> raise Impossible));
highlight_visit = Highlight_erlang.visit_toplevel;
(function Erlang x -> [x] | _ -> raise Impossible));
highlight_visit = Highlight_erlang.visit_program;
info_of_tok = Token_helpers_erlang.info_of_tok;
}
file prefs hentities
Expand Down
7 changes: 4 additions & 3 deletions lang_erlang/analyze/highlight_erlang.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ open Entity_code open Highlight_code
module Ast = Ast_erlang
module T = Parser_erlang
module TH = Token_helpers_erlang
module PI = Parse_info

(*****************************************************************************)
(* Prelude *)
Expand All @@ -43,11 +44,11 @@ let fake_no_use2 = (NoInfoPlace, UniqueDef, MultiUse)
* to figure out what kind of ident it is.
*)

let visit_toplevel
let visit_program
~tag_hook
_prefs
(*db_opt *)
(_toplevel, toks)
(_program, toks)
=
let already_tagged = Hashtbl.create 101 in
let atom_already_tagged = Hashtbl.create 101 in
Expand Down Expand Up @@ -101,7 +102,7 @@ let visit_toplevel
(* poor's man identifier tagger *)

(* defs *)
| T.TIdent (s, ii1)::xs when Ast.col_of_info ii1 = 0 ->
| T.TIdent (s, ii1)::xs when PI.col_of_info ii1 = 0 ->
if not (Hashtbl.mem atom_already_tagged s) then begin
Hashtbl.add atom_already_tagged s true;
tag ii1 (Entity (Function, (Def2 fake_no_def2)));
Expand Down
7 changes: 3 additions & 4 deletions lang_erlang/analyze/highlight_erlang.mli
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

val visit_toplevel :
tag_hook:
(Ast_erlang.info -> Highlight_code.category -> unit) ->
val visit_program :
tag_hook: (Parse_info.info -> Highlight_code.category -> unit) ->
Highlight_code.highlighter_preferences ->
(*(Database_php.id * Common.filename * Database_php.database) option -> *)
Ast_erlang.toplevel * Parser_erlang.token list ->
Ast_erlang.program * Parser_erlang.token list ->
unit
35 changes: 0 additions & 35 deletions lang_erlang/parsing/ast_erlang.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,5 @@
(* 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 *)
(*****************************************************************************)

let str_of_info x = Parse_info.str_of_info x
let col_of_info x = Parse_info.col_of_info x
let line_of_info x = Parse_info.line_of_info x
let pos_of_info x = Parse_info.pos_of_info x
20 changes: 3 additions & 17 deletions lang_erlang/parsing/parse_erlang.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,8 @@ module PI = Parse_info
(* Types *)
(*****************************************************************************)

type program2 = toplevel2 list
(* the token list contains also the comment-tokens *)
and toplevel2 =
Ast_erlang.toplevel (* NotParsedCorrectly if parse error *) *
Parser_erlang.token list


(*****************************************************************************)
(* Tokens/Ast association *)
(*****************************************************************************)

(*****************************************************************************)
(* Error diagnostic *)
(*****************************************************************************)
(* the token list contains also the comment-tokens *)
type program_and_tokens = Ast_erlang.program * Parser_erlang.token list

(*****************************************************************************)
(* Lexing only *)
Expand Down Expand Up @@ -96,12 +84,10 @@ let tokens a =
(*****************************************************************************)

let parse2 filename =

let stat = Parse_info.default_stat filename in
let toks_orig = tokens filename in

(* TODO *)
[(), toks_orig], stat
((), toks_orig), stat


let parse a =
Expand Down
9 changes: 3 additions & 6 deletions lang_erlang/parsing/parse_erlang.mli
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@

type program2 = toplevel2 list
(* the token list contains also the comment-tokens *)
and toplevel2 =
Ast_erlang.toplevel (* NotParsedCorrectly if parse error *) *
Parser_erlang.token list
(* the token list contains also the comment-tokens *)
type program_and_tokens = Ast_erlang.program * Parser_erlang.token list

(* This is the main function *)
val parse:
Common.filename -> (program2 * Parse_info.parsing_stat)
Common.filename -> (program_and_tokens * Parse_info.parsing_stat)

(* internal *)
val tokens: Common.filename -> Parser_erlang.token list
30 changes: 15 additions & 15 deletions lang_erlang/parsing/parser_erlang.mly
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@
/*(*-----------------------------------------*)*/

/*(* coupling: Token_helpers.is_real_comment *)*/
%token <Ast_erlang.info> TCommentSpace TCommentNewline TComment
%token <Ast_erlang.info> TCommentMisc
%token <Parse_info.info> TCommentSpace TCommentNewline TComment
%token <Parse_info.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
%token <string * Parse_info.info> TInt
%token <string * Parse_info.info> TFloat
%token <string * Parse_info.info> TChar
%token <string * Parse_info.info> TString

/*(* they call atom TIdent, but I prefer TIdent for consistency *)*/
%token <string * Ast_erlang.info> TIdent TVariable
%token <string * Parse_info.info> TIdent TVariable

/*(* keywords tokens *)*/
%token <Ast_erlang.info>
%token <Parse_info.info>
Tif Tcond Twhen Tcase
Tbegin Tend
Tlet Tof
Expand All @@ -56,17 +56,17 @@
Tquery Tcatch Treceive

/*(* syntax *)*/
%token <Ast_erlang.info> TOParen TCParen
%token <Ast_erlang.info> TOBracket TCBracket
%token <Ast_erlang.info> TOBrace TCBrace
%token <Parse_info.info> TOParen TCParen
%token <Parse_info.info> TOBracket TCBracket
%token <Parse_info.info> TOBrace TCBrace

%token <Ast_erlang.info>
%token <Parse_info.info>
TDot TColon TSemiColon TComma TQuestion
TPipe TPipePipe TArrow TSharp
TUnderscore

/*(* operators *)*/
%token <Ast_erlang.info>
%token <Parse_info.info>
TPlus TMinus TStar TDiv
Tdiv Trem Tor Txor Tbor Tbxor Tbsl Tbsr Tand Tband Tnot Tbnot
TEqEq TSlashEq
Expand All @@ -81,8 +81,8 @@
/*(*-----------------------------------------*)*/

/*(* classic *)*/
%token <Ast_erlang.info> TUnknown
%token <Ast_erlang.info> EOF
%token <Parse_info.info> TUnknown
%token <Parse_info.info> EOF

/*(*-----------------------------------------*)*/
/*(* priorities *)*/
Expand Down
15 changes: 0 additions & 15 deletions lang_erlang/parsing/token_helpers_erlang.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file
* license.txt for more details.
*)

open Common

open Parser_erlang
Expand Down Expand Up @@ -119,17 +118,3 @@ let info_of_tok tok =
visitor_info_of_tok (fun ii -> res := Some ii; ii) tok +> ignore;
Common2.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 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)

9 changes: 2 additions & 7 deletions lang_erlang/parsing/token_helpers_erlang.mli
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ val is_eof : Parser_erlang.token -> bool
val is_comment : Parser_erlang.token -> bool

val info_of_tok :
Parser_erlang.token -> Ast_erlang.info
Parser_erlang.token -> Parse_info.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
(Parse_info.info -> Parse_info.info) -> Parser_erlang.token -> Parser_erlang.token

0 comments on commit 5b4e9d6

Please sign in to comment.