From 5a6a8b2b8e515941f9a2b3cc051da646ae696251 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Sat, 21 Dec 2019 17:01:52 +0000 Subject: [PATCH] Rename parsing/ to src/ And some refactoring of the main code and command line parsing. --- .gitignore | 12 ++++----- Makefile.in | 4 +-- configure.ac | 2 +- {parsing => src}/Goalfile.in | 0 {parsing => src}/Makefile.in | 7 +++++- {parsing => src}/ast.ml | 0 {parsing => src}/ast.mli | 0 {parsing => src}/lexer.mli | 0 {parsing => src}/lexer.mll | 0 src/main.ml | 55 +++++++++++++++++++++++++++++++++++++++++ parsing/main.ml => src/parse.ml | 6 ++--- src/parse.mli | 21 ++++++++++++++++ {parsing => src}/parser.mly | 0 13 files changed, 93 insertions(+), 14 deletions(-) rename {parsing => src}/Goalfile.in (100%) rename {parsing => src}/Makefile.in (95%) rename {parsing => src}/ast.ml (100%) rename {parsing => src}/ast.mli (100%) rename {parsing => src}/lexer.mli (100%) rename {parsing => src}/lexer.mll (100%) create mode 100644 src/main.ml rename parsing/main.ml => src/parse.ml (95%) create mode 100644 src/parse.mli rename {parsing => src}/parser.mly (100%) diff --git a/.gitignore b/.gitignore index 535fea6..bd1d969 100644 --- a/.gitignore +++ b/.gitignore @@ -18,10 +18,10 @@ config.log /config.h.in /config.status /install-sh -/parsing/goals -/parsing/lexer.ml -/parsing/parser.conflicts -/parsing/parser.ml -/parsing/parser.mli -/parsing/stamp-parser +/src/goals +/src/lexer.ml +/src/parser.conflicts +/src/parser.ml +/src/parser.mli +/src/stamp-parser /stamp-h diff --git a/Makefile.in b/Makefile.in index 2928514..30fe5b1 100644 --- a/Makefile.in +++ b/Makefile.in @@ -16,10 +16,10 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -SUBDIRS = parsing +SUBDIRS = src all clean depend install: - $(MAKE) -C parsing $@ + $(MAKE) -C src $@ config.h: stamp-h stamp-h: config.h.in config.status diff --git a/configure.ac b/configure.ac index a542e70..d521660 100644 --- a/configure.ac +++ b/configure.ac @@ -53,6 +53,6 @@ dnl Produce output files. AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h]) AC_CONFIG_FILES([Goalfile Makefile - parsing/Goalfile parsing/Makefile]) + src/Goalfile src/Makefile]) AC_OUTPUT diff --git a/parsing/Goalfile.in b/src/Goalfile.in similarity index 100% rename from parsing/Goalfile.in rename to src/Goalfile.in diff --git a/parsing/Makefile.in b/src/Makefile.in similarity index 95% rename from parsing/Makefile.in rename to src/Makefile.in index 666bd6b..15e8006 100644 --- a/parsing/Makefile.in +++ b/src/Makefile.in @@ -16,7 +16,12 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -OBJECTS = ast.cmx parser.cmx lexer.cmx main.cmx +OBJECTS = \ + ast.cmx \ + parser.cmx \ + lexer.cmx \ + parse.cmx \ + main.cmx all: goals diff --git a/parsing/ast.ml b/src/ast.ml similarity index 100% rename from parsing/ast.ml rename to src/ast.ml diff --git a/parsing/ast.mli b/src/ast.mli similarity index 100% rename from parsing/ast.mli rename to src/ast.mli diff --git a/parsing/lexer.mli b/src/lexer.mli similarity index 100% rename from parsing/lexer.mli rename to src/lexer.mli diff --git a/parsing/lexer.mll b/src/lexer.mll similarity index 100% rename from parsing/lexer.mll rename to src/lexer.mll diff --git a/src/main.ml b/src/main.ml new file mode 100644 index 0000000..30ba31f --- /dev/null +++ b/src/main.ml @@ -0,0 +1,55 @@ +(* Goalfile parser + * Copyright (C) 2019 Richard W.M. Jones + * Copyright (C) 2019 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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 + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + *) + +open Printf + +let usage = + "\ +goals: Build software. + + goals [-f Goalfile] ['var = value' ...] [target ...] + +For detailed help see goals(1). + +Options:" + +let main () = + (* Command line arguments. *) + let filename = ref "Goalfile" in + + let argspec = [ + "-f", Arg.Set_string filename, + "filename Set name of Goalfile"; + "--file", Arg.Set_string filename, + "filename Set name of Goalfile"; + ] in + let argspec = Arg.align argspec in + let args = ref [] in + let anon_fun s = args := s :: !args in + Arg.parse argspec anon_fun usage; + + (*let args = List.rev !args in*) + let filename = !filename in + + (* Parse the input file. *) + let file = Parse.parse_from_file filename in + + Ast.print_file stdout file + +let () = main () diff --git a/parsing/main.ml b/src/parse.ml similarity index 95% rename from parsing/main.ml rename to src/parse.ml index 7253954..6b7c03d 100644 --- a/parsing/main.ml +++ b/src/parse.ml @@ -38,12 +38,10 @@ let parse lexbuf = eprintf "%a: parse error\n" print_position lexbuf; exit 1 -let () = - let filename = "Goalfile" in +let parse_from_file filename = let fp = open_in filename in let lexbuf = Lexing.from_channel fp in lexbuf.lex_curr_p <- { lexbuf.lex_curr_p with pos_fname = filename }; let file : Ast.file = parse lexbuf in close_in fp; - - Ast.print_file stdout file + file diff --git a/src/parse.mli b/src/parse.mli new file mode 100644 index 0000000..692524c --- /dev/null +++ b/src/parse.mli @@ -0,0 +1,21 @@ +(* Goalfile parser + * Copyright (C) 2019 Richard W.M. Jones + * Copyright (C) 2019 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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 + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + *) + +val parse : Lexing.lexbuf -> Ast.file +val parse_from_file : string -> Ast.file diff --git a/parsing/parser.mly b/src/parser.mly similarity index 100% rename from parsing/parser.mly rename to src/parser.mly -- 1.8.3.1