mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
gr: Added utility to check grammar
This commit is contained in:
parent
75ca4a3b71
commit
fbc47dc1e4
4 changed files with 111 additions and 1 deletions
|
@ -119,5 +119,5 @@ set (CPACK_SOURCE_IGNORE_FILES "CMakeCache" "CMakeFiles" "CPackConfig" "CPackSo
|
|||
"_CPack_Packages" "cmake_install" "install_manifest" "Makefile$"
|
||||
"test" "package-config" "misc/*" "src/timew$" "src/common/libcommon.a"
|
||||
"performance" "src/libtimew.a" "/\\\\.gitignore" "/\\\\.git/" "swp$"
|
||||
"src/lex$")
|
||||
"src/gr$")
|
||||
include (CPack)
|
||||
|
|
1
src/.gitignore
vendored
1
src/.gitignore
vendored
|
@ -1,4 +1,5 @@
|
|||
timew
|
||||
gr
|
||||
libtimew.a
|
||||
CMakeFiles
|
||||
Makefile
|
||||
|
|
|
@ -10,10 +10,13 @@ set (timew_SRCS Grammar.cpp Grammar.h
|
|||
|
||||
add_library (timew STATIC ${timew_SRCS})
|
||||
add_executable (timew_executable timew.cpp)
|
||||
add_executable (gr_executable gr.cpp)
|
||||
|
||||
target_link_libraries (timew_executable common timew ${TIMEW_LIBRARIES})
|
||||
target_link_libraries (gr_executable common timew ${TIMEW_LIBRARIES})
|
||||
|
||||
set_property (TARGET timew_executable PROPERTY OUTPUT_NAME "timew")
|
||||
set_property (TARGET gr_executable PROPERTY OUTPUT_NAME "gr")
|
||||
|
||||
install (TARGETS timew_executable DESTINATION ${TIMEW_BINDIR})
|
||||
|
||||
|
|
106
src/gr.cpp
Normal file
106
src/gr.cpp
Normal file
|
@ -0,0 +1,106 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2015, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// http://www.opensource.org/licenses/mit-license.php
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <cmake.h>
|
||||
#include <FS.h>
|
||||
#include <Grammar.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void usage ()
|
||||
{
|
||||
std::cout << "\n"
|
||||
<< "Usage: gr [options] <grammar> [<args>]\n"
|
||||
<< "\n"
|
||||
<< "Options are:\n"
|
||||
<< " -h/--help Command usage\n"
|
||||
<< "\n";
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
// Process command line arguments
|
||||
std::string grammarFile = "";
|
||||
std::string commandLine = "";
|
||||
/*
|
||||
std::vector <std::string> args;
|
||||
*/
|
||||
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
if (argv[i][0] == '-')
|
||||
{
|
||||
if (!strcmp (argv[i], "-h")) usage ();
|
||||
else if (!strcmp (argv[i], "--help")) usage ();
|
||||
else
|
||||
{
|
||||
std::cout << "Unrecognized option '" << argv[i] << "'" << std::endl;
|
||||
usage ();
|
||||
}
|
||||
}
|
||||
else if (grammarFile == "")
|
||||
{
|
||||
grammarFile = argv[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (commandLine != "")
|
||||
commandLine += " ";
|
||||
|
||||
commandLine += "'" + std::string (argv[i]) + "'";
|
||||
}
|
||||
}
|
||||
|
||||
// Display usage for incorrect command line.
|
||||
if (grammarFile == "")
|
||||
usage ();
|
||||
|
||||
try
|
||||
{
|
||||
File file (grammarFile);
|
||||
Grammar grammar;
|
||||
grammar.loadFromFile (file);
|
||||
std::cout << grammar.dump ();
|
||||
|
||||
// TODO Test commandLine against grammar.
|
||||
if (commandLine != "")
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
catch (const std::string& error)
|
||||
{
|
||||
std::cout << error << "\n";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
Loading…
Add table
Add a link
Reference in a new issue