code-lexer 0.2 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/code-lexer/config.rb +12 -6
- data/lib/code-lexer/languages/javascript.yml +36 -0
- data/lib/code-lexer.rb +1 -1
- metadata +3 -3
- data/lib/code-lexer/languages/javascript.clex +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0be86a493e60a21bc3c8d16598c6f6af914a2521255bb604b01ffa9410ff399f
|
4
|
+
data.tar.gz: 46e60be81ceda1cc9621ef7519189a45cceaaa54afa27313a5c6d4c8be0e8377
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adcc4ee93e5c58da53df775584dbd4de485d8af7af232e2a7aa379a1ec09c1e928a804139983d585773f3b837bdb6f9fe95623107dfceaa0fb3afc2ddd5a7593
|
7
|
+
data.tar.gz: e9ee16aa762e15515d58930b29b5c8f784baee483f40fa1ae520734a0efc98f7680ffa5a4f6c88de3c261b836e17bb9e529aa4adc55314928d3a60f7f0d0d2da
|
data/lib/code-lexer/config.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
1
3
|
module CodeLexer
|
2
4
|
class Config
|
3
5
|
attr_reader :rules
|
@@ -5,7 +7,7 @@ module CodeLexer
|
|
5
7
|
@config = File.basename(path)
|
6
8
|
@rules = []
|
7
9
|
|
8
|
-
load_rules(
|
10
|
+
load_rules(path)
|
9
11
|
end
|
10
12
|
|
11
13
|
def matching_rule(text)
|
@@ -25,11 +27,15 @@ module CodeLexer
|
|
25
27
|
|
26
28
|
private
|
27
29
|
def load_rules(content)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
parsed = YAML.load_file(content)
|
31
|
+
|
32
|
+
|
33
|
+
parsed['lexer'].each do |name, regexs|
|
34
|
+
regexs.each do |regex|
|
35
|
+
p regex
|
36
|
+
regex = Regexp.new("^" + regex)
|
37
|
+
@rules << [name.to_sym, regex]
|
38
|
+
end
|
33
39
|
end
|
34
40
|
|
35
41
|
@rules << [:other, /./]
|
@@ -0,0 +1,36 @@
|
|
1
|
+
lexer:
|
2
|
+
keyword:
|
3
|
+
- (?:abstract|arguments|boolean|break|byte|case|catch|char|const|continue|debugger|default|delete|do|double|else|eval|false|final|finally|float|for|function|goto|if|implements|in|instanceof|int|interface|let|long|native|new|null|package|private|protected|public|return|short|static|switch|synchronized|this|throw|throws|transient|true|try|typeof|var|void|volatile|while|with|yield|class|enum|export|extends|import|super|from)
|
4
|
+
identifier:
|
5
|
+
- "[$A-Za-z_][$A-Za-z0-9_]*"
|
6
|
+
comment:
|
7
|
+
- \/\/[^\n\r]*[\n\r]
|
8
|
+
- \/\/.*$
|
9
|
+
- \/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/
|
10
|
+
string:
|
11
|
+
- \"([^"]|\\\")*\"
|
12
|
+
- \'[^']*\'
|
13
|
+
number:
|
14
|
+
- \-?[0-9]*\.[0-9]e\-?[0-9]+
|
15
|
+
- \-?[0-9]*\.[0-9]
|
16
|
+
- \-?[1-9][0-9]*
|
17
|
+
- \-?0[Xx][0-9A-Fa-f]+
|
18
|
+
- \-?[0-9]
|
19
|
+
- \-?0[0-7]+
|
20
|
+
operator:
|
21
|
+
- (\=\=\=|\!\=\=)
|
22
|
+
- (\<\=|\>\=|\=\=|\!\=)
|
23
|
+
- (\&\&|\|\||\!)
|
24
|
+
- (\+\=|\-\=|\/\=|\*\=|\%\=|\+\+|\-\-)
|
25
|
+
- (\&|\||\~|\^|\<\<|\>\>)
|
26
|
+
- (\=|\+|\-|\/|\*|\%)
|
27
|
+
- (\.|\,|\:)
|
28
|
+
- (\<|\>)
|
29
|
+
parenthesis:
|
30
|
+
- (\(|\)|\[|\]|\{|\})
|
31
|
+
semicolon:
|
32
|
+
- \;
|
33
|
+
newline:
|
34
|
+
- "[\\n\\r]"
|
35
|
+
space:
|
36
|
+
- \s+
|
data/lib/code-lexer.rb
CHANGED
@@ -5,6 +5,6 @@ require_relative 'code-lexer/token'
|
|
5
5
|
|
6
6
|
module CodeLexer
|
7
7
|
def self.get(language)
|
8
|
-
return Lexer.new("#{File.dirname(File.expand_path(__FILE__))}/code-lexer/languages/#{language}.
|
8
|
+
return Lexer.new("#{File.dirname(File.expand_path(__FILE__))}/code-lexer/languages/#{language}.yml")
|
9
9
|
end
|
10
10
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code-lexer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.6'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simone Scalabrino
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: code-assertions
|
@@ -40,7 +40,7 @@ files:
|
|
40
40
|
- lib/code-lexer.rb
|
41
41
|
- lib/code-lexer/abstractor.rb
|
42
42
|
- lib/code-lexer/config.rb
|
43
|
-
- lib/code-lexer/languages/javascript.
|
43
|
+
- lib/code-lexer/languages/javascript.yml
|
44
44
|
- lib/code-lexer/lexer.rb
|
45
45
|
- lib/code-lexer/token.rb
|
46
46
|
homepage: https://github.com/intersimone999/code-lexer
|
@@ -1,24 +0,0 @@
|
|
1
|
-
keyword:(?:abstract|arguments|boolean|break|byte|case|catch|char|const|continue|debugger|default|delete|do|double|else|eval|false|final|finally|float|for|function|goto|if|implements|in|instanceof|int|interface|let|long|native|new|null|package|private|protected|public|return|short|static|switch|synchronized|this|throw|throws|transient|true|try|typeof|var|void|volatile|while|with|yield|class|enum|export|extends|import|super|from)
|
2
|
-
identifier:[$A-Za-z_][$A-Za-z0-9_]*
|
3
|
-
comment:\/\/[^.]*[\n\r]
|
4
|
-
comment:\/\/[^.]*$
|
5
|
-
comment:\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/
|
6
|
-
string:\"([^"]|\\\")*\"
|
7
|
-
string:\'[^']*\'
|
8
|
-
number:\-?[0-9]
|
9
|
-
number:\-?[1-9][0-9]*
|
10
|
-
number:\-?[0-9]*\.[0-9]
|
11
|
-
number:\-?[0-9]*\.[0-9]e\-?[0-9]+
|
12
|
-
number:\-?0[Xx][0-9A-Fa-f]+
|
13
|
-
number:\-?0[0-7]+
|
14
|
-
operator:(\<\=|\>\=|\=\=|\=\=\=|\!\=\=|\!\=)
|
15
|
-
operator:(\&\&|\||\|\||\!)
|
16
|
-
operator:(\=|\+\=|\-\=|\/\=|\*\=|\%\=)
|
17
|
-
operator:(\&|\||\~|\^|\<\<|\>\>)
|
18
|
-
operator:(\+|\-|\/|\*|\%|\+\+|\-\-)
|
19
|
-
operator:(\.|\,|\:)
|
20
|
-
operator:(\<|\>)
|
21
|
-
parenthesis:(\(|\)|\[|\]|\{|\})
|
22
|
-
semicolon:\;
|
23
|
-
newline:[\n\r]
|
24
|
-
space:\s+
|