Removed python stuff from mooscript
parent
62e3c8a52f
commit
7ef4163a6d
|
@ -5,6 +5,10 @@ mooscript_yacc: $(srcdir)/mooscript.y
|
|||
touch mooscript_yacc
|
||||
bison -o $(srcdir)/mooscript-yacc.c -d $(srcdir)/mooscript.y
|
||||
|
||||
mooscript.o: mooscript_yacc
|
||||
echo stamp > mooscript.o
|
||||
CLEANFILES = mooscript.o
|
||||
|
||||
mooscript_headers = \
|
||||
mooscript-context.h \
|
||||
mooscript-func.h \
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include "mooscript-context.h"
|
||||
#include "mooscript-parser.h"
|
||||
#include "mooscript-zenity.h"
|
||||
#include "mooutils/moopython.h"
|
||||
#include "mooutils/mooprefs.h"
|
||||
#include <string.h>
|
||||
|
||||
|
@ -97,21 +96,6 @@ int_func (MSValue *arg,
|
|||
}
|
||||
|
||||
|
||||
static MSValue*
|
||||
python_func (MSValue *arg,
|
||||
MSContext *ctx)
|
||||
{
|
||||
char *script;
|
||||
MSValue *ret;
|
||||
|
||||
script = ms_value_print (arg);
|
||||
ret = ms_context_run_python (ctx, script);
|
||||
|
||||
g_free (script);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static MSValue*
|
||||
include_func (MSValue *arg,
|
||||
MSContext *ctx)
|
||||
|
@ -376,7 +360,6 @@ _ms_context_add_builtin (MSContext *ctx)
|
|||
ADD_FUNC (ms_cfunc_new_1, len_func, "Len");
|
||||
|
||||
ADD_FUNC (ms_cfunc_new_var, print_func, "Print");
|
||||
ADD_FUNC (ms_cfunc_new_1, python_func, "Python");
|
||||
ADD_FUNC (ms_cfunc_new_1, include_func, "Include");
|
||||
ADD_FUNC (ms_cfunc_new_0, abort_func, "Abort");
|
||||
|
||||
|
|
|
@ -151,9 +151,6 @@ ms_context_init (MSContext *ctx)
|
|||
ctx->vars = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
|
||||
(GDestroyNotify) ms_variable_unref);
|
||||
|
||||
if (moo_python_running ())
|
||||
ctx->py_dict = moo_py_get_script_dict ("__moo_script__");
|
||||
|
||||
ctx->print_func = default_print_func;
|
||||
|
||||
_ms_context_add_builtin (ctx);
|
||||
|
@ -165,9 +162,6 @@ ms_context_finalize (GObject *object)
|
|||
{
|
||||
MSContext *ctx = MS_CONTEXT (object);
|
||||
|
||||
if (moo_python_running ())
|
||||
moo_Py_DECREF (ctx->py_dict);
|
||||
|
||||
g_hash_table_destroy (ctx->vars);
|
||||
g_free (ctx->error_msg);
|
||||
|
||||
|
@ -616,72 +610,3 @@ ms_context_get_env_variable (MSContext *ctx,
|
|||
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* Python
|
||||
*/
|
||||
|
||||
void
|
||||
ms_context_assign_py_var (MSContext *ctx,
|
||||
const char *var,
|
||||
MooPyObject *obj)
|
||||
{
|
||||
g_return_if_fail (MS_IS_CONTEXT (ctx));
|
||||
g_return_if_fail (var != NULL);
|
||||
g_return_if_fail (obj != NULL);
|
||||
g_return_if_fail (moo_python_running ());
|
||||
|
||||
if (!ctx->py_dict)
|
||||
ctx->py_dict = moo_py_get_script_dict ("__moo_script__");
|
||||
|
||||
moo_py_dict_set_item (ctx->py_dict, var, obj);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ms_context_assign_py_object (MSContext *ctx,
|
||||
const char *var,
|
||||
gpointer gobj)
|
||||
{
|
||||
MooPyObject *pyobj;
|
||||
|
||||
g_return_if_fail (moo_python_running ());
|
||||
g_return_if_fail (MS_IS_CONTEXT (ctx));
|
||||
g_return_if_fail (var != NULL);
|
||||
g_return_if_fail (!gobj || G_IS_OBJECT (gobj));
|
||||
|
||||
pyobj = moo_py_object_from_gobject (gobj);
|
||||
g_return_if_fail (pyobj != NULL);
|
||||
ms_context_assign_py_var (ctx, var, pyobj);
|
||||
moo_Py_DECREF (pyobj);
|
||||
}
|
||||
|
||||
|
||||
MSValue *
|
||||
ms_context_run_python (MSContext *ctx,
|
||||
const char *script)
|
||||
{
|
||||
MooPyObject *py_ret;
|
||||
|
||||
g_return_val_if_fail (MS_IS_CONTEXT (ctx), NULL);
|
||||
g_return_val_if_fail (script != NULL, NULL);
|
||||
|
||||
if (!moo_python_running())
|
||||
return ms_context_format_error (ctx, MS_ERROR_RUNTIME,
|
||||
"Python support not available");
|
||||
|
||||
py_ret = moo_python_run_string (script, ctx->py_dict, ctx->py_dict);
|
||||
|
||||
if (py_ret)
|
||||
{
|
||||
moo_Py_DECREF (py_ret);
|
||||
return ms_value_none ();
|
||||
}
|
||||
else
|
||||
{
|
||||
moo_PyErr_Print ();
|
||||
return ms_context_format_error (ctx, MS_ERROR_RUNTIME,
|
||||
"python script raised exception");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#define __MOO_SCRIPT_CONTEXT_H__
|
||||
|
||||
#include <mooscript/mooscript-func.h>
|
||||
#include <mooutils/moopython.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
@ -51,7 +50,6 @@ typedef void (*MSPrintFunc) (const char *string,
|
|||
struct _MSContext {
|
||||
GObject object;
|
||||
|
||||
MooPyObject *py_dict;
|
||||
GHashTable *vars;
|
||||
MSError error;
|
||||
char *error_msg;
|
||||
|
@ -134,16 +132,6 @@ void ms_context_unset_break (MSContext *ctx);
|
|||
void ms_context_unset_continue (MSContext *ctx);
|
||||
|
||||
|
||||
MSValue *ms_context_run_python (MSContext *ctx,
|
||||
const char *script);
|
||||
void ms_context_assign_py_var (MSContext *ctx,
|
||||
const char *var,
|
||||
MooPyObject *obj);
|
||||
void ms_context_assign_py_object (MSContext *ctx,
|
||||
const char *var,
|
||||
gpointer gobj);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __MOO_SCRIPT_CONTEXT_H__ */
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include "mooscript-node.h"
|
||||
#include "mooscript-func.h"
|
||||
#include "mooscript-context.h"
|
||||
#include "mooutils/moopython.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
@ -1076,43 +1075,6 @@ ms_node_val_range_new (MSNode *first,
|
|||
}
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/* MSNodePython
|
||||
*/
|
||||
|
||||
static void
|
||||
ms_node_python_destroy (MSNode *node)
|
||||
{
|
||||
g_free (MS_NODE_PYTHON(node)->script);
|
||||
}
|
||||
|
||||
|
||||
static MSValue *
|
||||
ms_node_python_eval (MSNode *node_,
|
||||
MSContext *ctx)
|
||||
{
|
||||
return ms_context_run_python (ctx, MS_NODE_PYTHON(node_)->script);
|
||||
}
|
||||
|
||||
|
||||
MSNodePython *
|
||||
ms_node_python_new (const char *script)
|
||||
{
|
||||
MSNodePython *node;
|
||||
|
||||
g_return_val_if_fail (script != NULL, NULL);
|
||||
|
||||
node = NODE_NEW (MSNodePython,
|
||||
MS_TYPE_NODE_PYTHON,
|
||||
ms_node_python_eval,
|
||||
ms_node_python_destroy);
|
||||
|
||||
node->script = g_strdup (script);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/* MSNodeGetItem
|
||||
*/
|
||||
|
|
|
@ -31,7 +31,6 @@ typedef enum {
|
|||
MS_TYPE_NODE_ASSIGN,
|
||||
MS_TYPE_NODE_VALUE,
|
||||
MS_TYPE_NODE_VAL_LIST,
|
||||
MS_TYPE_NODE_PYTHON,
|
||||
MS_TYPE_NODE_RETURN,
|
||||
MS_TYPE_NODE_BREAK,
|
||||
MS_TYPE_NODE_DICT_ELM,
|
||||
|
@ -55,7 +54,6 @@ typedef struct _MSNodeAssign MSNodeAssign;
|
|||
typedef struct _MSNodeValue MSNodeValue;
|
||||
typedef struct _MSNodeEnvVar MSNodeEnvVar;
|
||||
typedef struct _MSNodeValList MSNodeValList;
|
||||
typedef struct _MSNodePython MSNodePython;
|
||||
typedef struct _MSNodeBreak MSNodeBreak;
|
||||
typedef struct _MSNodeReturn MSNodeReturn;
|
||||
typedef struct _MSNodeDict MSNodeDict;
|
||||
|
@ -119,7 +117,6 @@ _ms_node_check_type (gpointer pnode,
|
|||
#define MS_NODE_VALUE(node_) MS_NODE_CAST (node_, MS_TYPE_NODE_VALUE, MSNodeValue)
|
||||
#define MS_NODE_ENV_VAR(node_) MS_NODE_CAST (node_, MS_TYPE_NODE_ENV_VAR, MSNodeEnvVar)
|
||||
#define MS_NODE_VAL_LIST(node_) MS_NODE_CAST (node_, MS_TYPE_NODE_VAL_LIST, MSNodeValList)
|
||||
#define MS_NODE_PYTHON(node_) MS_NODE_CAST (node_, MS_TYPE_NODE_PYTHON, MSNodePython)
|
||||
#define MS_NODE_BREAK(node_) MS_NODE_CAST (node_, MS_TYPE_NODE_BREAK, MSNodeBreak)
|
||||
#define MS_NODE_RETURN(node_) MS_NODE_CAST (node_, MS_TYPE_NODE_RETURN, MSNodeReturn)
|
||||
#define MS_NODE_DICT(node_) MS_NODE_CAST (node_, MS_TYPE_NODE_DICT, MSNodeDict)
|
||||
|
@ -219,12 +216,6 @@ struct _MSNodeEnvVar {
|
|||
};
|
||||
|
||||
|
||||
struct _MSNodePython {
|
||||
MSNode node;
|
||||
char *script;
|
||||
};
|
||||
|
||||
|
||||
typedef enum {
|
||||
MS_VAL_LIST,
|
||||
MS_VAL_RANGE
|
||||
|
@ -325,8 +316,6 @@ MSNodeEnvVar *ms_node_env_var_new (MSNode *name,
|
|||
MSNode *dflt);
|
||||
MSNodeVar *ms_node_var_new (const char *name);
|
||||
|
||||
MSNodePython *ms_node_python_new (const char *script);
|
||||
|
||||
MSNodeGetItem *ms_node_get_item_new (MSNode *obj,
|
||||
MSNode *key);
|
||||
MSNodeSetItem *ms_node_set_item_new (MSNode *obj,
|
||||
|
|
|
@ -253,42 +253,6 @@ ms_lex_parse_word (MSLex *lex,
|
|||
}
|
||||
|
||||
|
||||
static int
|
||||
ms_lex_parse_python (MSLex *lex)
|
||||
{
|
||||
guint ptr = lex->ptr;
|
||||
const char *input = (const char *) lex->input;
|
||||
|
||||
g_assert (input[ptr] == input[ptr+1] &&
|
||||
input[ptr+1] == input[ptr+2] &&
|
||||
input[ptr] == '=');
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
while (ptr < lex->len && !IS_EOL(input[ptr]))
|
||||
ptr++;
|
||||
|
||||
if (ptr == lex->len)
|
||||
{
|
||||
_ms_script_yylval.str = ms_lex_add_string (lex, input + lex->ptr + 3, -1);
|
||||
lex->ptr = lex->len;
|
||||
return PYTHON;
|
||||
}
|
||||
|
||||
while (IS_EOL (input[ptr]))
|
||||
ptr++;
|
||||
|
||||
if (input[ptr] == '=' && input[ptr+1] == '=' && input[ptr+2] == '=')
|
||||
{
|
||||
_ms_script_yylval.str = ms_lex_add_string (lex, input + lex->ptr + 3,
|
||||
ptr - lex->ptr - 3);
|
||||
lex->ptr = ptr + 3;
|
||||
return PYTHON;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define THIS (lex->input[lex->ptr])
|
||||
#define NEXT (lex->input[lex->ptr+1])
|
||||
#define NEXT2 (lex->input[lex->ptr+2])
|
||||
|
@ -356,9 +320,6 @@ _ms_script_yylex (MSParser *parser)
|
|||
return ms_lex_error (parser);
|
||||
}
|
||||
|
||||
if (c == '=' && NEXT == '=' && NEXT2 == '=')
|
||||
return ms_lex_parse_python (lex);
|
||||
|
||||
if (c == '#')
|
||||
{
|
||||
while (lex->ptr < lex->len && !IS_EOL(lex->input[lex->ptr]))
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,7 +1,9 @@
|
|||
/* A Bison parser, made by GNU Bison 2.1. */
|
||||
/* A Bison parser, made by GNU Bison 2.3. */
|
||||
|
||||
/* Skeleton parser for Yacc-like parsing with Bison,
|
||||
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
|
||||
/* Skeleton interface for Bison's Yacc-like parsers in C
|
||||
|
||||
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
|
||||
Free Software Foundation, 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
|
||||
|
@ -18,10 +20,18 @@
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA. */
|
||||
|
||||
/* As a special exception, when this file is copied by Bison into a
|
||||
Bison output file, you may use that output file without restriction.
|
||||
This special exception was added by the Free Software Foundation
|
||||
in version 1.24 of Bison. */
|
||||
/* As a special exception, you may create a larger work that contains
|
||||
part or all of the Bison parser skeleton and distribute that work
|
||||
under terms of your choice, so long as that work isn't itself a
|
||||
parser generator using the skeleton or a modified version thereof
|
||||
as a parser skeleton. Alternatively, if you modify or redistribute
|
||||
the parser skeleton itself, you may (at your option) remove this
|
||||
special exception, which will cause the skeleton and the resulting
|
||||
Bison output files to be licensed under the GNU General Public
|
||||
License without this special exception.
|
||||
|
||||
This special exception was added by the Free Software Foundation in
|
||||
version 2.2 of Bison. */
|
||||
|
||||
/* Tokens. */
|
||||
#ifndef YYTOKENTYPE
|
||||
|
@ -32,73 +42,73 @@
|
|||
IDENTIFIER = 258,
|
||||
LITERAL = 259,
|
||||
VARIABLE = 260,
|
||||
PYTHON = 261,
|
||||
NUMBER = 262,
|
||||
IF = 263,
|
||||
THEN = 264,
|
||||
ELSE = 265,
|
||||
ELIF = 266,
|
||||
FI = 267,
|
||||
WHILE = 268,
|
||||
DO = 269,
|
||||
OD = 270,
|
||||
FOR = 271,
|
||||
IN = 272,
|
||||
CONTINUE = 273,
|
||||
BREAK = 274,
|
||||
RETURN = 275,
|
||||
EQ = 276,
|
||||
NEQ = 277,
|
||||
LE = 278,
|
||||
GE = 279,
|
||||
AND = 280,
|
||||
OR = 281,
|
||||
NOT = 282,
|
||||
UMINUS = 283,
|
||||
TWODOTS = 284
|
||||
NUMBER = 261,
|
||||
IF = 262,
|
||||
THEN = 263,
|
||||
ELSE = 264,
|
||||
ELIF = 265,
|
||||
FI = 266,
|
||||
WHILE = 267,
|
||||
DO = 268,
|
||||
OD = 269,
|
||||
FOR = 270,
|
||||
IN = 271,
|
||||
CONTINUE = 272,
|
||||
BREAK = 273,
|
||||
RETURN = 274,
|
||||
EQ = 275,
|
||||
NEQ = 276,
|
||||
LE = 277,
|
||||
GE = 278,
|
||||
AND = 279,
|
||||
OR = 280,
|
||||
NOT = 281,
|
||||
UMINUS = 282,
|
||||
TWODOTS = 283
|
||||
};
|
||||
#endif
|
||||
/* Tokens. */
|
||||
#define IDENTIFIER 258
|
||||
#define LITERAL 259
|
||||
#define VARIABLE 260
|
||||
#define PYTHON 261
|
||||
#define NUMBER 262
|
||||
#define IF 263
|
||||
#define THEN 264
|
||||
#define ELSE 265
|
||||
#define ELIF 266
|
||||
#define FI 267
|
||||
#define WHILE 268
|
||||
#define DO 269
|
||||
#define OD 270
|
||||
#define FOR 271
|
||||
#define IN 272
|
||||
#define CONTINUE 273
|
||||
#define BREAK 274
|
||||
#define RETURN 275
|
||||
#define EQ 276
|
||||
#define NEQ 277
|
||||
#define LE 278
|
||||
#define GE 279
|
||||
#define AND 280
|
||||
#define OR 281
|
||||
#define NOT 282
|
||||
#define UMINUS 283
|
||||
#define TWODOTS 284
|
||||
#define NUMBER 261
|
||||
#define IF 262
|
||||
#define THEN 263
|
||||
#define ELSE 264
|
||||
#define ELIF 265
|
||||
#define FI 266
|
||||
#define WHILE 267
|
||||
#define DO 268
|
||||
#define OD 269
|
||||
#define FOR 270
|
||||
#define IN 271
|
||||
#define CONTINUE 272
|
||||
#define BREAK 273
|
||||
#define RETURN 274
|
||||
#define EQ 275
|
||||
#define NEQ 276
|
||||
#define LE 277
|
||||
#define GE 278
|
||||
#define AND 279
|
||||
#define OR 280
|
||||
#define NOT 281
|
||||
#define UMINUS 282
|
||||
#define TWODOTS 283
|
||||
|
||||
|
||||
|
||||
|
||||
#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
|
||||
#line 390 "/home/muntyan/projects/moo/moo/mooutils/mooscript/mooscript.y"
|
||||
typedef union YYSTYPE {
|
||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
typedef union YYSTYPE
|
||||
#line 377 "/home/muntyan/projects/moo/moo/mooscript/mooscript.y"
|
||||
{
|
||||
int ival;
|
||||
const char *str;
|
||||
MSNode *node;
|
||||
} YYSTYPE;
|
||||
/* Line 1447 of yacc.c. */
|
||||
#line 102 "/home/muntyan/projects/moo/moo/mooutils/mooscript/mooscript-yacc.h"
|
||||
}
|
||||
/* Line 1529 of yacc.c. */
|
||||
#line 111 "/home/muntyan/projects/moo/moo/mooscript/mooscript-yacc.h"
|
||||
YYSTYPE;
|
||||
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
|
||||
# define YYSTYPE_IS_DECLARED 1
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
|
@ -106,5 +116,3 @@ typedef union YYSTYPE {
|
|||
|
||||
extern YYSTYPE _ms_script_yylval;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -204,19 +204,6 @@ node_string (MSParser *parser,
|
|||
}
|
||||
|
||||
|
||||
static MSNode *
|
||||
node_python (MSParser *parser,
|
||||
const char *string)
|
||||
{
|
||||
MSNodePython *node;
|
||||
|
||||
node = ms_node_python_new (string);
|
||||
_ms_parser_add_node (parser, node);
|
||||
|
||||
return MS_NODE (node);
|
||||
}
|
||||
|
||||
|
||||
static MSNode *
|
||||
node_value_list (MSParser *parser,
|
||||
MSNodeList *list)
|
||||
|
@ -396,10 +383,9 @@ node_dict_assign (MSParser *parser,
|
|||
%token <str> IDENTIFIER
|
||||
%token <str> LITERAL
|
||||
%token <str> VARIABLE
|
||||
%token <str> PYTHON
|
||||
%token <ival> NUMBER
|
||||
|
||||
%type <node> program stmt stmt_or_python
|
||||
%type <node> program stmt stmt_or_error
|
||||
%type <node> if_stmt elif_block ternary loop assignment
|
||||
%type <node> simple_expr compound_expr expr variable
|
||||
%type <node> list_elms dict_elms dict_entry
|
||||
|
@ -427,14 +413,13 @@ node_dict_assign (MSParser *parser,
|
|||
script: program { _ms_parser_set_top_node (parser, $1); }
|
||||
;
|
||||
|
||||
program: stmt_or_python { $$ = node_list_add (parser, NULL, $1); }
|
||||
| program stmt_or_python { $$ = node_list_add (parser, MS_NODE_LIST ($1), $2); }
|
||||
program: stmt_or_error { $$ = node_list_add (parser, NULL, $1); }
|
||||
| program stmt_or_error { $$ = node_list_add (parser, MS_NODE_LIST ($1), $2); }
|
||||
;
|
||||
|
||||
stmt_or_python:
|
||||
stmt_or_error:
|
||||
error ';' { $$ = NULL; }
|
||||
| stmt ';' { $$ = $1; }
|
||||
| PYTHON { $$ = node_python (parser, $1); }
|
||||
;
|
||||
|
||||
stmt: /* empty */ { $$ = NULL; }
|
||||
|
|
Loading…
Reference in New Issue