ether-code 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +130 -0
  3. package/cli/compiler.js +298 -0
  4. package/cli/ether.js +532 -0
  5. package/cli/watcher.js +106 -0
  6. package/generators/css-generator.js +583 -0
  7. package/generators/graphql-generator.js +868 -0
  8. package/generators/html-generator.js +745 -0
  9. package/generators/js-generator.js +909 -0
  10. package/generators/node-generator.js +467 -0
  11. package/generators/php-generator.js +706 -0
  12. package/generators/python-generator.js +913 -0
  13. package/generators/react-generator.js +599 -0
  14. package/generators/ruby-generator.js +904 -0
  15. package/generators/sql-generator.js +988 -0
  16. package/generators/ts-generator.js +569 -0
  17. package/i18n/i18n-css.json +743 -0
  18. package/i18n/i18n-graphql.json +1531 -0
  19. package/i18n/i18n-html.json +572 -0
  20. package/i18n/i18n-js.json +2790 -0
  21. package/i18n/i18n-node.json +2442 -0
  22. package/i18n/i18n-php.json +4306 -0
  23. package/i18n/i18n-python.json +3080 -0
  24. package/i18n/i18n-react.json +1784 -0
  25. package/i18n/i18n-ruby.json +1858 -0
  26. package/i18n/i18n-sql.json +3466 -0
  27. package/i18n/i18n-ts.json +442 -0
  28. package/lexer/ether-lexer.js +728 -0
  29. package/lexer/tokens.js +292 -0
  30. package/package.json +45 -0
  31. package/parsers/ast-css.js +545 -0
  32. package/parsers/ast-graphql.js +424 -0
  33. package/parsers/ast-html.js +886 -0
  34. package/parsers/ast-js.js +750 -0
  35. package/parsers/ast-node.js +2440 -0
  36. package/parsers/ast-php.js +957 -0
  37. package/parsers/ast-react.js +580 -0
  38. package/parsers/ast-ruby.js +895 -0
  39. package/parsers/ast-ts.js +1352 -0
  40. package/parsers/css-parser.js +1981 -0
  41. package/parsers/graphql-parser.js +2011 -0
  42. package/parsers/html-parser.js +1181 -0
  43. package/parsers/js-parser.js +2564 -0
  44. package/parsers/node-parser.js +2644 -0
  45. package/parsers/php-parser.js +3037 -0
  46. package/parsers/react-parser.js +1035 -0
  47. package/parsers/ruby-parser.js +2680 -0
  48. package/parsers/ts-parser.js +3881 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Steve
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,130 @@
1
+ # Ether
2
+
3
+ **Le langage intentionnel** - Programmez dans votre langue naturelle.
4
+
5
+ Ether est un compilateur qui transforme du code écrit en langage naturel (français, anglais, espagnol, russe, chinois, japonais) en code exécutable dans les langages cibles : JavaScript, TypeScript, HTML, CSS, PHP, Python, Ruby, SQL, Node.js, React, GraphQL.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install -g ether-lang
11
+ ```
12
+
13
+ ## Utilisation
14
+
15
+ ### Compiler un projet
16
+
17
+ ```bash
18
+ ether build
19
+ ```
20
+
21
+ ### Mode développement (watch)
22
+
23
+ ```bash
24
+ ether dev
25
+ ```
26
+
27
+ ### Compiler un fichier spécifique
28
+
29
+ ```bash
30
+ ether build fichier.eth
31
+ ```
32
+
33
+ ## Configuration
34
+
35
+ Créez un fichier `ether.config.json` à la racine de votre projet :
36
+
37
+ ```json
38
+ {
39
+ "lang": "fr",
40
+ "src": "./src",
41
+ "out": "./dist",
42
+ "targets": ["js", "css", "html"]
43
+ }
44
+ ```
45
+
46
+ ### Options
47
+
48
+ | Option | Description | Défaut |
49
+ |--------|-------------|--------|
50
+ | `lang` | Langue source (fr, en, es, ru, zh, ja) | `fr` |
51
+ | `src` | Dossier source | `./src` |
52
+ | `out` | Dossier de sortie | `./dist` |
53
+ | `targets` | Langages cibles | tous |
54
+
55
+ ## Exemple
56
+
57
+ ### Code Ether (français)
58
+
59
+ ```ether
60
+ // style.eth
61
+ sélecteur ".bouton"
62
+ couleur fond: bleu
63
+ couleur texte: blanc
64
+ marge: 1rem
65
+ bordure arrondie: 0.5rem
66
+ ```
67
+
68
+ ### Résultat CSS
69
+
70
+ ```css
71
+ .bouton {
72
+ background-color: blue;
73
+ color: white;
74
+ margin: 1rem;
75
+ border-radius: 0.5rem;
76
+ }
77
+ ```
78
+
79
+ ### Code Ether (JavaScript)
80
+
81
+ ```ether
82
+ // app.eth
83
+ fonction saluer avec nom
84
+ retourner "Bonjour, " + nom + "!"
85
+
86
+ afficher saluer("Monde")
87
+ ```
88
+
89
+ ### Résultat JavaScript
90
+
91
+ ```javascript
92
+ function saluer(nom) {
93
+ return "Bonjour, " + nom + "!";
94
+ }
95
+
96
+ console.log(saluer("Monde"));
97
+ ```
98
+
99
+ ## Langages supportés
100
+
101
+ ### Langues source
102
+ - 🇫🇷 Français
103
+ - 🇬🇧 English
104
+ - 🇪🇸 Español
105
+ - 🇷🇺 Русский
106
+ - 🇨🇳 中文
107
+ - 🇯🇵 日本語
108
+
109
+ ### Langages cibles
110
+ - JavaScript / TypeScript
111
+ - HTML / CSS
112
+ - PHP
113
+ - Python
114
+ - Ruby
115
+ - SQL
116
+ - Node.js
117
+ - React / JSX
118
+ - GraphQL
119
+
120
+ ## Philosophie
121
+
122
+ Ether est un **langage intentionnel** : au lieu de forcer les humains à parler comme des machines, Ether permet aux machines de comprendre l'intention humaine.
123
+
124
+ - **Naturel** : Écrivez du code comme vous pensez
125
+ - **Multilingue** : Programmez dans votre langue maternelle
126
+ - **Universel** : Un seul langage, tous les frameworks
127
+
128
+ ## Licence
129
+
130
+ MIT © Steve
@@ -0,0 +1,298 @@
1
+ const fs = require('fs')
2
+ const path = require('path')
3
+
4
+ const { EtherLexer } = require('../lexer/ether-lexer')
5
+
6
+ const { CSSGenerator } = require('../generators/css-generator')
7
+ const { HTMLGenerator } = require('../generators/html-generator')
8
+ const { JSGenerator } = require('../generators/js-generator')
9
+ const { PHPGenerator } = require('../generators/php-generator')
10
+ const { SQLGenerator } = require('../generators/sql-generator')
11
+ const { PythonGenerator } = require('../generators/python-generator')
12
+ const { RubyGenerator } = require('../generators/ruby-generator')
13
+ const { TSGenerator } = require('../generators/ts-generator')
14
+ const { NodeGenerator } = require('../generators/node-generator')
15
+ const { ReactGenerator } = require('../generators/react-generator')
16
+ const { GraphQLGenerator } = require('../generators/graphql-generator')
17
+
18
+ const GENERATORS = {
19
+ css: CSSGenerator,
20
+ html: HTMLGenerator,
21
+ js: JSGenerator,
22
+ javascript: JSGenerator,
23
+ php: PHPGenerator,
24
+ sql: SQLGenerator,
25
+ python: PythonGenerator,
26
+ py: PythonGenerator,
27
+ ruby: RubyGenerator,
28
+ rb: RubyGenerator,
29
+ ts: TSGenerator,
30
+ typescript: TSGenerator,
31
+ node: NodeGenerator,
32
+ nodejs: NodeGenerator,
33
+ react: ReactGenerator,
34
+ jsx: ReactGenerator,
35
+ graphql: GraphQLGenerator,
36
+ gql: GraphQLGenerator
37
+ }
38
+
39
+ const TARGET_EXTENSIONS = {
40
+ css: '.css',
41
+ html: '.html',
42
+ js: '.js',
43
+ javascript: '.js',
44
+ php: '.php',
45
+ sql: '.sql',
46
+ python: '.py',
47
+ py: '.py',
48
+ ruby: '.rb',
49
+ rb: '.rb',
50
+ ts: '.ts',
51
+ typescript: '.ts',
52
+ node: '.js',
53
+ nodejs: '.js',
54
+ react: '.jsx',
55
+ jsx: '.jsx',
56
+ graphql: '.graphql',
57
+ gql: '.graphql'
58
+ }
59
+
60
+ class EtherCompiler {
61
+ constructor(config = {}) {
62
+ this.config = {
63
+ i18n: 'fr',
64
+ targets: {},
65
+ ...config
66
+ }
67
+
68
+ this.lexer = new EtherLexer()
69
+ this.generators = {}
70
+ this.parsers = {}
71
+
72
+ this.initGenerators()
73
+ }
74
+
75
+ initGenerators() {
76
+ const i18nDir = path.join(__dirname, '..', 'i18n')
77
+
78
+ for (const [target, GeneratorClass] of Object.entries(GENERATORS)) {
79
+ const i18nFile = path.join(i18nDir, `i18n-${this.normalizeTarget(target)}.json`)
80
+
81
+ if (fs.existsSync(i18nFile)) {
82
+ this.generators[target] = new GeneratorClass(i18nFile)
83
+ } else {
84
+ this.generators[target] = new GeneratorClass()
85
+ }
86
+ }
87
+ }
88
+
89
+ normalizeTarget(target) {
90
+ const mappings = {
91
+ javascript: 'js',
92
+ typescript: 'ts',
93
+ nodejs: 'node',
94
+ python: 'python',
95
+ py: 'python',
96
+ ruby: 'ruby',
97
+ rb: 'ruby',
98
+ jsx: 'react',
99
+ gql: 'graphql'
100
+ }
101
+ return mappings[target] || target
102
+ }
103
+
104
+ async compileFile(filePath) {
105
+ const content = fs.readFileSync(filePath, 'utf-8')
106
+ const fileName = path.basename(filePath, '.eth')
107
+ const dirName = path.dirname(filePath)
108
+
109
+ const target = this.detectTarget(content, filePath)
110
+
111
+ const ast = this.parse(content, target)
112
+
113
+ const code = this.generate(ast, target)
114
+
115
+ const extension = this.getExtension(target)
116
+ const outputPath = `${fileName}${extension}`
117
+
118
+ return {
119
+ source: filePath,
120
+ target,
121
+ outputs: [{
122
+ path: outputPath,
123
+ content: code
124
+ }]
125
+ }
126
+ }
127
+
128
+ parse(content, target) {
129
+ const lexer = new EtherLexer(content)
130
+ const tokens = lexer.tokenize()
131
+
132
+ const normalizedTarget = this.normalizeTarget(target)
133
+
134
+ try {
135
+ const ParserClass = this.loadParser(normalizedTarget)
136
+ if (ParserClass) {
137
+ const parser = new ParserClass(tokens, this.config)
138
+ return parser.parse()
139
+ }
140
+ } catch (err) {
141
+ }
142
+
143
+ return this.buildGenericAST(tokens, target)
144
+ }
145
+
146
+ loadParser(target) {
147
+ try {
148
+ const parserPath = path.join(__dirname, '..', 'parsers', `${target}-parser.js`)
149
+ if (fs.existsSync(parserPath)) {
150
+ const module = require(parserPath)
151
+ const className = `${target.charAt(0).toUpperCase()}${target.slice(1)}Parser`
152
+ return module[className] || module.default || Object.values(module)[0]
153
+ }
154
+ } catch (err) {
155
+ }
156
+ return null
157
+ }
158
+
159
+ buildGenericAST(tokens, target) {
160
+ return {
161
+ type: 'Program',
162
+ target,
163
+ body: tokens.map(token => ({
164
+ type: 'Token',
165
+ tokenType: token.type,
166
+ value: token.value,
167
+ line: token.line,
168
+ column: token.column
169
+ }))
170
+ }
171
+ }
172
+
173
+ generate(ast, target) {
174
+ const normalizedTarget = this.normalizeTarget(target)
175
+ const generator = this.generators[normalizedTarget]
176
+
177
+ if (!generator) {
178
+ throw new Error(`Générateur non trouvé pour la cible: ${target}`)
179
+ }
180
+
181
+ return generator.generate(ast)
182
+ }
183
+
184
+ detectTarget(content, filePath) {
185
+ const directiveMatch = content.match(/^\/\/\s*(?:cible|target|@target)\s*:\s*(\w+)/im)
186
+ if (directiveMatch) {
187
+ return directiveMatch[1].toLowerCase()
188
+ }
189
+
190
+ const commentMatch = content.match(/^\/\*\s*(?:cible|target)\s*:\s*(\w+)\s*\*\//im)
191
+ if (commentMatch) {
192
+ return commentMatch[1].toLowerCase()
193
+ }
194
+
195
+ const hashMatch = content.match(/^#\s*(?:cible|target)\s*:\s*(\w+)/im)
196
+ if (hashMatch) {
197
+ return hashMatch[1].toLowerCase()
198
+ }
199
+
200
+ const fileName = path.basename(filePath, '.eth')
201
+ const parts = fileName.split('.')
202
+ if (parts.length > 1) {
203
+ const ext = parts[parts.length - 1].toLowerCase()
204
+ if (GENERATORS[ext]) {
205
+ return ext
206
+ }
207
+ }
208
+
209
+ return this.inferTargetFromContent(content)
210
+ }
211
+
212
+ inferTargetFromContent(content) {
213
+ const patterns = {
214
+ html: [
215
+ /\b(page|document|entête|corps|section|div|paragraphe|titre|lien|image|formulaire|bouton)\b/i,
216
+ /\b(balise|élément|attribut)\b/i
217
+ ],
218
+ css: [
219
+ /\b(style|couleur|taille|marge|bordure|fond|police|largeur|hauteur)\s*[:=]/i,
220
+ /\.([\w-]+)\s*\{/,
221
+ /#([\w-]+)\s*\{/
222
+ ],
223
+ js: [
224
+ /\b(fonction|variable|constante|si|sinon|pour|tant que|retourner)\b/i,
225
+ /\b(classe|méthode|constructeur)\b/i,
226
+ /=>\s*\{/
227
+ ],
228
+ php: [
229
+ /\b(<?php|echo|namespace|use)\b/i,
230
+ /\$\w+/
231
+ ],
232
+ sql: [
233
+ /\b(sélectionner|insérer|mettre à jour|supprimer|créer table|depuis|où)\b/i,
234
+ /\b(SELECT|INSERT|UPDATE|DELETE|CREATE|FROM|WHERE)\b/i
235
+ ],
236
+ python: [
237
+ /\b(def|class|import|from|if|elif|else|for|while|return)\b/,
238
+ /:\s*$/m
239
+ ],
240
+ react: [
241
+ /\b(composant|état|effet|props|rendu)\b/i,
242
+ /<[\w]+[^>]*\/>/
243
+ ],
244
+ graphql: [
245
+ /\b(type|query|mutation|subscription|schema|input)\b/i
246
+ ]
247
+ }
248
+
249
+ for (const [target, patternList] of Object.entries(patterns)) {
250
+ for (const pattern of patternList) {
251
+ if (pattern.test(content)) {
252
+ return target
253
+ }
254
+ }
255
+ }
256
+
257
+ return 'js'
258
+ }
259
+
260
+ getExtension(target) {
261
+ const normalizedTarget = this.normalizeTarget(target)
262
+
263
+ if (this.config.targets[normalizedTarget]?.extension) {
264
+ return this.config.targets[normalizedTarget].extension
265
+ }
266
+
267
+ return TARGET_EXTENSIONS[target] || TARGET_EXTENSIONS[normalizedTarget] || '.js'
268
+ }
269
+
270
+ async check(filePath) {
271
+ const content = fs.readFileSync(filePath, 'utf-8')
272
+ const target = this.detectTarget(content, filePath)
273
+
274
+ try {
275
+ this.lexer.tokenize(content)
276
+ } catch (err) {
277
+ throw new Error(`Erreur de lexer: ${err.message}`)
278
+ }
279
+
280
+ try {
281
+ this.parse(content, target)
282
+ } catch (err) {
283
+ throw new Error(`Erreur de syntaxe: ${err.message}`)
284
+ }
285
+
286
+ return { valid: true, target }
287
+ }
288
+
289
+ getTargets() {
290
+ return Object.keys(GENERATORS)
291
+ }
292
+
293
+ getSupportedExtensions() {
294
+ return Object.entries(TARGET_EXTENSIONS)
295
+ }
296
+ }
297
+
298
+ module.exports = { EtherCompiler, GENERATORS, TARGET_EXTENSIONS }