ether-code 0.7.7 → 0.7.8

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.
package/cli/compiler.js CHANGED
@@ -2,7 +2,7 @@ const fs = require('fs')
2
2
  const path = require('path')
3
3
 
4
4
  const { EtherLexer } = require('../lexer/ether-lexer')
5
- const { EtherParser } = require('../ether-parser')
5
+ const { EtherParser } = require('../parsers/ether-parser')
6
6
 
7
7
  const { CSSGenerator } = require('../generators/css-generator')
8
8
  const { HTMLGenerator } = require('../generators/html-generator')
package/cli/ether.js CHANGED
@@ -6,7 +6,7 @@ const http = require('http')
6
6
  const { EtherCompiler } = require('./compiler')
7
7
  const { Watcher } = require('./watcher')
8
8
 
9
- const VERSION = '0.7.7'
9
+ const VERSION = '0.7.8'
10
10
 
11
11
  const COLORS = {
12
12
  reset: '\x1b[0m',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ether-code",
3
- "version": "0.7.7",
3
+ "version": "0.7.8",
4
4
  "description": "Ether - Le langage intentionnel",
5
5
  "main": "cli/compiler.js",
6
6
  "bin": {
@@ -38,7 +38,7 @@
38
38
  "generators/",
39
39
  "lexer/",
40
40
  "i18n/",
41
- "ether-parser.js",
41
+ "parsers/ether-parser.js",
42
42
  "ether-compiler.js",
43
43
  "README.md",
44
44
  "LICENSE"
@@ -0,0 +1,145 @@
1
+ const { EtherLexer, TokenType } = require('../lexer/ether-lexer')
2
+ const { EtherParserJS } = require('./ether-parser-js')
3
+ const { EtherParserCSS } = require('./ether-parser-css')
4
+ const { EtherParserHTML } = require('./ether-parser-html')
5
+ const { EtherParserSQL } = require('./ether-parser-sql')
6
+ const { EtherParserGraphQL } = require('./ether-parser-graphql')
7
+
8
+ class EtherParser {
9
+ constructor(options = {}) {
10
+ this.options = options
11
+ this.targetLang = options.targetLang || 'auto'
12
+
13
+ this.parsers = {
14
+ js: null,
15
+ ts: null,
16
+ react: null,
17
+ node: null,
18
+ php: null,
19
+ css: null,
20
+ html: null,
21
+ sql: null,
22
+ graphql: null,
23
+ python: null,
24
+ ruby: null
25
+ }
26
+ }
27
+
28
+ getParser(lang) {
29
+ if (!this.parsers[lang]) {
30
+ switch (lang) {
31
+ case 'js':
32
+ case 'ts':
33
+ case 'react':
34
+ case 'node':
35
+ case 'php':
36
+ case 'python':
37
+ case 'ruby':
38
+ this.parsers[lang] = new EtherParserJS(this.options)
39
+ break
40
+ case 'css':
41
+ this.parsers[lang] = new EtherParserCSS(this.options)
42
+ break
43
+ case 'html':
44
+ this.parsers[lang] = new EtherParserHTML(this.options)
45
+ break
46
+ case 'sql':
47
+ this.parsers[lang] = new EtherParserSQL(this.options)
48
+ break
49
+ case 'graphql':
50
+ this.parsers[lang] = new EtherParserGraphQL(this.options)
51
+ break
52
+ default:
53
+ this.parsers[lang] = new EtherParserJS(this.options)
54
+ }
55
+ }
56
+ return this.parsers[lang]
57
+ }
58
+
59
+ detectTargetLanguage(source) {
60
+ const lower = source.toLowerCase()
61
+
62
+ const targetMatch = source.match(/\/\/\s*cible\s*:\s*(\w+)/i)
63
+ if (targetMatch) {
64
+ const target = targetMatch[1].toLowerCase()
65
+ const langMap = {
66
+ 'js': 'js', 'javascript': 'js',
67
+ 'css': 'css', 'style': 'css',
68
+ 'html': 'html', 'page': 'html',
69
+ 'ts': 'ts', 'typescript': 'ts',
70
+ 'react': 'react', 'jsx': 'react',
71
+ 'php': 'php',
72
+ 'python': 'python', 'py': 'python',
73
+ 'ruby': 'ruby', 'rb': 'ruby',
74
+ 'sql': 'sql',
75
+ 'node': 'node', 'nodejs': 'node',
76
+ 'graphql': 'graphql', 'gql': 'graphql'
77
+ }
78
+ if (langMap[target]) {
79
+ return langMap[target]
80
+ }
81
+ }
82
+
83
+ if (/^\s*(document|page|<!doctype|<html|tete|corps|entete|navigation|section|article)/m.test(lower)) {
84
+ return 'html'
85
+ }
86
+
87
+ if (/^\s*(\.|#|@media|@keyframes|corps|html|body|fond|marge|remplissage|largeur|hauteur)/m.test(lower)) {
88
+ if (!/fonction|si\s|pour\s|tant que/.test(lower)) {
89
+ return 'css'
90
+ }
91
+ }
92
+
93
+ if (/^\s*(composant|etat|effet|memo|contexte|utiliser\s+(etat|effet|memo)|retourner\s*\(?\s*<)/m.test(lower)) {
94
+ return 'react'
95
+ }
96
+
97
+ if (/<[a-z]+|jsx|tsx/i.test(lower) && /fonction|composant/.test(lower)) {
98
+ return 'react'
99
+ }
100
+
101
+ if (/^\s*(creer table|inserer|selectionner|mettre a jour|supprimer|table|base de donnees)/m.test(lower)) {
102
+ return 'sql'
103
+ }
104
+
105
+ if (/^\s*(type|interface|enum|generique|<[A-Z]\w*>)/m.test(lower)) {
106
+ return 'ts'
107
+ }
108
+
109
+ if (/^\s*(schema|type\s+\w+\s*{|query|mutation|subscription|input\s+\w+)/m.test(lower)) {
110
+ return 'graphql'
111
+ }
112
+
113
+ if (/^\s*(<\?php|\$\w+|echo|inclure|require)/m.test(lower)) {
114
+ return 'php'
115
+ }
116
+
117
+ if (/^\s*(def\s+\w+|classe\s+\w+|importer\s|de\s+\w+\s+importer)/m.test(lower) && !/fin\s*$|faire\s*$/m.test(lower)) {
118
+ return 'python'
119
+ }
120
+
121
+ if (/^\s*(classe\s+\w+|def\s+\w+|fin\s*$|faire\s*$|module\s+\w+)/m.test(lower)) {
122
+ return 'ruby'
123
+ }
124
+
125
+ if (/^\s*(const\s+\w+\s*=\s*require|module\.exports|exporter\s+defaut)/m.test(lower)) {
126
+ return 'node'
127
+ }
128
+
129
+ if (/fonction|variable|constante|si\s|pour\s|tant que|retourner/.test(lower)) {
130
+ return 'js'
131
+ }
132
+
133
+ return 'js'
134
+ }
135
+
136
+ parse(source, targetLang = null) {
137
+ const detectedLang = targetLang || this.targetLang
138
+ const lang = detectedLang === 'auto' ? this.detectTargetLanguage(source) : detectedLang
139
+
140
+ const parser = this.getParser(lang)
141
+ return parser.parse(source, lang)
142
+ }
143
+ }
144
+
145
+ module.exports = { EtherParser, TokenType }