Parse two-chars tokens (like <= or &&) as well
parent
f733f66f54
commit
6be94c2218
|
@ -268,16 +268,16 @@
|
|||
</kdevdoctreeview>
|
||||
<kdevfilecreate>
|
||||
<filetypes>
|
||||
<type icon="source" ext="g" name="GAP source" create="template" >
|
||||
<type icon="source" ext="g" create="template" name="GAP source" >
|
||||
<descr>A new empty GAP source file</descr>
|
||||
</type>
|
||||
<type icon="source_cpp" ext="cpp" name="C++ Source" create="template" >
|
||||
<type icon="source_cpp" ext="cpp" create="template" name="C++ Source" >
|
||||
<descr>A new empty C++ file.</descr>
|
||||
</type>
|
||||
<type icon="source_h" ext="h" name="C/C++ Header" create="template" >
|
||||
<type icon="source_h" ext="h" create="template" name="C/C++ Header" >
|
||||
<descr>A new empty header file for C/C++.</descr>
|
||||
</type>
|
||||
<type icon="source_c" ext="c" name="C Source" create="template" >
|
||||
<type icon="source_c" ext="c" create="template" name="C Source" >
|
||||
<descr>A new empty C file.</descr>
|
||||
</type>
|
||||
</filetypes>
|
||||
|
|
|
@ -241,21 +241,32 @@ ms_lex_parse_word (MSLex *lex,
|
|||
}
|
||||
|
||||
|
||||
static int
|
||||
ms_lex_parse_dot (MSLex *lex,
|
||||
G_GNUC_UNUSED MSParser *parser)
|
||||
{
|
||||
g_assert (lex->input[lex->ptr] == '.');
|
||||
#define THIS (lex->input[lex->ptr])
|
||||
#define NEXT (lex->input[lex->ptr+1])
|
||||
|
||||
if (lex->input[lex->ptr+1] == '.')
|
||||
{
|
||||
lex->ptr += 2;
|
||||
return TWODOTS;
|
||||
}
|
||||
#define RETURN1(what) \
|
||||
G_STMT_START { \
|
||||
lex->ptr += 1; \
|
||||
return what; \
|
||||
} G_STMT_END
|
||||
|
||||
lex->ptr++;
|
||||
return '.';
|
||||
}
|
||||
#define CHECK1(c_, what_) \
|
||||
G_STMT_START { \
|
||||
if (THIS == c_) \
|
||||
RETURN2 (what_); \
|
||||
} G_STMT_END
|
||||
|
||||
#define RETURN2(what) \
|
||||
G_STMT_START { \
|
||||
lex->ptr += 2; \
|
||||
return what; \
|
||||
} G_STMT_END
|
||||
|
||||
#define CHECK2(c1_, c2_, what_) \
|
||||
G_STMT_START { \
|
||||
if (THIS == c1_ && NEXT == c2_) \
|
||||
RETURN2 (what_); \
|
||||
} G_STMT_END
|
||||
|
||||
|
||||
int
|
||||
|
@ -287,8 +298,15 @@ _ms_script_yylex (MSParser *parser)
|
|||
if (IS_LETTER (c) || c == '_')
|
||||
return ms_lex_parse_word (lex, parser);
|
||||
|
||||
if (c == '.')
|
||||
return ms_lex_parse_dot (lex, parser);
|
||||
CHECK2 ('.', '.', TWODOTS);
|
||||
CHECK2 ('=', '=', EQ);
|
||||
CHECK2 ('!', '=', NEQ);
|
||||
CHECK2 ('&', '&', AND);
|
||||
CHECK2 ('|', '|', OR);
|
||||
CHECK2 ('<', '=', LE);
|
||||
CHECK2 ('>', '=', GE);
|
||||
|
||||
CHECK1 ('!', NOT);
|
||||
|
||||
lex->ptr++;
|
||||
return c;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
EXTRA_PROGRAMS += medit mterm markup termbuffer testfileview testpaned testpanedfileview miniglade langparser testobject testfold
|
||||
EXTRA_PROGRAMS += medit mterm markup termbuffer testfileview testpaned testpanedfileview miniglade langparser testobject testfold script
|
||||
bin_PROGRAMS =
|
||||
|
||||
|
||||
|
@ -98,6 +98,18 @@ nodist_langparser_SOURCES = $(nodist_libmoo_sources)
|
|||
endif
|
||||
|
||||
|
||||
##############################################################################
|
||||
## script
|
||||
##
|
||||
script_LDFLAGS = $(ldflags)
|
||||
script_LDADD = $(ldadd)
|
||||
script_SOURCES = tests/script.c
|
||||
if !MOO_BUILD_LIB
|
||||
script_SOURCES += $(libmoo_sources)
|
||||
nodist_script_SOURCES = $(nodist_libmoo_sources)
|
||||
endif
|
||||
|
||||
|
||||
##############################################################################
|
||||
## mterm
|
||||
##
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* script.c
|
||||
*
|
||||
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* See COPYING file that comes with this distribution.
|
||||
*/
|
||||
|
||||
#define MOOEDIT_COMPILATION
|
||||
#include "mooutils/mooscript/mooscript-parser.h"
|
||||
#include <gtk/gtk.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
static void usage (const char *prg)
|
||||
{
|
||||
g_error ("usage:\t%s -f <file>\n\t%s <script>", prg, prg);
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
char *script;
|
||||
MSNode *node;
|
||||
MSValue *val;
|
||||
MSContext *ctx;
|
||||
|
||||
gtk_init (&argc, &argv);
|
||||
|
||||
if (argc < 2)
|
||||
usage (argv[0]);
|
||||
|
||||
if (argc == 2)
|
||||
{
|
||||
script = argv[1];
|
||||
}
|
||||
else if (strcmp (argv[1], "-f"))
|
||||
{
|
||||
usage (argv[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
GError *error = NULL;
|
||||
if (!g_file_get_contents (argv[2], &script, NULL, &error))
|
||||
g_error ("%s", error->message);
|
||||
}
|
||||
|
||||
node = ms_script_parse (script);
|
||||
|
||||
if (!node)
|
||||
g_error ("could not parse script");
|
||||
|
||||
ctx = ms_context_new ();
|
||||
val = ms_node_eval (node, ctx);
|
||||
|
||||
if (!val)
|
||||
g_print ("error: %s\n", ms_context_get_error_msg (ctx));
|
||||
else
|
||||
g_print ("success: %s\n", ms_value_print (val));
|
||||
}
|
Loading…
Reference in New Issue