code-lexer 0.1 → 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: d6c98649f07e77d4148fb744db9b79fb0ed714113d6aaee7cf02f249868070c9
4
- data.tar.gz: 6c6deb5e8f6778a036dd60cf49d649192620455d0197358b4783e0df0dd91bce
3
+ metadata.gz: 6ce8480d1b7e07f708c5cf0134a7eb05a6e85c493bc5cf391db1d0f36b195768
4
+ data.tar.gz: ebfed8650052cba1280b1a6ad8178f6080d2cd6fe70626153bb29e5c8a62f6e2
5
5
  SHA512:
6
- metadata.gz: 60556343e374a1c7ea58a076473fa98e9a15f4b8a89451788675a2415eb7c2da05f9255463abe9a2ae75da239c84a6186f8d5bc7aa570dd16580bdd8e685a7e7
7
- data.tar.gz: 974dcf39a0a41c496f61429dd0e5b16557a80be856fef450dddac29a19ca72dc4b4ed0c33a2ff9226a4c683af665b44d1b26c2b36ac49d15cd96d47cc350cd20
6
+ metadata.gz: 30ce58ffe14a55397dfdc23c1ab4cdb73e0b1e25e4b3eaa2f829157a50dd60c0cf6475a0911ea6e28d4ab98343b17179b31064dca984bbec53ddd811d6259b75
7
+ data.tar.gz: b4373e903dd74fc372d36b32370a2f7f0106f019b9e04a9049341443014c15276f0035579c2e7b93f69d9a4978c45761a193321322a3253a5a77cafa0f86e7dc
@@ -8,6 +8,16 @@ module CodeLexer
8
8
  @dictionary = ["NOOP"] + dictionary
9
9
  end
10
10
 
11
+ def abstract_everything
12
+ self.abstract_identifiers
13
+ self.abstract_numbers
14
+ self.abstract_comments
15
+ self.abstract_strings
16
+ self.abstract_spaces
17
+
18
+ return self
19
+ end
20
+
11
21
  def abstract_identifiers
12
22
  @abstract_identifiers = true
13
23
  return self
@@ -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.1'
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simone Scalabrino
8
- autorequire:
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,14 +40,14 @@ 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
47
47
  licenses:
48
48
  - GPL-3.0-only
49
49
  metadata: {}
50
- post_install_message:
50
+ post_install_message:
51
51
  rdoc_options: []
52
52
  require_paths:
53
53
  - lib
@@ -62,8 +62,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
64
  requirements: []
65
- rubygems_version: 3.2.29
66
- signing_key:
65
+ rubygems_version: 3.2.32
66
+ signing_key:
67
67
  specification_version: 4
68
68
  summary: Simple source code lexer
69
69
  test_files: []
@@ -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+