code-lexer 0.4 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13a18bbab7eb8a08deb270c5213c34b0a21d3ada73414d0cf7bfdd35606e4388
4
- data.tar.gz: f22c5fb83d5521dae653992f17de00a18fcc9a6fef37f026ab8b1051b7085fd0
3
+ metadata.gz: 6ce8480d1b7e07f708c5cf0134a7eb05a6e85c493bc5cf391db1d0f36b195768
4
+ data.tar.gz: ebfed8650052cba1280b1a6ad8178f6080d2cd6fe70626153bb29e5c8a62f6e2
5
5
  SHA512:
6
- metadata.gz: ccb2e6926b6868f3f4a9bdb18b420157dfc09beace098d9eceaddc85baffe2d2d63dabc2de6256bd1bdb0dc334adc16f36c60238700664c119a5327b01dd54a5
7
- data.tar.gz: fb1d5bca13e9c23cba238ca9f85839a92238789fab85b5530408c6ddcd8e4f58bcebd8c000f2107b65ffe8b12783583684393c23f6d6581f787e46ede62855ff
6
+ metadata.gz: 30ce58ffe14a55397dfdc23c1ab4cdb73e0b1e25e4b3eaa2f829157a50dd60c0cf6475a0911ea6e28d4ab98343b17179b31064dca984bbec53ddd811d6259b75
7
+ data.tar.gz: b4373e903dd74fc372d36b32370a2f7f0106f019b9e04a9049341443014c15276f0035579c2e7b93f69d9a4978c45761a193321322a3253a5a77cafa0f86e7dc
@@ -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(File.read(path))
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
- content.split("\n").each do |line|
29
- name, regex = line.split(":", 2)
30
- regex = Regexp.new("^" + regex)
31
-
32
- @rules << [name.to_sym, regex]
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]
15
+ - \-?[1-9][0-9]*
16
+ - \-?[0-9]*\.[0-9]
17
+ - \-?[0-9]*\.[0-9]e\-?[0-9]+
18
+ - \-?0[Xx][0-9A-Fa-f]+
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}.clex")
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'
4
+ version: 0.5.1
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-28 00:00:00.000000000 Z
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.clex
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,25 +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]*[\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
- operator:(\<|\>)
22
- parenthesis:(\(|\)|\[|\]|\{|\})
23
- semicolon:\;
24
- newline:[\n\r]
25
- space:\s+