Home modules.gotpike.org
Username: Password: [Create Account]
[Forgot Password?]

Modules

ADT
Database
GTK2
GUI
IP
PiJAX
Public
Sql
Stdio
Subversion
System
Tools
Xosd
lua
v4l2
wx

Recent Changes

Public.Parser.XML2 1.50
Public.ZeroMQ 1.1
Public.Template.Mustache 1.0
Public.Protocols.XMPP 1.4
Sql.Provider.jdbc 1.0

Popular Downloads

Public.Parser.JSON2 1.0
Public.Parser.JSON 0.2
GTK2 2.23
Public.Web.FCGI 1.8
Public.Parser.XML2 1.48


Module Information
Public.Parser.JSON2
Viewing contents of Public_Parser_JSON2-0.1/json.cmod

#line 1 "json.rl"
// vim:syntax=ragel
/* 
 * Pike CMOD parser for JSON.
 * Copyright (C) 2007 Arne Goedeke
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 * 
 * This library 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
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#include 
#include "global.h"
#include "interpret.h"
#include "stralloc.h"
#include "mapping.h"
#include "svalue.h"
#include "array.h"
#include "builtin_functions.h"
#include "module.h"

p_wchar2 *_parse_JSON(p_wchar2* p, p_wchar2* pe); 
p_wchar2 *_parse_JSON_mapping(p_wchar2* p, p_wchar2* pe); 
p_wchar2 *_parse_JSON_array(p_wchar2* p, p_wchar2* pe); 
p_wchar2 *_parse_JSON_number(p_wchar2* p, p_wchar2* pe); 
p_wchar2 *_parse_JSON_string(p_wchar2* p, p_wchar2* pe); 

#include "json_string.c"
#include "json_number.c"
#include "json_array.c"
#include "json_mapping.c"


#line 45 "json.cmod/json.cmod"
static const int JSON_start = 1;

static const int JSON_first_final = 12;

static const int JSON_error = 0;

#line 81 "json.rl"


p_wchar2 *_parse_JSON(p_wchar2 *p, p_wchar2 *pe) {
    p_wchar2 *i = p;
    int cs;

    
#line 60 "json.cmod/json.cmod"
	{
	cs = JSON_start;
	}
#line 88 "json.rl"
    
#line 66 "json.cmod/json.cmod"
	{
	if ( p == pe )
		goto _out;
	switch ( cs )
	{
st1:
	if ( ++p == pe )
		goto _out1;
case 1:
	switch( (*p) ) {
		case 13: goto st1;
		case 32: goto st1;
		case 34: goto tr2;
		case 43: goto tr3;
		case 91: goto tr4;
		case 102: goto st2;
		case 110: goto st6;
		case 116: goto st9;
		case 123: goto tr8;
	}
	if ( (*p) < 45 ) {
		if ( 9 <= (*p) && (*p) <= 10 )
			goto st1;
	} else if ( (*p) > 46 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto tr3;
	} else
		goto tr3;
	goto st0;
st0:
	goto _out0;
tr2:
#line 47 "json.rl"
	{
	i = _parse_JSON_string(p, pe);
	{p = (( i))-1;}
    }
	goto st12;
tr3:
#line 62 "json.rl"
	{
	i = _parse_JSON_number(p, pe);
	{p = (( i))-1;}
    }
	goto st12;
tr4:
#line 57 "json.rl"
	{
	i = _parse_JSON_array(p, pe);
	{p = (( i))-1;}
    }
	goto st12;
tr8:
#line 52 "json.rl"
	{
	i = _parse_JSON_mapping(p, pe);
	{p = (( i))-1;}
    }
	goto st12;
tr12:
#line 79 "json.rl"
	{ push_undefined(); }
	goto st12;
tr15:
#line 80 "json.rl"
	{ push_int(0); }
	goto st12;
tr18:
#line 78 "json.rl"
	{ push_int(1); }
	goto st12;
st12:
	if ( ++p == pe )
		goto _out12;
case 12:
#line 80 "json.rl"
	{ goto _out12; }
#line 144 "json.cmod/json.cmod"
	switch( (*p) ) {
		case 13: goto st12;
		case 32: goto st12;
	}
	if ( 9 <= (*p) && (*p) <= 10 )
		goto st12;
	goto st0;
st2:
	if ( ++p == pe )
		goto _out2;
case 2:
	if ( (*p) == 97 )
		goto st3;
	goto st0;
st3:
	if ( ++p == pe )
		goto _out3;
case 3:
	if ( (*p) == 108 )
		goto st4;
	goto st0;
st4:
	if ( ++p == pe )
		goto _out4;
case 4:
	if ( (*p) == 115 )
		goto st5;
	goto st0;
st5:
	if ( ++p == pe )
		goto _out5;
case 5:
	if ( (*p) == 101 )
		goto tr12;
	goto st0;
st6:
	if ( ++p == pe )
		goto _out6;
case 6:
	if ( (*p) == 117 )
		goto st7;
	goto st0;
st7:
	if ( ++p == pe )
		goto _out7;
case 7:
	if ( (*p) == 108 )
		goto st8;
	goto st0;
st8:
	if ( ++p == pe )
		goto _out8;
case 8:
	if ( (*p) == 108 )
		goto tr15;
	goto st0;
st9:
	if ( ++p == pe )
		goto _out9;
case 9:
	if ( (*p) == 114 )
		goto st10;
	goto st0;
st10:
	if ( ++p == pe )
		goto _out10;
case 10:
	if ( (*p) == 117 )
		goto st11;
	goto st0;
st11:
	if ( ++p == pe )
		goto _out11;
case 11:
	if ( (*p) == 101 )
		goto tr18;
	goto st0;
	}
	_out1: cs = 1; goto _out; 
	_out0: cs = 0; goto _out; 
	_out12: cs = 12; goto _out; 
	_out2: cs = 2; goto _out; 
	_out3: cs = 3; goto _out; 
	_out4: cs = 4; goto _out; 
	_out5: cs = 5; goto _out; 
	_out6: cs = 6; goto _out; 
	_out7: cs = 7; goto _out; 
	_out8: cs = 8; goto _out; 
	_out9: cs = 9; goto _out; 
	_out10: cs = 10; goto _out; 
	_out11: cs = 11; goto _out; 

	_out: {}
	}
#line 89 "json.rl"

    if (cs >= JSON_first_final) {
	return p;
    }
    Pike_error("Error parsing JSON at '%c'\n", (char)*p);
    return NULL;
}

/*! @module Public
 */

/*! @module Parser
 */

/*! @module JSON2
 *! This module contains a parser to parse JSON into native pike types. The parser has been written
 *! in c using ragel (@[http://www.cs.queensu.ca/~thurston/ragel/]).
 *! The parser is supposed to handle Unicode strings (internally 8, 16 and 32 bit wide strings that is).
 *! 
 *! Have a look at @[http://www.json.org] or @[http://www.ietf.org/rfc/rfc4627.txt?number=4627] for
 *! information about what JSON is.
 */

/*! @decl array|mapping|string|float|int parse(string s)
 *!
 *! Parses a JSON-formatted string and returns the corresponding pike data type.
 *! 
 *! @throws
 *! 	Throws an exception in case the data contained in @expr{s@} is not valid
 *! 	JSON.
 */
PIKEFUN mixed parse(string data) {
    struct pike_string *b;
    p_wchar2 *ret;
    // we wont be building more than one string at once.

    switch (data->size_shift != 0) {
    case 0:
	b=begin_wide_shared_string(data->len,2);
        convert_0_to_2(STR2(b),(p_wchar0 *)data->str,data->len);
	free_string(data);
	end_shared_string(b);
	break;
    case 1:
	b=begin_wide_shared_string(data->len,2);
        convert_1_to_2(STR2(b),STR1(data),data->len);
	free_string(data);
	end_shared_string(b);
	break;
    case 2:
	b = data;
	break;
    }

    pop_stack();
    ret = STR2(b);
    ret = _parse_JSON(ret, ret + b->len);
    return;
}

/*! @endmodule
 */
/*! @endmodule
 */
/*! @endmodule
 */


gotpike.org | Copyright © 2004 - 2019 | Pike is a trademark of Department of Computer and Information Science, Linköping University