Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed May 25, 2023
2 parents b50b0fc + 2a4cb7b commit 8902a7a
Show file tree
Hide file tree
Showing 19 changed files with 118 additions and 113 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Develop

## 1.6.1

- Fix critical issue - missing correct return when waiting for first character. Should be `lwjsonSTREAMWAITFIRSTCHAR`

## 1.6.0

- Split CMakeLists.txt files between library and executable
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Tilen MAJERLE
Copyright (c) 2023 Tilen MAJERLE

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ First one being optimized for ultra small microcontrollers, second one being rea
Fresh contributions are always welcome. Simple instructions to proceed::

1. Fork Github repository
2. Respect [C style & coding rules](https://github.com/MaJerle/c-code-style) used by the library
2. Follow [C style & coding rules](https://github.com/MaJerle/c-code-style) already used in the project
3. Create a pull request to develop branch with new features or bug fixes

Alternatively you may:
Expand Down
4 changes: 2 additions & 2 deletions dev/lwjson_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/*
* Copyright (c) 2022 Tilen MAJERLE
* Copyright (c) 2023 Tilen MAJERLE
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
Expand All @@ -29,7 +29,7 @@
* This file is part of LwJSON - Lightweight JSON format parser.
*
* Author: Tilen MAJERLE <[email protected]>
* Version: v1.6.0
* Version: v1.6.1
*/
#ifndef LWJSON_HDR_OPTS_H
#define LWJSON_HDR_OPTS_H
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# -- Project information -----------------------------------------------------

project = 'LwJSON'
copyright = '2022, Tilen MAJERLE'
copyright = '2023, Tilen MAJERLE'
author = 'Tilen MAJERLE'

# Try to get branch at which this is running
Expand Down
2 changes: 1 addition & 1 deletion docs/get-started/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Next step is to add the library to the project, by means of source files to comp

* Copy ``lwjson`` folder to your project, it contains library files
* Add ``lwjson/src/include`` folder to `include path` of your toolchain. This is where `C/C++` compiler can find the files during compilation process. Usually using ``-I`` flag
* Add source files from ``lwjson/src/`` folder to toolchain build. These files are built by `C/C++` compiler
* Add source files from ``lwjson/src/`` folder to toolchain build. These files are built by `C/C++` compiler. CMake configuration comes with the library, allows users to include library in the project as **subdirectory** and **library**.
* Copy ``lwjson/src/include/lwjson/lwjson_opts_template.h`` to project folder and rename it to ``lwjson_opts.h``
* Build the project

Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,4 @@ Table of contents
LwRB - Ring buffer <https://github.com/MaJerle/lwrb>
LwSHELL - Shell <https://github.com/MaJerle/lwshell>
LwUTIL - Utility functions <https://github.com/MaJerle/lwutil>
LwWDG - RTOS task watchdog <https://github.com/MaJerle/lwwdg>
5 changes: 3 additions & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
sphinx>=3.5.1
breathe>=4.9.1
colorama
urllib3==1.26.15
docutils==0.16
sphinx>=3.5.1
colorama
sphinx_rtd_theme>=1.0.0
sphinx-tabs
sphinxcontrib-svg2pdfconverter
Expand Down
Binary file modified docs/static/images/logo_tm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/static/images/logo_tm_full.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions examples/example_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ example_stream_run(void) {

/* Demonstrate as stream inputs */
for (const char* c = json_str; *c != '\0'; ++c) {
if ((res = lwjson_stream_parse(&stream_parser, *c)) == lwjsonOK) {
printf("OK\r\n");
res = lwjson_stream_parse(&stream_parser, *c);
if (res == lwjsonSTREAMINPROG) {
} else if (res == lwjsonSTREAMWAITFIRSTCHAR) {
printf("Waiting first character\r\n");
} else if (res == lwjsonSTREAMDONE) {
printf("Done\r\n");
} else {
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "LwJSON",
"version": "1.6.0",
"version": "1.6.1",
"description": "Lightweight JSON parser for embedded systems with support for inline comments",
"keywords": "json, javascript, lightweight, parser, stm32, manager, library, comment, object, notation, object notation",
"repository": {
Expand Down
8 changes: 1 addition & 7 deletions lwjson/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
cmake_minimum_required(VERSION 3.22)

#Debug message
message("Entering ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt")

# Setup generic source files
set(lwjson_core_SRCS
${CMAKE_CURRENT_LIST_DIR}/src/lwjson/lwjson.c
Expand All @@ -27,7 +24,4 @@ target_include_directories(lwjson INTERFACE ${lwjson_include_DIRS})
# Register lwjson debug module
add_library(lwjson_debug INTERFACE)
target_sources(lwjson_debug PUBLIC ${lwjson_debug_SRCS})
target_include_directories(lwjson_debug INTERFACE ${lwjson_include_DIRS})

#Debug message
message("Exiting ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt")
target_include_directories(lwjson_debug INTERFACE ${lwjson_include_DIRS})
52 changes: 25 additions & 27 deletions lwjson/src/include/lwjson/lwjson.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/*
* Copyright (c) 2022 Tilen MAJERLE
* Copyright (c) 2023 Tilen MAJERLE
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
Expand All @@ -29,13 +29,13 @@
* This file is part of LwJSON - Lightweight JSON format parser.
*
* Author: Tilen MAJERLE <[email protected]>
* Version: v1.6.0
* Version: v1.6.1
*/
#ifndef LWJSON_HDR_H
#define LWJSON_HDR_H

#include <string.h>
#include <stdint.h>
#include <string.h>
#include "lwjson/lwjson_opt.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -95,8 +95,8 @@ typedef struct lwjson_token {
token_value_len; /*!< Length of token value (this is needed to support const input strings to parse) */
} str; /*!< String data */

lwjson_real_t num_real; /*!< Real number format */
lwjson_int_t num_int; /*!< Int number format */
lwjson_real_t num_real; /*!< Real number format */
lwjson_int_t num_int; /*!< Int number format */
struct lwjson_token* first_child; /*!< First children object for object or array type */
} u; /*!< Union with different data types */
} lwjson_token_t;
Expand All @@ -105,20 +105,18 @@ typedef struct lwjson_token {
* \brief JSON result enumeration
*/
typedef enum {
lwjsonOK = 0x00, /*!< Function returns successfully */
lwjsonERR, /*!< Generic error message */
lwjsonERRJSON, /*!< Error JSON format */
lwjsonERRMEM, /*!< Memory error */
lwjsonERRPAR, /*!< Parameter error */
lwjsonOK = 0x00, /*!< Function returns successfully */
lwjsonERR, /*!< Generic error message */
lwjsonERRJSON, /*!< Error JSON format */
lwjsonERRMEM, /*!< Memory error */
lwjsonERRPAR, /*!< Parameter error */

lwjsonSTREAMWAITFIRSTCHAR, /*!< Streaming parser did not yet receive first valid character
indicating start of JSON sequence */
indicating start of JSON sequence */
lwjsonSTREAMDONE, /*!< Streaming parser is done,
closing character matched the stream opening one */
lwjsonSTREAMINPROG, /*!< Stream parsing is still in progress */
}

lwjsonr_t;
} lwjsonr_t;

/**
* \brief LwJSON instance
Expand All @@ -134,15 +132,15 @@ typedef struct {
} flags; /*!< List of flags */
} lwjson_t;

lwjsonr_t lwjson_init(lwjson_t* lw, lwjson_token_t* tokens, size_t tokens_len);
lwjsonr_t lwjson_parse_ex(lwjson_t* lw, const void* json_data, size_t len);
lwjsonr_t lwjson_parse(lwjson_t* lw, const char* json_str);
const lwjson_token_t* lwjson_find(lwjson_t* lw, const char* path);
const lwjson_token_t* lwjson_find_ex(lwjson_t* lw, const lwjson_token_t* token, const char* path);
lwjsonr_t lwjson_free(lwjson_t* lw);
lwjsonr_t lwjson_init(lwjson_t* lwobj, lwjson_token_t* tokens, size_t tokens_len);
lwjsonr_t lwjson_parse_ex(lwjson_t* lwobj, const void* json_data, size_t len);
lwjsonr_t lwjson_parse(lwjson_t* lwobj, const char* json_str);
const lwjson_token_t* lwjson_find(lwjson_t* lwobj, const char* path);
const lwjson_token_t* lwjson_find_ex(lwjson_t* lwobj, const lwjson_token_t* token, const char* path);
lwjsonr_t lwjson_free(lwjson_t* lwobj);

void lwjson_print_token(const lwjson_token_t* token);
void lwjson_print_json(const lwjson_t* lw);
void lwjson_print_json(const lwjson_t* lwobj);

/**
* \brief Object type for streaming parser
Expand Down Expand Up @@ -198,7 +196,7 @@ typedef struct lwjson_stream_parser {
stack[LWJSON_CFG_STREAM_STACK_SIZE]; /*!< Stack used for parsing. TODO: Add conditional compilation flag */
size_t stack_pos; /*!< Current stack position */

lwjson_stream_state_t parse_state; /*!< Parser state */
lwjson_stream_state_t parse_state; /*!< Parser state */

lwjson_stream_parser_callback_fn evt_fn; /*!< Event function for user */

Expand All @@ -219,7 +217,7 @@ typedef struct lwjson_stream_parser {
} prim; /*!< Primitive object. Used for all types, except key or string */

/* Todo: Add other types */
} data; /*!< Data union used to parse various */
} data; /*!< Data union used to parse various */

char prev_c; /*!< History of characters */
} lwjson_stream_parser_t;
Expand All @@ -230,17 +228,17 @@ lwjsonr_t lwjson_stream_parse(lwjson_stream_parser_t* jsp, char c);

/**
* \brief Get number of tokens used to parse JSON
* \param[in] lw: Pointer to LwJSON instance
* \param[in] lwobj: Pointer to LwJSON instance
* \return Number of tokens used to parse JSON
*/
#define lwjson_get_tokens_used(lw) (((lw) != NULL) ? ((lw)->next_free_token_pos + 1) : 0)
#define lwjson_get_tokens_used(lwobj) (((lwobj) != NULL) ? ((lwobj)->next_free_token_pos + 1) : 0)

/**
* \brief Get very first token of LwJSON instance
* \param[in] lw: Pointer to LwJSON instance
* \param[in] lwobj: Pointer to LwJSON instance
* \return Pointer to first token
*/
#define lwjson_get_first_token(lw) (((lw) != NULL) ? (&(lw)->first_token) : NULL)
#define lwjson_get_first_token(lwobj) (((lwobj) != NULL) ? (&(lwobj)->first_token) : NULL)

/**
* \brief Get token value for \ref LWJSON_TYPE_NUM_INT type
Expand Down
10 changes: 5 additions & 5 deletions lwjson/src/include/lwjson/lwjson_opt.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/*
* Copyright (c) 2022 Tilen MAJERLE
* Copyright (c) 2023 Tilen MAJERLE
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
Expand All @@ -29,10 +29,10 @@
* This file is part of LwJSON - Lightweight JSON format parser.
*
* Author: Tilen MAJERLE <[email protected]>
* Version: v1.6.0
* Version: v1.6.1
*/
#ifndef LWJSON_HDR_OPT_H
#define LWJSON_HDR_OPT_H
#ifndef LWJSON_OPT_HDR_H
#define LWJSON_OPT_HDR_H

/* Uncomment to ignore user options (or set macro in compiler flags) */
/* #define LWJSON_IGNORE_USER_OPTS */
Expand Down Expand Up @@ -132,4 +132,4 @@ extern "C" {
}
#endif /* __cplusplus */

#endif /* LWJSON_HDR_OPT_H */
#endif /* LWJSON_OPT_HDR_H */
10 changes: 5 additions & 5 deletions lwjson/src/include/lwjson/lwjson_opts_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/*
* Copyright (c) 2022 Tilen MAJERLE
* Copyright (c) 2023 Tilen MAJERLE
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
Expand All @@ -29,10 +29,10 @@
* This file is part of LwJSON - Lightweight JSON format parser.
*
* Author: Tilen MAJERLE <[email protected]>
* Version: v1.6.0
* Version: v1.6.1
*/
#ifndef LWJSON_HDR_OPTS_H
#define LWJSON_HDR_OPTS_H
#ifndef LWJSON_OPTS_HDR_H
#define LWJSON_OPTS_HDR_H

/* Rename this file to "lwjson_opts.h" for your application */

Expand All @@ -41,4 +41,4 @@
* copy & replace here settings you want to change values
*/

#endif /* LWJSON_HDR_OPTS_H */
#endif /* LWJSON_OPTS_HDR_H */
Loading

0 comments on commit 8902a7a

Please sign in to comment.