From 5c230596cda6cb9acce482cf6ea25909caed202b Mon Sep 17 00:00:00 2001 From: RonaldsonBellande Date: Tue, 3 Sep 2024 23:03:49 -0400 Subject: [PATCH 1/9] latest pushes --- Package/Python/README.md | 24 ++++++ Package/Python/src/bellande_parser.py | 115 ++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 Package/Python/src/bellande_parser.py diff --git a/Package/Python/README.md b/Package/Python/README.md index 887d165..2984480 100644 --- a/Package/Python/README.md +++ b/Package/Python/README.md @@ -10,3 +10,27 @@ parsed_data = bellande_formatter.parse_bellande("path/to/your/file.bellande") data_to_write = {"key": "value", "list": [1, 2, 3]} bellande_formatter.write_bellande(data_to_write, "path/to/output/file.bellande") ``` + +## Website PYPI +- https://pypi.org/project/bellande_format + +### Installation +- `$ pip install bellande_format` + +### Upgrade (if not upgraded) +- `$ pip install --upgrade bellande_format` + +``` +Name: bellande_robot_step +Version: 0.3.0 +Summary: Computes the next step towards a target node +Home-page: github.com/RonaldsonBellande/bellande_robot_step +Author: Ronaldson Bellande +Author-email: ronaldsonbellande@gmail.com +License: GNU General Public License v3.0 +Requires: numpy +Required-by: +``` + +## License +This Algorithm or Models is distributed under the [Creative Commons Attribution-ShareAlike 4.0 International License](http://creativecommons.org/licenses/by-sa/4.0/), see [LICENSE](https://github.com/RonaldsonBellande/bellande_format/blob/main/LICENSE) and [NOTICE](https://github.com/RonaldsonBellande/bellande_format/blob/main/LICENSE) for more information. diff --git a/Package/Python/src/bellande_parser.py b/Package/Python/src/bellande_parser.py new file mode 100644 index 0000000..6170547 --- /dev/null +++ b/Package/Python/src/bellande_parser.py @@ -0,0 +1,115 @@ +# Copyright (C) 2024 Bellande Algorithm Model Research Innovation Center, Ronaldson Bellande + +# 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 3 of the License, or +# (at your option) any later version. + +# This program 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 General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +#!/usr/bin/env python3 + +import re +from typing import Dict, List, Union, Any + +class bellande_format: + def parse_bellande(self, file_path: str) -> Dict: + with open(file_path, 'r') as file: + lines = file.readlines() + return self.parse_lines(lines) + + def parse_lines(self, lines: List[str]) -> Dict: + result = {} + stack = [(-1, result)] + + for line in lines: + stripped = line.strip() + if not stripped or stripped.startswith('#'): + continue + + indent = len(line) - len(line.lstrip()) + while stack and indent <= stack[-1][0]: + stack.pop() + + parent = stack[-1][1] + + if ':' in stripped: + key, value = map(str.strip, stripped.split(':', 1)) + if value: + parent[key] = self.parse_value(value) + else: + new_dict = {} + parent[key] = new_dict + stack.append((indent, new_dict)) + elif stripped.startswith('-'): + value = stripped[1:].strip() + + if isinstance(parent, list): + parent.append(self.parse_value(value)) + else: + new_list = [self.parse_value(value)] + last_key = list(parent.keys())[-1] + parent[last_key] = new_list + stack.append((indent, new_list)) + + return result + + def parse_value(self, value: str) -> Union[str, int, float, bool, None]: + if value.lower() == 'true': + return True + elif value.lower() == 'false': + return False + elif value.lower() == 'null': + return None + elif value.startswith('"') and value.endswith('"'): + return value[1:-1] + elif re.match(r'^-?\d+$', value): + return int(value) + elif re.match(r'^-?\d*\.\d+$', value): + return float(value) + else: + return value + + def write_bellande(self, data: Any, file_path: str): + with open(file_path, 'w') as file: + file.write(self.to_bellande_string(data)) + + def to_bellande_string(self, data: Any, indent: int = 0) -> str: + if isinstance(data, dict): + lines = [] + for key, value in data.items(): + if isinstance(value, (dict, list)): + lines.append(f"{' ' * indent}{key}:") + lines.append(self.to_bellande_string(value, indent + 4)) + else: + lines.append(f"{' ' * indent}{key}: {self.format_value(value)}") + return '\n'.join(lines) + elif isinstance(data, list): + lines = [] + for item in data: + if isinstance(item, (dict, list)): + lines.append(f"{' ' * indent}-") + lines.append(self.to_bellande_string(item, indent + 4)) + else: + lines.append(f"{' ' * indent}- {self.format_value(item)}") + return '\n'.join(lines) + else: + return f"{' ' * indent}{self.format_value(data)}" + + def format_value(self, value: Any) -> str: + if isinstance(value, str): + if ' ' in value or ':' in value: + return f'"{value}"' + return value + elif isinstance(value, bool): + return str(value).lower() + elif value is None: + return 'null' + else: + return str(value) From 99c916531bd1708d531ba0fdea7b623394879a11 Mon Sep 17 00:00:00 2001 From: RonaldsonBellande Date: Tue, 3 Sep 2024 23:05:02 -0400 Subject: [PATCH 2/9] latest pushes --- Package/Python/.gitignore | 5 +++++ git_scripts/.gitignore | 3 +++ 2 files changed, 8 insertions(+) create mode 100644 Package/Python/.gitignore create mode 100644 git_scripts/.gitignore diff --git a/Package/Python/.gitignore b/Package/Python/.gitignore new file mode 100644 index 0000000..51c275c --- /dev/null +++ b/Package/Python/.gitignore @@ -0,0 +1,5 @@ +publish.sh +src +tests +setup.py +dist diff --git a/git_scripts/.gitignore b/git_scripts/.gitignore new file mode 100644 index 0000000..e5a7a9c --- /dev/null +++ b/git_scripts/.gitignore @@ -0,0 +1,3 @@ +fix_errors.sh +push.sh +repository_recal.sh From d0bbc81d9f7705741b1b92cdea371483bbccc796 Mon Sep 17 00:00:00 2001 From: RonaldsonBellande Date: Tue, 3 Sep 2024 23:32:42 -0400 Subject: [PATCH 3/9] bellande parser packages --- Package/Python/README.md | 8 ++++---- git_scripts/.gitignore | 3 --- 2 files changed, 4 insertions(+), 7 deletions(-) delete mode 100644 git_scripts/.gitignore diff --git a/Package/Python/README.md b/Package/Python/README.md index 2984480..ae3a3e4 100644 --- a/Package/Python/README.md +++ b/Package/Python/README.md @@ -21,10 +21,10 @@ bellande_formatter.write_bellande(data_to_write, "path/to/output/file.bellande") - `$ pip install --upgrade bellande_format` ``` -Name: bellande_robot_step -Version: 0.3.0 -Summary: Computes the next step towards a target node -Home-page: github.com/RonaldsonBellande/bellande_robot_step +Name: bellande_format +Version: 0.1.0 +Summary: File type Formats +Home-page: github.com/RonaldsonBellande/bellande_format Author: Ronaldson Bellande Author-email: ronaldsonbellande@gmail.com License: GNU General Public License v3.0 diff --git a/git_scripts/.gitignore b/git_scripts/.gitignore deleted file mode 100644 index e5a7a9c..0000000 --- a/git_scripts/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -fix_errors.sh -push.sh -repository_recal.sh From 3bcb3ccfc4b8d3c9489b62a68578dce2a40f5d5b Mon Sep 17 00:00:00 2001 From: RonaldsonBellande Date: Tue, 3 Sep 2024 23:59:30 -0400 Subject: [PATCH 4/9] recal --- Package/Python/.gitignore | 1 - git_scripts/.gitignore | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 git_scripts/.gitignore diff --git a/Package/Python/.gitignore b/Package/Python/.gitignore index 51c275c..3e54b1f 100644 --- a/Package/Python/.gitignore +++ b/Package/Python/.gitignore @@ -1,5 +1,4 @@ publish.sh -src tests setup.py dist diff --git a/git_scripts/.gitignore b/git_scripts/.gitignore new file mode 100644 index 0000000..e5a7a9c --- /dev/null +++ b/git_scripts/.gitignore @@ -0,0 +1,3 @@ +fix_errors.sh +push.sh +repository_recal.sh From b1e6342b81bbeadc7cf975c8c64aa18ba6859f3f Mon Sep 17 00:00:00 2001 From: Ronaldson Bellande <47253433+RonaldsonBellande@users.noreply.github.com> Date: Wed, 4 Sep 2024 14:27:48 -0400 Subject: [PATCH 5/9] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 6256550..b751661 100644 --- a/README.md +++ b/README.md @@ -45,3 +45,6 @@ projects: status: completed team_size: 3 ``` + +## License +This Algorithm or Models is distributed under the [Creative Commons Attribution-ShareAlike 4.0 International License](http://creativecommons.org/licenses/by-sa/4.0/), see [LICENSE](https://github.com/RonaldsonBellande/bellande_format/blob/main/LICENSE) and [NOTICE](https://github.com/RonaldsonBellande/bellande_format/blob/main/LICENSE) for more information. From 5fa2ffc26dedbd003280b14c9c0364f5e0119382 Mon Sep 17 00:00:00 2001 From: RonaldsonBellande Date: Wed, 4 Sep 2024 19:12:27 -0400 Subject: [PATCH 6/9] latest pushes --- Package/JavaScript/README.md | 36 +++++++++ Package/JavaScript/package.json | 19 +++++ Package/JavaScript/src/bellande_parser.js | 97 +++++++++++++++++++++++ Package/Python/README.md | 2 +- 4 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 Package/JavaScript/README.md create mode 100644 Package/JavaScript/package.json create mode 100644 Package/JavaScript/src/bellande_parser.js diff --git a/Package/JavaScript/README.md b/Package/JavaScript/README.md new file mode 100644 index 0000000..065029a --- /dev/null +++ b/Package/JavaScript/README.md @@ -0,0 +1,36 @@ +# Bellande Format JavaScript Example + +``` +// Example usage +const bellandeFormatter = new BellandeFormat(); + +// Parse a Bellande file +const parsedData = bellandeFormatter.parseBellande('path/to/your/file.bellande'); +console.log(parsedData); + +// Write data to a Bellande file +const dataToWrite = { key: 'value', list: [1, 2, 3] }; +bellandeFormatter.writeBellande(dataToWrite, 'path/to/output/file.bellande'); +``` + +## Website NPM +- https://www.npmjs.com/package/bellande_format + +### Installation +- `npm i bellande_format` + + +``` +Name: bellande_format +Version: 0.1.0 +Summary: File type Formats +Home-page: github.com/RonaldsonBellande/bellande_format +Author: Ronaldson Bellande +Author-email: ronaldsonbellande@gmail.com +License: GNU General Public License v3.0 +Requires: numpy +Required-by: +``` + +## License +This Algorithm or Models is distributed under the [Creative Commons Attribution-ShareAlike 4.0 International License](http://creativecommons.org/licenses/by-sa/4.0/), see [LICENSE](https://github.com/RonaldsonBellande/bellande_format/blob/main/LICENSE) and [NOTICE](https://github.com/RonaldsonBellande/bellande_format/blob/main/LICENSE) for more information. diff --git a/Package/JavaScript/package.json b/Package/JavaScript/package.json new file mode 100644 index 0000000..23764c0 --- /dev/null +++ b/Package/JavaScript/package.json @@ -0,0 +1,19 @@ +{ + "name": "bellande_format", + "version": "0.1.1", + "description": "File type Formats", + "main": "src/bellande_parser.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "github.com/RonaldsonBellande/bellande_format" + }, + "keywords": [ + "Bellande", + "Format" + ], + "author": "Ronaldson Bellande", + "license": "GNU General Public License v3.0" +} diff --git a/Package/JavaScript/src/bellande_parser.js b/Package/JavaScript/src/bellande_parser.js new file mode 100644 index 0000000..c86feb1 --- /dev/null +++ b/Package/JavaScript/src/bellande_parser.js @@ -0,0 +1,97 @@ +const fs = require('fs'); + +class BellandeFormat { + parseBellande(filePath) { + const content = fs.readFileSync(filePath, 'utf8'); + const lines = content.split('\n'); + return this.parseLines(lines); + } + + parseLines(lines) { + const result = {}; + const stack = [[-1, result]]; + + for (const line of lines) { + const stripped = line.trim(); + if (!stripped || stripped.startsWith('#')) continue; + + const indent = line.length - line.trimLeft().length; + while (stack.length && indent <= stack[stack.length - 1][0]) { + stack.pop(); + } + + const parent = stack[stack.length - 1][1]; + + if (stripped.includes(':')) { + const [key, value] = stripped.split(':').map(s => s.trim()); + if (value) { + parent[key] = this.parseValue(value); + } else { + const newDict = {}; + parent[key] = newDict; + stack.push([indent, newDict]); + } + } else if (stripped.startsWith('-')) { + const value = stripped.slice(1).trim(); + if (Array.isArray(parent)) { + parent.push(this.parseValue(value)); + } else { + const newList = [this.parseValue(value)]; + const lastKey = Object.keys(parent).pop(); + parent[lastKey] = newList; + stack.push([indent, newList]); + } + } + } + + return result; + } + + parseValue(value) { + if (value.toLowerCase() === 'true') return true; + if (value.toLowerCase() === 'false') return false; + if (value.toLowerCase() === 'null') return null; + if (value.startsWith('"') && value.endsWith('"')) return value.slice(1, -1); + if (/^-?\d+$/.test(value)) return parseInt(value, 10); + if (/^-?\d*\.\d+$/.test(value)) return parseFloat(value); + return value; + } + + writeBellande(data, filePath) { + const content = this.toBellandeString(data); + fs.writeFileSync(filePath, content); + } + + toBellandeString(data, indent = 0) { + if (typeof data === 'object' && data !== null) { + if (Array.isArray(data)) { + return data.map(item => `${' '.repeat(indent)}- ${this.toBellandeString(item, indent + 2)}`).join('\n'); + } else { + return Object.entries(data) + .map(([key, value]) => { + if (typeof value === 'object' && value !== null) { + return `${' '.repeat(indent)}${key}:\n${this.toBellandeString(value, indent + 2)}`; + } else { + return `${' '.repeat(indent)}${key}: ${this.formatValue(value)}`; + } + }) + .join('\n'); + } + } else { + return this.formatValue(data); + } + } + + formatValue(value) { + if (typeof value === 'string') { + return value.includes(' ') || value.includes(':') ? `"${value}"` : value; + } + if (typeof value === 'boolean') { + return value.toString(); + } + if (value === null) { + return 'null'; + } + return value.toString(); + } +} diff --git a/Package/Python/README.md b/Package/Python/README.md index ae3a3e4..c9cb265 100644 --- a/Package/Python/README.md +++ b/Package/Python/README.md @@ -1,4 +1,4 @@ -# Bellande Format Example +# Bellande Format Python Example ``` bellande_formatter = Bellande_Format() From 07351c2f28ebe31603713e14ea2fd3baa3ef9173 Mon Sep 17 00:00:00 2001 From: Ronaldson Bellande <47253433+RonaldsonBellande@users.noreply.github.com> Date: Wed, 4 Sep 2024 19:16:07 -0400 Subject: [PATCH 7/9] Delete git_scripts directory --- git_scripts/.gitignore | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 git_scripts/.gitignore diff --git a/git_scripts/.gitignore b/git_scripts/.gitignore deleted file mode 100644 index e5a7a9c..0000000 --- a/git_scripts/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -fix_errors.sh -push.sh -repository_recal.sh From 43d3e84137c1b7e94fff1b1b1590f56fadf47e6c Mon Sep 17 00:00:00 2001 From: RonaldsonBellande Date: Wed, 4 Sep 2024 19:16:31 -0400 Subject: [PATCH 8/9] latest pushes --- Package/JavaScript/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/Package/JavaScript/README.md b/Package/JavaScript/README.md index 065029a..c008bad 100644 --- a/Package/JavaScript/README.md +++ b/Package/JavaScript/README.md @@ -28,8 +28,6 @@ Home-page: github.com/RonaldsonBellande/bellande_format Author: Ronaldson Bellande Author-email: ronaldsonbellande@gmail.com License: GNU General Public License v3.0 -Requires: numpy -Required-by: ``` ## License From b3fc18f894256f38a58ba47ba099c8781b57c25f Mon Sep 17 00:00:00 2001 From: RonaldsonBellande Date: Wed, 4 Sep 2024 19:34:40 -0400 Subject: [PATCH 9/9] Remove files listed in .gitignore --- git_scripts/.gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 git_scripts/.gitignore diff --git a/git_scripts/.gitignore b/git_scripts/.gitignore new file mode 100644 index 0000000..e5a7a9c --- /dev/null +++ b/git_scripts/.gitignore @@ -0,0 +1,3 @@ +fix_errors.sh +push.sh +repository_recal.sh