Skip to content

Commit e8ffa8e

Browse files
authored
Merge pull request #780 from interscript/feat/parsanol-grammar
feat: parse ISC with parsanol natively
2 parents 7cc476d + 4a81525 commit e8ffa8e

17 files changed

Lines changed: 51 additions & 40 deletions

‎interscript.gemspec‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ Gem::Specification.new do |spec|
3535
spec.add_dependency "thor"
3636
spec.add_dependency "interscript-maps", "~> #{Interscript::VERSION.split(".")[0, 2].join(".")}.0a"
3737
spec.add_dependency "text"
38-
spec.add_dependency "parslet", "~> 2.0"
38+
spec.add_dependency "parsanol", "~> 1.3"
3939
end

‎lib/interscript/compiler.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Interscript::Compiler
1010

1111
def self.call(map, **kwargs)
1212
# DSL.parse locates, dispatches .isc and caches the parsed document —
13-
# calling parse_isc here re-ran a ~30 s Parslet parse on every
13+
# calling parse_isc here re-ran a full grammar parse on every
1414
# compiler instantiation.
1515
map = Interscript::DSL.parse(map) if String === map
1616
compiler = new

‎lib/interscript/dsl.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def self.parse(map_name, reverse: true)
4040
end
4141
end
4242
# ISC documents route through the ISC parser, not the .imp DSL.
43-
# The parse is expensive (Parslet over the whole map) — cache it like
43+
# The parse is expensive (the whole grammar over the map) — cache it like
4444
# the .imp path does, or every transliterate call re-parses the map.
4545
return @cache[map_name] = Interscript::Compiler.parse_isc(path) if path.end_with?(".isc")
4646

‎lib/interscript/isc.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require "parslet"
3+
require "parsanol"
44

55
module Interscript
66
module Isc

‎lib/interscript/isc/document_builder.rb‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ def build
7171
def unquote(fragment)
7272
return "" if fragment.nil?
7373
return fragment.to_s unless fragment.is_a?(Hash)
74-
return fragment.to_s unless fragment.key?(:string)
74+
# Direct decode for the overwhelmingly common shape — routing
75+
# every quoted string through Transform pattern matching
76+
# dominated large-map builds.
77+
return Transform.decode_string_parts(fragment[:string]) if fragment.key?(:string)
7578

76-
out = @transform.apply(fragment)
77-
out.is_a?(Items::StringValue) ? out.value : out.to_s
79+
fragment.to_s
7880
end
7981

8082
def unescape_braces(text)
@@ -325,17 +327,19 @@ def extract_dependency(item)
325327
}.compact
326328
end
327329

328-
# Convert a parslet tree fragment into a concrete Item object via Transform.
330+
# Convert a grammar tree fragment into a concrete Item object via
331+
# Transform. Reuses the builder's Transform instance — allocating
332+
# one per fragment dominated large-map builds.
329333
def materialize(fragment)
330334
case fragment
331335
when Hash
332336
if fragment.key?(:concatenation)
333-
Transform.new.apply(fragment)
337+
@transform.apply(fragment)
334338
else
335-
Transform.new.apply(concatenation: [fragment])
339+
@transform.apply(concatenation: [fragment])
336340
end
337341
when Array
338-
Transform.new.apply(concatenation: fragment)
342+
@transform.apply(concatenation: fragment)
339343
when NilClass
340344
Items::None.new
341345
else

‎lib/interscript/isc/grammar.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require "parslet"
3+
require "parsanol"
44

55
module Interscript
66
module Isc

‎lib/interscript/isc/grammar/concerns/aliases.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# frozen_string_literal: true
22

3-
require "parslet"
3+
require "parsanol"
44

55
module Interscript
66
module Isc
77
module Grammar
88
module Concerns
99
# Aliases block: named expressions reused throughout the system.
1010
module Aliases
11-
include Parslet
11+
include Parsanol
1212

1313
rule(:aliases_block) do
1414
str("aliases") >> whitespace? >>

‎lib/interscript/isc/grammar/concerns/dependencies.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# frozen_string_literal: true
22

3-
require "parslet"
3+
require "parsanol"
44

55
module Interscript
66
module Isc
77
module Grammar
88
module Concerns
99
# Dependencies: references to other systems whose stages may be invoked.
1010
module Dependencies
11-
include Parslet
11+
include Parsanol
1212

1313
rule(:dependency_decl) do
1414
str("dependency") >> whitespace >>

‎lib/interscript/isc/grammar/concerns/items.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# frozen_string_literal: true
22

3-
require "parslet"
3+
require "parsanol"
44

55
module Interscript
66
module Isc
77
module Grammar
88
module Concerns
99
# Item expressions: the building blocks of rule matches and targets.
1010
module Items
11-
include Parslet
11+
include Parsanol
1212

1313
rule(:item_atom) do
1414
quoted_string |

‎lib/interscript/isc/grammar/concerns/metadata.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# frozen_string_literal: true
22

3-
require "parslet"
3+
require "parsanol"
44

55
module Interscript
66
module Isc
77
module Grammar
88
module Concerns
99
# Metadata block: identity + provenance + lifecycle of a system.
1010
module Metadata
11-
include Parslet
11+
include Parsanol
1212

1313
rule(:metadata_block) do
1414
str("metadata") >> whitespace? >>

0 commit comments

Comments
 (0)