modl 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -4
- data/README.md +10 -7
- data/grammar_tests/base_tests.json +1 -1
- data/lib/modl/parser/MODLLexer.rb +217 -217
- data/lib/modl/parser/MODLParser.interp +1 -1
- data/lib/modl/parser/MODLParser.rb +389 -400
- data/lib/modl/parser/MODLParserBaseListener.rb +1 -1
- data/lib/modl/parser/MODLParserBaseVisitor.rb +1 -1
- data/lib/modl/parser/MODLParserListener.rb +1 -1
- data/lib/modl/parser/MODLParserVisitor.rb +1 -1
- data/lib/modl/parser/class_processor.rb +2 -2
- data/lib/modl/parser/evaluator.rb +5 -5
- data/lib/modl/parser/file_importer.rb +11 -7
- data/lib/modl/parser/global_parse_context.rb +7 -3
- data/lib/modl/parser/instruction_processor.rb +3 -1
- data/lib/modl/parser/interpreter.rb +20 -5
- data/lib/modl/parser/modl_class.rb +1 -1
- data/lib/modl/parser/modl_index.rb +1 -1
- data/lib/modl/parser/modl_keylist.rb +1 -1
- data/lib/modl/parser/modl_method.rb +1 -1
- data/lib/modl/parser/object_cache.rb +1 -1
- data/lib/modl/parser/parsed.rb +31 -29
- data/lib/modl/parser/parser.rb +3 -3
- data/lib/modl/parser/ref_processor.rb +3 -3
- data/lib/modl/parser/substitutions.rb +1 -1
- data/lib/modl/parser/throwing_error_listener.rb +1 -1
- data/lib/modl/parser/version.rb +2 -2
- data/modl.gemspec +15 -16
- metadata +18 -18
- /data/lib/{modl/interpreter.rb → modl.rb} +0 -0
@@ -1,11 +1,11 @@
|
|
1
|
-
module
|
1
|
+
module MODL
|
2
2
|
module Parser
|
3
3
|
# This class handles the conversion of objects that refer to classes into instances of those classes.
|
4
4
|
# It works recursively since class usage can be nested.
|
5
5
|
class ClassProcessor
|
6
6
|
# How deep can the class structure be?
|
7
7
|
MAX_RECURSION_DEPTH = 20
|
8
|
-
# global is a GlobalParseContext and obj is the extracted Array or Hash from
|
8
|
+
# global is a GlobalParseContext and obj is the extracted Array or Hash from MODL::Parser::Parsed.extract_json
|
9
9
|
def self.process(global, obj)
|
10
10
|
# Process each object in the array or just process the object if its a hash.
|
11
11
|
# Any other object is ignored.
|
@@ -1,10 +1,10 @@
|
|
1
|
-
module
|
1
|
+
module MODL
|
2
2
|
module Parser
|
3
3
|
# Evaluate a conditional expression
|
4
4
|
class Evaluator
|
5
5
|
# Evaluate the given condition
|
6
6
|
def self.evaluate(global, condition)
|
7
|
-
return false if global.nil? || !global.is_a?(GlobalParseContext) || !condition.is_a?(
|
7
|
+
return false if global.nil? || !global.is_a?(GlobalParseContext) || !condition.is_a?(MODL::Parser::Parsed::ParsedCondition)
|
8
8
|
|
9
9
|
start = 0
|
10
10
|
if condition.text
|
@@ -65,7 +65,7 @@ module Modl
|
|
65
65
|
def self.value(global, k)
|
66
66
|
success = false
|
67
67
|
if k.is_a?(String) && k.include?('%')
|
68
|
-
value1, _ignore =
|
68
|
+
value1, _ignore = MODL::Parser::RefProcessor.deref(k, global)
|
69
69
|
success = true
|
70
70
|
elsif k.is_a?(FalseClass)
|
71
71
|
value1 = false
|
@@ -96,7 +96,7 @@ module Modl
|
|
96
96
|
result = false
|
97
97
|
if @key
|
98
98
|
if @key.include?('%')
|
99
|
-
value1, _ignore =
|
99
|
+
value1, _ignore = MODL::Parser::RefProcessor.deref(@key, @global)
|
100
100
|
else
|
101
101
|
key = @key
|
102
102
|
ikey = key.to_i
|
@@ -113,7 +113,7 @@ module Modl
|
|
113
113
|
|
114
114
|
@values.each do |value|
|
115
115
|
value2 = value.text
|
116
|
-
value2, _ignore =
|
116
|
+
value2, _ignore = MODL::Parser::RefProcessor.deref(value2, @global) if value2.is_a?(String) && value2.include?('%')
|
117
117
|
value2 = @global.pair(value.text).text if @global.pair(value.text)
|
118
118
|
|
119
119
|
case @operator
|
@@ -1,11 +1,15 @@
|
|
1
|
+
require 'singleton'
|
1
2
|
require 'modl/parser/object_cache'
|
2
3
|
require 'modl/parser/sutil'
|
3
4
|
|
4
|
-
module
|
5
|
+
module MODL
|
5
6
|
module Parser
|
6
7
|
|
7
8
|
# This class handled file loading from local or remote file systems.
|
8
9
|
class FileImporter
|
10
|
+
include Singleton
|
11
|
+
|
12
|
+
CACHE_DISABLED = true
|
9
13
|
|
10
14
|
def initialize
|
11
15
|
@cache = ObjectCache.new
|
@@ -19,10 +23,12 @@ module Modl
|
|
19
23
|
|
20
24
|
file_names.each do |file_name|
|
21
25
|
force = file_name.end_with?('!')
|
26
|
+
file_name = Sutil.head(file_name) if force
|
27
|
+
file_name << '.modl' unless file_name.end_with?('.txt', '.modl')
|
28
|
+
file_name, new_val = RefProcessor.deref file_name, global if file_name.include?('%')
|
22
29
|
if force
|
23
30
|
# Don't use the cache if we're forcing a reload.
|
24
31
|
@cache.evict(file_name)
|
25
|
-
file_name = Sutil.head(file_name)
|
26
32
|
parsed = nil
|
27
33
|
else
|
28
34
|
# Do we have a cached version?
|
@@ -30,10 +36,8 @@ module Modl
|
|
30
36
|
end
|
31
37
|
|
32
38
|
# Did we hit the cache?
|
33
|
-
|
39
|
+
if (parsed.nil? && CACHE_DISABLED) || (CACHE_DISABLED)
|
34
40
|
# No.
|
35
|
-
file_name << '.modl' unless file_name.end_with?('.txt', '.modl')
|
36
|
-
file_name, new_val = RefProcessor.deref file_name, global if file_name.include?('%')
|
37
41
|
|
38
42
|
begin
|
39
43
|
uri = URI(file_name)
|
@@ -49,9 +53,9 @@ module Modl
|
|
49
53
|
global.loaded_file(file_name)
|
50
54
|
|
51
55
|
# Parse the downloaded file ands extract the classes
|
52
|
-
parsed =
|
56
|
+
parsed = MODL::Parser::Parser.parse txt, global
|
53
57
|
# Save it for next time
|
54
|
-
@cache.put(file_name, parsed)
|
58
|
+
@cache.put(file_name, parsed) unless CACHE_DISABLED
|
55
59
|
end
|
56
60
|
# Extract the JSON content and add the classes and pairs to the existing GlobalParseContext hashes.
|
57
61
|
parsed.extract_hash
|
@@ -1,8 +1,8 @@
|
|
1
|
-
module
|
1
|
+
module MODL
|
2
2
|
module Parser
|
3
3
|
# Each time we run the parser on a MODL file we need to keep track of a few things so they can be made available
|
4
4
|
# to other areas of the code. This class is the container for that contextual information, which is gathered
|
5
|
-
# as the
|
5
|
+
# as the MODL::Parser:Parsed object processes the parse tree.
|
6
6
|
class GlobalParseContext
|
7
7
|
|
8
8
|
attr_accessor :syntax_version
|
@@ -183,7 +183,11 @@ module Modl
|
|
183
183
|
end
|
184
184
|
|
185
185
|
def all_pairs
|
186
|
-
|
186
|
+
result = {}
|
187
|
+
@pairs.keys.each do |k|
|
188
|
+
result[k] = @pairs[k] unless k.start_with?('*')
|
189
|
+
end
|
190
|
+
result
|
187
191
|
end
|
188
192
|
|
189
193
|
private
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module MODL
|
2
2
|
module Parser
|
3
3
|
# This class handles the conversion of objects that refer to classes into instances of those classes.
|
4
4
|
# It works recursively since class usage can be nested.
|
@@ -51,6 +51,8 @@ module Modl
|
|
51
51
|
return global.transform_list
|
52
52
|
when '%*allow'
|
53
53
|
return global.allow_list
|
54
|
+
when '%*expect'
|
55
|
+
return global.allow_list
|
54
56
|
end
|
55
57
|
end
|
56
58
|
end
|
@@ -6,7 +6,7 @@ require 'modl/parser/class_processor'
|
|
6
6
|
require 'modl/parser/parser'
|
7
7
|
require 'json'
|
8
8
|
|
9
|
-
module
|
9
|
+
module MODL
|
10
10
|
# Interpreter-specific errors
|
11
11
|
class InterpreterError < StandardError
|
12
12
|
end
|
@@ -15,15 +15,15 @@ module Modl
|
|
15
15
|
# containing the JSON equivalent. The JSON isn't pretty-printed unless pretty is true
|
16
16
|
class Interpreter
|
17
17
|
def self.interpret(str, pretty = false)
|
18
|
-
# Parse the MODL string into a
|
19
|
-
parsed =
|
18
|
+
# Parse the MODL string into a MODL::Parser::Parsed object.
|
19
|
+
parsed = MODL::Parser::Parser.parse str
|
20
20
|
|
21
21
|
# Convert the Parsed object into a simpler structure of and Array or Hash
|
22
22
|
interpreted = parsed.extract_hash
|
23
23
|
|
24
24
|
# Process any class definitions used by the MODL file.
|
25
|
-
|
26
|
-
|
25
|
+
MODL::Parser::ClassProcessor.process(parsed.global, interpreted)
|
26
|
+
MODL::Parser::InstructionProcessor.process(parsed.global, interpreted)
|
27
27
|
# If the result is a simple string then just return it.
|
28
28
|
return interpreted if interpreted.is_a? String
|
29
29
|
|
@@ -35,4 +35,19 @@ module Modl
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
38
|
+
|
39
|
+
# Parse a MODL string and return a hash, array, or String depending on how the MODL is structured.
|
40
|
+
def self.parse(string)
|
41
|
+
# Parse the MODL string into a MODL::Parser::Parsed object.
|
42
|
+
parsed = MODL::Parser::Parser.parse(string)
|
43
|
+
|
44
|
+
# Convert the Parsed object into a simpler structure of and Array or Hash
|
45
|
+
interpreted = parsed.extract_hash
|
46
|
+
|
47
|
+
# Process any class definitions used by the MODL file.
|
48
|
+
MODL::Parser::ClassProcessor.process(parsed.global, interpreted)
|
49
|
+
MODL::Parser::InstructionProcessor.process(parsed.global, interpreted)
|
50
|
+
# If the result is a simple string then just return it.
|
51
|
+
interpreted
|
52
|
+
end
|
38
53
|
end
|
data/lib/modl/parser/parsed.rb
CHANGED
@@ -13,14 +13,14 @@ require 'modl/parser/evaluator'
|
|
13
13
|
require 'cgi'
|
14
14
|
require 'net/http'
|
15
15
|
|
16
|
-
module
|
16
|
+
module MODL
|
17
17
|
module Parser
|
18
18
|
# This class represents a MODL parse tree for a given MODL object.
|
19
19
|
# It tries to process the parse tree as it is generated as much as
|
20
20
|
# possible to save revisiting nodes unnecessarily.
|
21
21
|
#
|
22
22
|
# Many of the method names are generated by ANTLR4 so are not ruby style.
|
23
|
-
class Parsed <
|
23
|
+
class Parsed < MODL::Parser::MODLParserBaseListener
|
24
24
|
attr_accessor :structures
|
25
25
|
attr_accessor :global
|
26
26
|
|
@@ -54,7 +54,7 @@ module Modl
|
|
54
54
|
end
|
55
55
|
|
56
56
|
# Class to represent a parsed grammar object
|
57
|
-
class ParsedMap <
|
57
|
+
class ParsedMap < MODL::Parser::MODLParserBaseListener
|
58
58
|
attr_accessor :mapItems
|
59
59
|
|
60
60
|
def initialize(global)
|
@@ -99,7 +99,7 @@ module Modl
|
|
99
99
|
end
|
100
100
|
|
101
101
|
# Class to represent a parsed grammar object
|
102
|
-
class ParsedMapItem <
|
102
|
+
class ParsedMapItem < MODL::Parser::MODLParserBaseListener
|
103
103
|
attr_accessor :pair
|
104
104
|
attr_accessor :mapConditional
|
105
105
|
|
@@ -128,7 +128,7 @@ module Modl
|
|
128
128
|
end
|
129
129
|
|
130
130
|
# Class to represent a parsed grammar object
|
131
|
-
class ParsedStructure <
|
131
|
+
class ParsedStructure < MODL::Parser::MODLParserBaseListener
|
132
132
|
attr_accessor :array
|
133
133
|
attr_accessor :pair
|
134
134
|
attr_accessor :top_level_conditional
|
@@ -168,7 +168,7 @@ module Modl
|
|
168
168
|
end
|
169
169
|
|
170
170
|
# Class to represent a parsed grammar object
|
171
|
-
class ParsedPair <
|
171
|
+
class ParsedPair < MODL::Parser::MODLParserBaseListener
|
172
172
|
attr_accessor :key
|
173
173
|
attr_accessor :map
|
174
174
|
attr_accessor :array
|
@@ -182,7 +182,7 @@ module Modl
|
|
182
182
|
@global = global
|
183
183
|
@needs_defref = true
|
184
184
|
@final = false
|
185
|
-
@file_importer = FileImporter.
|
185
|
+
@file_importer = FileImporter.instance
|
186
186
|
end
|
187
187
|
|
188
188
|
def find_property(key)
|
@@ -259,6 +259,7 @@ module Modl
|
|
259
259
|
return if @type == 'method'
|
260
260
|
return if @type == 'import'
|
261
261
|
return if @type == 'allow'
|
262
|
+
return if @type == 'expect'
|
262
263
|
|
263
264
|
{@key => @text}
|
264
265
|
end
|
@@ -443,11 +444,12 @@ module Modl
|
|
443
444
|
@type = 'index' if @key == '?'
|
444
445
|
@type = 'hidden' if @key.start_with? '_'
|
445
446
|
@type = 'allow' if @key.downcase == '*allow'
|
447
|
+
@type = 'expect' if @key.downcase == '*expect'
|
446
448
|
end
|
447
449
|
end
|
448
450
|
|
449
451
|
# Class to represent a parsed grammar object
|
450
|
-
class ParsedArrayValueItem <
|
452
|
+
class ParsedArrayValueItem < MODL::Parser::MODLParserBaseListener
|
451
453
|
attr_accessor :map
|
452
454
|
attr_accessor :array
|
453
455
|
attr_accessor :pair
|
@@ -503,7 +505,7 @@ module Modl
|
|
503
505
|
end
|
504
506
|
|
505
507
|
# Class to represent a parsed grammar object
|
506
|
-
class ParsedValueItem <
|
508
|
+
class ParsedValueItem < MODL::Parser::MODLParserBaseListener
|
507
509
|
attr_accessor :value
|
508
510
|
attr_accessor :valueConditional
|
509
511
|
|
@@ -535,7 +537,7 @@ module Modl
|
|
535
537
|
end
|
536
538
|
|
537
539
|
# Class to represent a parsed grammar object
|
538
|
-
class ParsedValue <
|
540
|
+
class ParsedValue < MODL::Parser::MODLParserBaseListener
|
539
541
|
attr_accessor :map
|
540
542
|
attr_accessor :array
|
541
543
|
attr_accessor :nbArray
|
@@ -608,7 +610,7 @@ module Modl
|
|
608
610
|
end
|
609
611
|
|
610
612
|
# Class to represent a parsed grammar object
|
611
|
-
class ParsedPrimitive <
|
613
|
+
class ParsedPrimitive < MODL::Parser::MODLParserBaseListener
|
612
614
|
attr_accessor :quoted
|
613
615
|
attr_accessor :number
|
614
616
|
attr_accessor :trueVal
|
@@ -729,7 +731,7 @@ module Modl
|
|
729
731
|
end
|
730
732
|
|
731
733
|
# Class to represent a parsed grammar object
|
732
|
-
class ParsedConditionTest <
|
734
|
+
class ParsedConditionTest < MODL::Parser::MODLParserBaseListener
|
733
735
|
attr_accessor :subConditionList
|
734
736
|
|
735
737
|
def initialize(global)
|
@@ -806,7 +808,7 @@ module Modl
|
|
806
808
|
end
|
807
809
|
|
808
810
|
# Class to represent a parsed grammar object
|
809
|
-
class ParsedConditionGroup <
|
811
|
+
class ParsedConditionGroup < MODL::Parser::MODLParserBaseListener
|
810
812
|
attr_accessor :conditionsTestList
|
811
813
|
|
812
814
|
def initialize(global)
|
@@ -845,7 +847,7 @@ module Modl
|
|
845
847
|
end
|
846
848
|
|
847
849
|
# Class to represent a parsed grammar object
|
848
|
-
class ParsedCondition <
|
850
|
+
class ParsedCondition < MODL::Parser::MODLParserBaseListener
|
849
851
|
attr_accessor :values
|
850
852
|
attr_accessor :operator
|
851
853
|
attr_accessor :text
|
@@ -878,7 +880,7 @@ module Modl
|
|
878
880
|
end
|
879
881
|
|
880
882
|
# Class to represent a parsed grammar object
|
881
|
-
class ParsedMapConditionalReturn <
|
883
|
+
class ParsedMapConditionalReturn < MODL::Parser::MODLParserBaseListener
|
882
884
|
attr_accessor :mapItems
|
883
885
|
|
884
886
|
def initialize(global)
|
@@ -903,7 +905,7 @@ module Modl
|
|
903
905
|
end
|
904
906
|
|
905
907
|
# Class to represent a parsed grammar object
|
906
|
-
class ParsedMapConditional <
|
908
|
+
class ParsedMapConditional < MODL::Parser::MODLParserBaseListener
|
907
909
|
attr_accessor :conditionTests
|
908
910
|
attr_accessor :mapConditionalReturns
|
909
911
|
|
@@ -917,7 +919,7 @@ module Modl
|
|
917
919
|
result = @conditionTests[0].evaluate
|
918
920
|
return @mapConditionalReturns[0].extract_hash if result
|
919
921
|
|
920
|
-
@mapConditionalReturns[1].extract_hash
|
922
|
+
@mapConditionalReturns[1].extract_hash if @mapConditionalReturns.length > 1
|
921
923
|
end
|
922
924
|
|
923
925
|
def enterModl_map_conditional(ctx)
|
@@ -946,7 +948,7 @@ module Modl
|
|
946
948
|
end
|
947
949
|
|
948
950
|
# Class to represent a parsed grammar object
|
949
|
-
class ParsedTopLevelConditionalReturn <
|
951
|
+
class ParsedTopLevelConditionalReturn < MODL::Parser::MODLParserBaseListener
|
950
952
|
attr_accessor :structures
|
951
953
|
|
952
954
|
def initialize(global)
|
@@ -979,7 +981,7 @@ module Modl
|
|
979
981
|
end
|
980
982
|
|
981
983
|
# Class to represent a parsed grammar object
|
982
|
-
class ParsedTopLevelConditional <
|
984
|
+
class ParsedTopLevelConditional < MODL::Parser::MODLParserBaseListener
|
983
985
|
attr_accessor :conditionTests
|
984
986
|
attr_accessor :topLevelConditionalReturns
|
985
987
|
|
@@ -1038,7 +1040,7 @@ module Modl
|
|
1038
1040
|
end
|
1039
1041
|
|
1040
1042
|
# Class to represent a parsed grammar object
|
1041
|
-
class ParsedArrayConditionalReturn <
|
1043
|
+
class ParsedArrayConditionalReturn < MODL::Parser::MODLParserBaseListener
|
1042
1044
|
attr_accessor :arrayItems
|
1043
1045
|
|
1044
1046
|
def initialize(global)
|
@@ -1063,7 +1065,7 @@ module Modl
|
|
1063
1065
|
end
|
1064
1066
|
|
1065
1067
|
# Class to represent a parsed grammar object
|
1066
|
-
class ParsedArrayConditional <
|
1068
|
+
class ParsedArrayConditional < MODL::Parser::MODLParserBaseListener
|
1067
1069
|
attr_accessor :conditionTest
|
1068
1070
|
attr_accessor :arrayConditionalReturns
|
1069
1071
|
|
@@ -1109,7 +1111,7 @@ module Modl
|
|
1109
1111
|
end
|
1110
1112
|
|
1111
1113
|
# Class to represent a parsed grammar object
|
1112
|
-
class ParsedValueConditionalReturn <
|
1114
|
+
class ParsedValueConditionalReturn < MODL::Parser::MODLParserBaseListener
|
1113
1115
|
attr_accessor :valueItems
|
1114
1116
|
|
1115
1117
|
def initialize(global)
|
@@ -1136,7 +1138,7 @@ module Modl
|
|
1136
1138
|
end
|
1137
1139
|
|
1138
1140
|
# Class to represent a parsed grammar object
|
1139
|
-
class ParsedValueConditional <
|
1141
|
+
class ParsedValueConditional < MODL::Parser::MODLParserBaseListener
|
1140
1142
|
attr_accessor :conditionTests
|
1141
1143
|
attr_accessor :valueConditionalReturns
|
1142
1144
|
|
@@ -1187,7 +1189,7 @@ module Modl
|
|
1187
1189
|
end
|
1188
1190
|
|
1189
1191
|
# Class to represent a parsed grammar object
|
1190
|
-
class ParsedNbArray <
|
1192
|
+
class ParsedNbArray < MODL::Parser::MODLParserBaseListener
|
1191
1193
|
attr_accessor :arrayItems
|
1192
1194
|
|
1193
1195
|
def initialize(global)
|
@@ -1260,7 +1262,7 @@ module Modl
|
|
1260
1262
|
end
|
1261
1263
|
|
1262
1264
|
# Class to represent a parsed grammar object
|
1263
|
-
class ParsedArray <
|
1265
|
+
class ParsedArray < MODL::Parser::MODLParserBaseListener
|
1264
1266
|
# We now have a list of < array_item | nb_array >
|
1265
1267
|
attr_accessor :abstractArrayItems
|
1266
1268
|
|
@@ -1339,7 +1341,7 @@ module Modl
|
|
1339
1341
|
end
|
1340
1342
|
|
1341
1343
|
# Class to represent a parsed grammar object
|
1342
|
-
class ParsedArrayItem <
|
1344
|
+
class ParsedArrayItem < MODL::Parser::MODLParserBaseListener
|
1343
1345
|
attr_accessor :arrayValueItem
|
1344
1346
|
attr_accessor :arrayConditional
|
1345
1347
|
|
@@ -1372,17 +1374,17 @@ module Modl
|
|
1372
1374
|
end
|
1373
1375
|
|
1374
1376
|
# Singleton class to represent a true value
|
1375
|
-
class ParsedTrue <
|
1377
|
+
class ParsedTrue < MODL::Parser::MODLParserBaseListener
|
1376
1378
|
include Singleton
|
1377
1379
|
end
|
1378
1380
|
|
1379
1381
|
# Singleton class to represent a false value
|
1380
|
-
class ParsedFalse <
|
1382
|
+
class ParsedFalse < MODL::Parser::MODLParserBaseListener
|
1381
1383
|
include Singleton
|
1382
1384
|
end
|
1383
1385
|
|
1384
1386
|
# Singleton class to represent a null value
|
1385
|
-
class ParsedNull <
|
1387
|
+
class ParsedNull < MODL::Parser::MODLParserBaseListener
|
1386
1388
|
include Singleton
|
1387
1389
|
end
|
1388
1390
|
|
data/lib/modl/parser/parser.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
require 'modl/parser/throwing_error_listener'
|
2
2
|
require 'modl/parser/parsed'
|
3
3
|
|
4
|
-
module
|
4
|
+
module MODL
|
5
5
|
module Parser
|
6
6
|
|
7
7
|
# This class converts the input string into a Modl:Parser::Parsed object for further processing.
|
8
8
|
class Parser
|
9
9
|
def self.parse(str, global = nil)
|
10
10
|
begin
|
11
|
-
lexer =
|
11
|
+
lexer = MODL::Parser::MODLLexer.new(Antlr4::Runtime::CharStreams.from_string(str, 'String'))
|
12
12
|
lexer.remove_error_listeners
|
13
13
|
lexer.add_error_listener ThrowingErrorListener.instance
|
14
14
|
|
15
15
|
tokens = Antlr4::Runtime::CommonTokenStream.new(lexer)
|
16
16
|
|
17
|
-
parser =
|
17
|
+
parser = MODL::Parser::MODLParser.new(tokens)
|
18
18
|
parser.remove_error_listeners
|
19
19
|
parser.add_error_listener ThrowingErrorListener.instance
|
20
20
|
|
@@ -4,7 +4,7 @@ require 'modl/parser/parsed'
|
|
4
4
|
require 'punycode'
|
5
5
|
require 'modl/parser/sutil'
|
6
6
|
|
7
|
-
module
|
7
|
+
module MODL
|
8
8
|
module Parser
|
9
9
|
# Convert MODL reference to the replacement value
|
10
10
|
class RefProcessor
|
@@ -59,7 +59,7 @@ module Modl
|
|
59
59
|
str.sub(ref, nv_text.to_s)
|
60
60
|
end
|
61
61
|
new_value = nil
|
62
|
-
elsif new_value.is_a?(
|
62
|
+
elsif new_value.is_a?(MODL::Parser::MODLParserBaseListener)
|
63
63
|
if new_value.text
|
64
64
|
str = if ref == str
|
65
65
|
new_value.text
|
@@ -92,7 +92,7 @@ module Modl
|
|
92
92
|
parts.each do |p|
|
93
93
|
if p.include?('%')
|
94
94
|
p, _ignore = expand(global, p)
|
95
|
-
if p.is_a?(
|
95
|
+
if p.is_a?(MODL::Parser::MODLParserBaseListener)
|
96
96
|
p = p.text
|
97
97
|
end
|
98
98
|
end
|
data/lib/modl/parser/version.rb
CHANGED
data/modl.gemspec
CHANGED
@@ -1,32 +1,31 @@
|
|
1
1
|
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require 'modl/parser/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
-
spec.version =
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
7
|
+
spec.name = 'modl'
|
8
|
+
spec.version = MODL::Parser::VERSION
|
9
|
+
spec.authors = ['Tony Walmsley']
|
10
|
+
spec.email = ['tony@aosd.co.uk']
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
12
|
+
spec.summary = 'The ANTLR4 Lexer and Parser for MODL generated using the Ruby language target.'
|
13
|
+
spec.description = 'Contains the base Lexer, Parser, and supporting classes for a MODL parser.'
|
14
|
+
spec.homepage = 'https://github.com/MODLanguage/ruby-interpreter'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
17
|
# Specify which files should be added to the gem when it is released.
|
18
18
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
19
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
20
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
21
|
end
|
22
|
-
spec.bindir =
|
22
|
+
spec.bindir = 'exe'
|
23
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
-
spec.require_paths = [
|
24
|
+
spec.require_paths = ['lib']
|
25
25
|
|
26
|
-
#spec.add_development_dependency "bundler", "~> 2.0"
|
27
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
29
26
|
spec.add_development_dependency 'antlr4-runtime', '>= 0.0.1'
|
30
|
-
spec.
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
spec.add_runtime_dependency 'antlr4-runtime', '= 0.2.1'
|
31
30
|
spec.add_runtime_dependency 'punycode4r', '>= 0.2.0'
|
32
31
|
end
|