fmt 0.1.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +167 -93
- data/lib/fmt/boot.rb +50 -0
- data/lib/fmt/lru_cache.rb +181 -0
- data/lib/fmt/mixins/matchable.rb +26 -0
- data/lib/fmt/models/arguments.rb +194 -0
- data/lib/fmt/models/embed.rb +48 -0
- data/lib/fmt/models/macro.rb +58 -0
- data/lib/fmt/models/model.rb +66 -0
- data/lib/fmt/models/pipeline.rb +47 -0
- data/lib/fmt/models/template.rb +55 -0
- data/lib/fmt/node.rb +128 -0
- data/lib/fmt/parsers/arguments_parser.rb +43 -0
- data/lib/fmt/parsers/embed_parser.rb +54 -0
- data/lib/fmt/parsers/macro_parser.rb +113 -0
- data/lib/fmt/parsers/parser.rb +56 -0
- data/lib/fmt/parsers/pipeline_parser.rb +41 -0
- data/lib/fmt/parsers/template_parser.rb +125 -0
- data/lib/fmt/refinements/kernel_refinement.rb +38 -0
- data/lib/fmt/registries/native_registry.rb +66 -0
- data/lib/fmt/registries/rainbow_registry.rb +36 -0
- data/lib/fmt/registries/registry.rb +127 -0
- data/lib/fmt/renderer.rb +132 -0
- data/lib/fmt/sigils.rb +23 -0
- data/lib/fmt/token.rb +126 -0
- data/lib/fmt/tokenizer.rb +96 -0
- data/lib/fmt/version.rb +3 -1
- data/lib/fmt.rb +50 -12
- data/sig/generated/fmt/boot.rbs +2 -0
- data/sig/generated/fmt/lru_cache.rbs +122 -0
- data/sig/generated/fmt/mixins/matchable.rbs +18 -0
- data/sig/generated/fmt/models/arguments.rbs +115 -0
- data/sig/generated/fmt/models/embed.rbs +34 -0
- data/sig/generated/fmt/models/macro.rbs +37 -0
- data/sig/generated/fmt/models/model.rbs +45 -0
- data/sig/generated/fmt/models/pipeline.rbs +31 -0
- data/sig/generated/fmt/models/template.rbs +33 -0
- data/sig/generated/fmt/node.rbs +64 -0
- data/sig/generated/fmt/parsers/arguments_parser.rbs +25 -0
- data/sig/generated/fmt/parsers/embed_parser.rbs +36 -0
- data/sig/generated/fmt/parsers/macro_parser.rbs +60 -0
- data/sig/generated/fmt/parsers/parser.rbs +44 -0
- data/sig/generated/fmt/parsers/pipeline_parser.rbs +25 -0
- data/sig/generated/fmt/parsers/template_parser.rbs +50 -0
- data/sig/generated/fmt/refinements/kernel_refinement.rbs +23 -0
- data/sig/generated/fmt/registries/native_registry.rbs +19 -0
- data/sig/generated/fmt/registries/rainbow_registry.rbs +11 -0
- data/sig/generated/fmt/registries/registry.rbs +69 -0
- data/sig/generated/fmt/renderer.rbs +70 -0
- data/sig/generated/fmt/sigils.rbs +30 -0
- data/sig/generated/fmt/token.rbs +77 -0
- data/sig/generated/fmt/tokenizer.rbs +51 -0
- data/sig/generated/fmt/version.rbs +5 -0
- data/sig/generated/fmt.rbs +41 -0
- metadata +126 -18
- data/lib/fmt/embed.rb +0 -19
- data/lib/fmt/filter.rb +0 -32
- data/lib/fmt/filter_groups/filter_group.rb +0 -56
- data/lib/fmt/filter_groups/rainbow_filter_group.rb +0 -27
- data/lib/fmt/filter_groups/string_filter_group.rb +0 -28
- data/lib/fmt/formatter.rb +0 -60
- data/lib/fmt/scanners/base_scanner.rb +0 -41
- data/lib/fmt/scanners/embed_scanner.rb +0 -56
- data/lib/fmt/scanners/filter_scanner.rb +0 -31
- data/lib/fmt/scanners/key_scanner.rb +0 -15
- data/lib/fmt/scanners.rb +0 -3
- data/lib/fmt/transformer.rb +0 -57
@@ -0,0 +1,115 @@
|
|
1
|
+
# Generated from lib/fmt/models/arguments.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Fmt
|
4
|
+
# Represents arguments for a method call
|
5
|
+
#
|
6
|
+
# Arguments are comprised of:
|
7
|
+
# 1. args: Array[Object]
|
8
|
+
# 2. kwargs: Hash[Symbol, Object]
|
9
|
+
class Arguments < Model
|
10
|
+
# Constructor
|
11
|
+
# @rbs ast: Node
|
12
|
+
def initialize: (Node ast) -> untyped
|
13
|
+
|
14
|
+
attr_reader args: untyped
|
15
|
+
|
16
|
+
attr_reader kwargs: untyped
|
17
|
+
|
18
|
+
# Hash representation of the model (required for pattern matching)
|
19
|
+
# @rbs return: Hash[Symbol, Object]
|
20
|
+
def to_h: () -> Hash[Symbol, Object]
|
21
|
+
|
22
|
+
# Processes an arguments AST node
|
23
|
+
# @rbs node: Node
|
24
|
+
# @rbs return: void
|
25
|
+
def on_arguments: (Node node) -> void
|
26
|
+
|
27
|
+
# Processes a tokens AST node
|
28
|
+
# @rbs node: Node
|
29
|
+
# @rbs return: void
|
30
|
+
def on_tokens: (Node node) -> void
|
31
|
+
|
32
|
+
# Processes a keyword AST node
|
33
|
+
# @rbs node: Node
|
34
|
+
# @rbs return: nil | true | false | Object
|
35
|
+
def on_kw: (Node node) -> (nil | true | false | Object)
|
36
|
+
|
37
|
+
# Processes a string AST node
|
38
|
+
# @rbs node: Node
|
39
|
+
# @rbs return: String
|
40
|
+
def on_tstring_content: (Node node) -> String
|
41
|
+
|
42
|
+
# Processes a symbol AST Node
|
43
|
+
# @rbs node: Node
|
44
|
+
# @rbs return: Symbol
|
45
|
+
def on_symbol: (Node node) -> Symbol
|
46
|
+
|
47
|
+
# Processes a symbol start AST Node
|
48
|
+
# @rbs node: Node
|
49
|
+
# @rbs return: void
|
50
|
+
def on_symbeg: (Node node) -> void
|
51
|
+
|
52
|
+
# Processes an identifier AST Node
|
53
|
+
# @rbs node: Node
|
54
|
+
# @rbs return: Symbol?
|
55
|
+
def on_ident: (Node node) -> Symbol?
|
56
|
+
|
57
|
+
# Processes an integer AST node
|
58
|
+
# @rbs node: Node
|
59
|
+
# @rbs return: Integer
|
60
|
+
def on_int: (Node node) -> Integer
|
61
|
+
|
62
|
+
# Processes a float AST node
|
63
|
+
# @rbs node: Node
|
64
|
+
# @rbs return: Float
|
65
|
+
def on_float: (Node node) -> Float
|
66
|
+
|
67
|
+
# Processes a rational AST node
|
68
|
+
# @rbs node: Node
|
69
|
+
# @rbs return: Rational
|
70
|
+
def on_rational: (Node node) -> Rational
|
71
|
+
|
72
|
+
# Processes an imaginary (complex) AST node
|
73
|
+
# @rbs node: Node
|
74
|
+
# @rbs return: Complex
|
75
|
+
def on_imaginary: (Node node) -> Complex
|
76
|
+
|
77
|
+
# Processes a left bracket AST node
|
78
|
+
# @rbs node: Node
|
79
|
+
# @rbs return: Array
|
80
|
+
def on_lbracket: (Node node) -> Array
|
81
|
+
|
82
|
+
# Processes a left brace AST node
|
83
|
+
# @rbs node: Node
|
84
|
+
# @rbs return: Hash
|
85
|
+
def on_lbrace: (Node node) -> Hash
|
86
|
+
|
87
|
+
# Process a label (hash key) AST node
|
88
|
+
# @rbs node: Node
|
89
|
+
# @rbs return: void
|
90
|
+
def on_label: (Node node) -> void
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
# Assigns a value to the receiver
|
95
|
+
# @rbs value: Object -- value to assign
|
96
|
+
# @rbs label: Symbol? -- label to use (if applicable)
|
97
|
+
# @rbs return: Object
|
98
|
+
def assign: (Object value, ?label: Symbol?) -> Object
|
99
|
+
|
100
|
+
# Receiver that the processed value will be assigned to
|
101
|
+
# @rbs label: Symbol? -- label to use (if applicable)
|
102
|
+
# @rbs return: Array | Hash
|
103
|
+
def receiver: (?label: Symbol?) -> (Array | Hash)
|
104
|
+
|
105
|
+
# Finds the receiver that the processed value will be assigned to
|
106
|
+
# @rbs obj: Object
|
107
|
+
# @rbs return: Array? | Hash?
|
108
|
+
def find_receiver: (Object obj) -> (Array? | Hash?)
|
109
|
+
|
110
|
+
# Indicates if the value is a composite type (Array or Hash)
|
111
|
+
# @rbs value: Object -- value to check
|
112
|
+
# @rbs return: bool
|
113
|
+
def composite?: (Object value) -> bool
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Generated from lib/fmt/models/embed.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Fmt
|
4
|
+
class Embed < Model
|
5
|
+
attr_reader key: untyped
|
6
|
+
|
7
|
+
attr_reader placeholder: untyped
|
8
|
+
|
9
|
+
attr_reader template: untyped
|
10
|
+
|
11
|
+
# Hash representation of the model (required for pattern matching)
|
12
|
+
# @rbs return: Hash[Symbol, Object]
|
13
|
+
def to_h: () -> Hash[Symbol, Object]
|
14
|
+
|
15
|
+
# Processes an embed AST node
|
16
|
+
# @rbs node: Node
|
17
|
+
# @rbs return: void
|
18
|
+
def on_embed: (Node node) -> void
|
19
|
+
|
20
|
+
# Processes a key AST node
|
21
|
+
# @rbs node: Node
|
22
|
+
# @rbs return: void
|
23
|
+
def on_key: (Node node) -> void
|
24
|
+
|
25
|
+
# Processes a placeholder AST node
|
26
|
+
# @rbs node: Node
|
27
|
+
# @rbs return: void
|
28
|
+
def on_placeholder: (Node node) -> void
|
29
|
+
|
30
|
+
# Processes a template AST node
|
31
|
+
# @rbs node: Node
|
32
|
+
def on_template: (Node node) -> untyped
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Generated from lib/fmt/models/macro.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Fmt
|
4
|
+
# Represents an uninvoked method call
|
5
|
+
#
|
6
|
+
# A Macro is comprised of:
|
7
|
+
# 1. name: Symbol
|
8
|
+
# 2. arguments: Arguments
|
9
|
+
class Macro < Model
|
10
|
+
attr_reader name: untyped
|
11
|
+
|
12
|
+
attr_reader arguments: untyped
|
13
|
+
|
14
|
+
# Constructor
|
15
|
+
# @rbs ast: Node
|
16
|
+
def initialize: (Node ast) -> untyped
|
17
|
+
|
18
|
+
# Hash representation of the model (required for pattern matching)
|
19
|
+
# @rbs return: Hash[Symbol, Object]
|
20
|
+
def to_h: () -> Hash[Symbol, Object]
|
21
|
+
|
22
|
+
# Processes a macro AST node
|
23
|
+
# @rbs node: Node
|
24
|
+
# @rbs return: void
|
25
|
+
def on_macro: (Node node) -> void
|
26
|
+
|
27
|
+
# Processes a procedure AST node
|
28
|
+
# @rbs node: Node
|
29
|
+
# @rbs return: void
|
30
|
+
def on_name: (Node node) -> void
|
31
|
+
|
32
|
+
# Processes an arguments AST node
|
33
|
+
# @rbs node: Node
|
34
|
+
# @rbs return: void
|
35
|
+
def on_arguments: (Node node) -> void
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Generated from lib/fmt/models/model.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Fmt
|
4
|
+
# Superclass for all models
|
5
|
+
# @note Models are constructed from AST nodes
|
6
|
+
class Model
|
7
|
+
include AST::Processor::Mixin
|
8
|
+
|
9
|
+
include Matchable
|
10
|
+
|
11
|
+
# Constructor
|
12
|
+
# @rbs ast: Node
|
13
|
+
def initialize: (Node ast) -> untyped
|
14
|
+
|
15
|
+
attr_reader ast: untyped
|
16
|
+
|
17
|
+
attr_reader urtext: untyped
|
18
|
+
|
19
|
+
attr_reader source: untyped
|
20
|
+
|
21
|
+
# Model inspection
|
22
|
+
# @rbs return: String
|
23
|
+
def inspect: () -> String
|
24
|
+
|
25
|
+
# Indicates if a given AST node is the same AST used to construct the model
|
26
|
+
# @rbs node: Node
|
27
|
+
# @rbs return: bool
|
28
|
+
def self?: (Node node) -> bool
|
29
|
+
|
30
|
+
# Hash representation of the model (required for pattern matching)
|
31
|
+
# @note Subclasses should override this method and call: super.merge(**)
|
32
|
+
# @rbs return: Hash[Symbol, Object]
|
33
|
+
def to_h: () -> Hash[Symbol, Object]
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# Hash of instance variables for inspection
|
38
|
+
# @rbs return: Hash[String, Object]
|
39
|
+
def inspectable_properties: () -> Hash[String, Object]
|
40
|
+
|
41
|
+
# String of inspectable properties for inspection
|
42
|
+
# @rbs return: String
|
43
|
+
def inspect_properties: () -> String
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Generated from lib/fmt/models/pipeline.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Fmt
|
4
|
+
# Represents a series of Macros
|
5
|
+
#
|
6
|
+
# A Pipeline is comprised of:
|
7
|
+
# 1. macros: Array[Macro]
|
8
|
+
#
|
9
|
+
# @note Pipelines are processed in sequence (left to right)
|
10
|
+
class Pipeline < Model
|
11
|
+
# Constructor
|
12
|
+
# @rbs ast: Node
|
13
|
+
def initialize: (Node ast) -> untyped
|
14
|
+
|
15
|
+
attr_reader macros: untyped
|
16
|
+
|
17
|
+
# Hash representation of the model (required for pattern matching)
|
18
|
+
# @rbs return: Hash[Symbol, Object]
|
19
|
+
def to_h: () -> Hash[Symbol, Object]
|
20
|
+
|
21
|
+
# Processes a pipeline AST node
|
22
|
+
# @rbs node: Node
|
23
|
+
# @rbs return: void
|
24
|
+
def on_pipeline: (Node node) -> void
|
25
|
+
|
26
|
+
# Processes a macro AST node
|
27
|
+
# @rbs node: Node
|
28
|
+
# @rbs return: void
|
29
|
+
def on_macro: (Node node) -> void
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Generated from lib/fmt/models/template.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Fmt
|
4
|
+
# Represents a formattable string
|
5
|
+
#
|
6
|
+
# A Template is comprised of:
|
7
|
+
# 1. embeds: Array[Template] -- embedded templates
|
8
|
+
# 2. pipelines :: Array[Pipeline] -- sets of Macros
|
9
|
+
#
|
10
|
+
# @note Embeds are processed from inner to outer
|
11
|
+
class Template < Model
|
12
|
+
# Constructor
|
13
|
+
# @rbs ast: Node
|
14
|
+
def initialize: (Node ast) -> untyped
|
15
|
+
|
16
|
+
attr_reader embeds: untyped
|
17
|
+
|
18
|
+
attr_reader pipelines: untyped
|
19
|
+
|
20
|
+
# @rbs return: Hash[Symbol, Object]
|
21
|
+
def to_h: () -> Hash[Symbol, Object]
|
22
|
+
|
23
|
+
def on_template: (untyped node) -> untyped
|
24
|
+
|
25
|
+
def on_embeds: (untyped node) -> untyped
|
26
|
+
|
27
|
+
def on_embed: (untyped node) -> untyped
|
28
|
+
|
29
|
+
def on_pipelines: (untyped node) -> untyped
|
30
|
+
|
31
|
+
def on_pipeline: (untyped node) -> untyped
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Generated from lib/fmt/node.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Fmt
|
4
|
+
# Extends behavior of AST::Node
|
5
|
+
class Node < AST::Node
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
# Finds all Node child nodes
|
9
|
+
# @rbs node: Node -- node to search
|
10
|
+
# @rbs return: Array[Node]
|
11
|
+
def self.node_children: (Node node) -> Array[Node]
|
12
|
+
|
13
|
+
# Recursively finds all Nodes in the tree
|
14
|
+
# @rbs node: Node -- node to search
|
15
|
+
# @rbs return: Array[Node]
|
16
|
+
def self.node_descendants: (Node node) -> Array[Node]
|
17
|
+
|
18
|
+
# Constructor
|
19
|
+
# @rbs type: Symbol
|
20
|
+
# @rbs children: Array[Node]
|
21
|
+
# @rbs properties: Hash[Symbol, Object]
|
22
|
+
def initialize: (Symbol type, ?Array[Node] children, ?Hash[Symbol, Object] properties) -> untyped
|
23
|
+
|
24
|
+
attr_reader properties: untyped
|
25
|
+
|
26
|
+
# Recursively searches the tree for a descendant node
|
27
|
+
# @rbs types: Array[Object] -- node types to find
|
28
|
+
# @rbs return: Node?
|
29
|
+
def dig: (*untyped types) -> Node?
|
30
|
+
|
31
|
+
# Finds the first child node of the specified type
|
32
|
+
# @rbs type: Object -- node type to find
|
33
|
+
# @rbs return: Node?
|
34
|
+
def find: (Object type) -> Node?
|
35
|
+
|
36
|
+
# Flattens Node descendants into a one dimensional array
|
37
|
+
# @rbs return: Array[Node]
|
38
|
+
def flatten: () -> Array[Node]
|
39
|
+
|
40
|
+
# Finds all child nodes of the specified type
|
41
|
+
# @rbs type: Object -- node type to select
|
42
|
+
# @rbs return: Node?
|
43
|
+
def select: (Object type) -> Node?
|
44
|
+
|
45
|
+
# String representation of the node (AST)
|
46
|
+
# @rbs squish: bool -- remove extra whitespace
|
47
|
+
# @rbs return: String
|
48
|
+
def to_s: (?squish: bool) -> String
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
# Finds all Node child nodes
|
53
|
+
# @rbs return: Array[Node]
|
54
|
+
def node_children: () -> Array[Node]
|
55
|
+
|
56
|
+
# Recursively finds all Node nodes in the tree
|
57
|
+
# @rbs return: Array[Node]
|
58
|
+
def node_descendants: () -> Array[Node]
|
59
|
+
|
60
|
+
# Defines accessor methods for properties on the receiver
|
61
|
+
# @rbs properties: Hash[Symbol, Object] -- exposed as instance methods
|
62
|
+
def define_properties: (Hash[Symbol, Object] properties) -> untyped
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Generated from lib/fmt/parsers/arguments_parser.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Fmt
|
4
|
+
# Parses arguments from a string and builds an AST (Abstract Syntax Tree)
|
5
|
+
class ArgumentsParser < Parser
|
6
|
+
# Constructor
|
7
|
+
# @rbs tokens: Array[Token] -- wrapped ripper tokens
|
8
|
+
def initialize: (?Array[Token] tokens) -> untyped
|
9
|
+
|
10
|
+
attr_reader tokens: untyped
|
11
|
+
|
12
|
+
# Parses the urtext (original source code)
|
13
|
+
# @rbs return: Node -- AST (Abstract Syntax Tree)
|
14
|
+
def parse: () -> Node
|
15
|
+
|
16
|
+
# Extracts components for building the AST (Abstract Syntax Tree)
|
17
|
+
# @rbs return: Hash[Symbol, Object] -- extracted components
|
18
|
+
def extract: () -> Hash[Symbol, Object]
|
19
|
+
|
20
|
+
# Transforms extracted components into an AST (Abstract Syntax Tree)
|
21
|
+
# @rbs tokens: Array[Token] -- extracted tokens
|
22
|
+
# @rbs return: Node -- AST (Abstract Syntax Tree)
|
23
|
+
def transform: (tokens: Array[Token]) -> Node
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# Generated from lib/fmt/parsers/embed_parser.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Fmt
|
4
|
+
# Parses embeds from a string and builds an AST (Abstract Syntax Tree)
|
5
|
+
class EmbedParser < Parser
|
6
|
+
# Constructor
|
7
|
+
# @rbs urtext: String -- original source code
|
8
|
+
# @rbs key: Symbol -- key for embed
|
9
|
+
# @rbs placeholder: String -- placeholder for embed
|
10
|
+
def initialize: (?String urtext, key: Symbol, placeholder: String) -> untyped
|
11
|
+
|
12
|
+
attr_reader urtext: untyped
|
13
|
+
|
14
|
+
attr_reader key: untyped
|
15
|
+
|
16
|
+
attr_reader placeholder: untyped
|
17
|
+
|
18
|
+
# Parses the urtext (original source code)
|
19
|
+
# @rbs return: Node -- AST (Abstract Syntax Tree)
|
20
|
+
def parse: () -> Node
|
21
|
+
|
22
|
+
# Extracts components for building the AST (Abstract Syntax Tree)
|
23
|
+
# @rbs return: Hash[Symbol, Object] -- extracted components
|
24
|
+
def extract: () -> Hash[Symbol, Object]
|
25
|
+
|
26
|
+
# Transforms extracted components into an AST (Abstract Syntax Tree)
|
27
|
+
# @rbs return: Node -- AST (Abstract Syntax Tree)
|
28
|
+
def transform: (**untyped) -> Node
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# Returns the template urtext
|
33
|
+
# @rbs return: String
|
34
|
+
def template_urtext: () -> String
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Generated from lib/fmt/parsers/macro_parser.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Fmt
|
4
|
+
# Parses a macro from a string and builds an AST (Abstract Syntax Tree)
|
5
|
+
class MacroParser < Parser
|
6
|
+
# Constructor
|
7
|
+
# @rbs urtext: String -- original source code
|
8
|
+
def initialize: (?String urtext) -> untyped
|
9
|
+
|
10
|
+
attr_reader urtext: untyped
|
11
|
+
|
12
|
+
# Parses the urtext (original source code)
|
13
|
+
# @rbs return: Node -- AST (Abstract Syntax Tree)
|
14
|
+
def parse: () -> Node
|
15
|
+
|
16
|
+
# Extracts components for building the AST (Abstract Syntax Tree)
|
17
|
+
# @rbs return: Hash[Symbol, Object] -- extracted components
|
18
|
+
def extract: () -> Hash[Symbol, Object]
|
19
|
+
|
20
|
+
# Transforms extracted components into an AST (Abstract Syntax Tree)
|
21
|
+
# @rbs method: Symbol?
|
22
|
+
# @rbs arguments_tokens: Array[Token] -- arguments tokens
|
23
|
+
# @rbs return: Node -- AST (Abstract Syntax Tree)
|
24
|
+
def transform: (method: Symbol?, arguments_tokens: Array[Token]) -> Node
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
# Tokenizes source code
|
29
|
+
# @rbs code: String -- source code to tokenize
|
30
|
+
# @rbs return: Array[Token] -- wrapped ripper tokens
|
31
|
+
def tokenize: (String code) -> Array[Token]
|
32
|
+
|
33
|
+
# Indicates if there is a set of arguments in the tokens
|
34
|
+
# @rbs tokens: Array[Token] -- tokens to check
|
35
|
+
# @rbs return: bool
|
36
|
+
def arguments?: (Array[Token] tokens) -> bool
|
37
|
+
|
38
|
+
# Indicates if arguments have started
|
39
|
+
# @rbs tokens: Array[Token] -- tokens to check
|
40
|
+
# @rbs return: bool
|
41
|
+
def arguments_started?: (Array[Token] tokens) -> bool
|
42
|
+
|
43
|
+
# Indicates if arguments have finished
|
44
|
+
# @note Call this after a whitespace has been detected
|
45
|
+
# @rbs tokens: Array[Token] -- tokens to check
|
46
|
+
# @rbs return: bool
|
47
|
+
def arguments_finished?: (Array[Token] tokens) -> bool
|
48
|
+
|
49
|
+
# Indicates if a macro token array is complete or finished
|
50
|
+
# @note Call this after a whitespace has been detected
|
51
|
+
# @rbs tokens: Array[Token] -- tokens to check
|
52
|
+
# @rbs return: bool
|
53
|
+
def finished?: (Array[Token] tokens) -> bool
|
54
|
+
|
55
|
+
# Indicates if a value is a Ruby native format string
|
56
|
+
# @rbs value: String -- value to check
|
57
|
+
# @rbs return: bool
|
58
|
+
def native_format_string?: (String value) -> bool
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# Generated from lib/fmt/parsers/parser.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Fmt
|
4
|
+
# Responsible for parsing various inputs and returning an AST (Abstract Syntax Tree)
|
5
|
+
#
|
6
|
+
# Mechanics are similar to an ETL pipeline (Extract, Transform, Load), however,
|
7
|
+
# parsers only handle extracting and transforming.
|
8
|
+
#
|
9
|
+
# Loading is handled by AST processors (Models)
|
10
|
+
# @see lib/fmt/models/
|
11
|
+
class Parser
|
12
|
+
Cache: untyped
|
13
|
+
|
14
|
+
# Escapes a string for use in a regular expression
|
15
|
+
# @rbs value: String -- string to escape
|
16
|
+
# @rbs return: String -- escaped string
|
17
|
+
def self.esc: (String value) -> String
|
18
|
+
|
19
|
+
# Parses input passed to the constructor and returns an AST (Abstract Syntax Tree)
|
20
|
+
#
|
21
|
+
# 1. Extract components
|
22
|
+
# 2. Transform to AST
|
23
|
+
#
|
24
|
+
# @note Subclasses must implement the extract and transform methods
|
25
|
+
#
|
26
|
+
# @rbs return: Node -- AST (Abstract Syntax Tree)
|
27
|
+
def parse: () -> Node
|
28
|
+
|
29
|
+
# Extracts components for building the AST (Abstract Syntax Tree)
|
30
|
+
# @rbs return: Hash[Symbol, Object] -- extracted components
|
31
|
+
def extract: () -> Hash[Symbol, Object]
|
32
|
+
|
33
|
+
# Transforms extracted components into an AST (Abstract Syntax Tree)
|
34
|
+
# @rbs kwargs: Hash[Symbol, Object] -- extracted components
|
35
|
+
# @rbs return: Node -- AST (Abstract Syntax Tree)
|
36
|
+
def transform: (**untyped kwargs) -> Node
|
37
|
+
|
38
|
+
# Cache helper that fetches a value from the cache
|
39
|
+
# @rbs key: String -- cache key
|
40
|
+
# @rbs block: Proc -- block to execute if the value is not found in the cache
|
41
|
+
# @rbs return: Object
|
42
|
+
def cache: (String key) ?{ (?) -> untyped } -> Object
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Generated from lib/fmt/parsers/pipeline_parser.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Fmt
|
4
|
+
# Parses a pipeline from a string and builds an AST (Abstract Syntax Tree)
|
5
|
+
class PipelineParser < Parser
|
6
|
+
# Constructor
|
7
|
+
# @rbs urtext: String -- original source code
|
8
|
+
def initialize: (?String urtext) -> untyped
|
9
|
+
|
10
|
+
attr_reader urtext: untyped
|
11
|
+
|
12
|
+
# Parses the urtext (original source code)
|
13
|
+
# @rbs return: Node -- AST (Abstract Syntax Tree)
|
14
|
+
def parse: () -> Node
|
15
|
+
|
16
|
+
# Extracts components for building the AST (Abstract Syntax Tree)
|
17
|
+
# @rbs return: Hash[Symbol, Object] -- extracted components
|
18
|
+
def extract: () -> Hash[Symbol, Object]
|
19
|
+
|
20
|
+
# Transforms extracted components into an AST (Abstract Syntax Tree)
|
21
|
+
# @rbs macros: Array[Array[Token]] -- extracted macro tokens
|
22
|
+
# @rbs return: Node -- AST (Abstract Syntax Tree)
|
23
|
+
def transform: (macros: Array[Array[Token]]) -> Node
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# Generated from lib/fmt/parsers/template_parser.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Fmt
|
4
|
+
# Parses a template from a string and builds an AST (Abstract Syntax Tree)
|
5
|
+
class TemplateParser < Parser
|
6
|
+
PIPELINE_HEAD: ::Regexp
|
7
|
+
|
8
|
+
PIPELINE_TAIL: ::Regexp
|
9
|
+
|
10
|
+
EMBED_HEAD: ::Regexp
|
11
|
+
|
12
|
+
EMBED_TAIL: ::Regexp
|
13
|
+
|
14
|
+
# Constructor
|
15
|
+
# @rbs urtext: String -- original source code
|
16
|
+
# @rbs scanner: StringScanner?
|
17
|
+
def initialize: (?String urtext, ?scanner: StringScanner?) -> untyped
|
18
|
+
|
19
|
+
attr_reader urtext: untyped
|
20
|
+
|
21
|
+
attr_reader scanner: untyped
|
22
|
+
|
23
|
+
# Parses the urtext (original source code)
|
24
|
+
# @rbs return: Node -- AST (Abstract Syntax Tree)
|
25
|
+
def parse: () -> Node
|
26
|
+
|
27
|
+
# Extracts components for building the AST (Abstract Syntax Tree)
|
28
|
+
# @note Extraction is delegated to the PipelineParser and EmbedParser in transform
|
29
|
+
# @rbs return: Hash
|
30
|
+
def extract: () -> Hash
|
31
|
+
|
32
|
+
# Transforms extracted components into an AST (Abstract Syntax Tree)
|
33
|
+
# @rbs embeds: Array[Hash] -- extracted embeds
|
34
|
+
# @rbs pipelines: Array[String] -- extracted pipelines
|
35
|
+
# @rbs source: String -- parsed source code
|
36
|
+
# @rbs return: Node -- AST (Abstract Syntax Tree)
|
37
|
+
def transform: (embeds: Array[Hash], pipelines: Array[String], source: String) -> Node
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# Extracts embed metadata from the urtext
|
42
|
+
# @rbs return: Array[Hash] -- extracted embeds
|
43
|
+
def extract_embeds: () -> Array[Hash]
|
44
|
+
|
45
|
+
# Extracts pipelines from the source
|
46
|
+
# @rbs source: String -- source code to extract pipelines from
|
47
|
+
# @rbs return: Array[String] -- extracted pipelines
|
48
|
+
def extract_pipelines: (String source) -> Array[String]
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Generated from lib/fmt/refinements/kernel_refinement.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Fmt
|
4
|
+
module KernelRefinement
|
5
|
+
# Formats an object with Fmt
|
6
|
+
# @rbs object [Object] -- object to format (coerced to String)
|
7
|
+
# @rbs pipeline [Array[String | Symbol]] -- Fmt pipeline
|
8
|
+
# @rbs return [String] -- formatted text
|
9
|
+
def fmt: ([ Object ] object, *untyped pipeline) -> [ String ]
|
10
|
+
|
11
|
+
# Formats an object with Fmt and prints to STDOUT
|
12
|
+
# @rbs object [Object] -- object to format (coerced to String)
|
13
|
+
# @rbs pipeline [Array[String | Symbol]] -- Fmt pipeline
|
14
|
+
# @rbs return void
|
15
|
+
def fmt_print: ([ Object ] object, *untyped pipeline) -> void
|
16
|
+
|
17
|
+
# Formats an object with Fmt and puts to STDOUT
|
18
|
+
# @rbs object [Object] -- object to format (coerced to String)
|
19
|
+
# @rbs pipeline [Array[String | Symbol]] -- Fmt pipeline
|
20
|
+
# @rbs return void
|
21
|
+
def fmt_puts: ([ Object ] object, *untyped pipeline) -> void
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Generated from lib/fmt/registries/native_registry.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Fmt
|
4
|
+
# Extends native Ruby String format specifications with native Ruby methods
|
5
|
+
# @see https://ruby-doc.org/3.3.4/format_specifications_rdoc.html
|
6
|
+
class NativeRegistry < Registry
|
7
|
+
SUPPORTED_CLASSES: untyped
|
8
|
+
|
9
|
+
# Constructor
|
10
|
+
def initialize: () -> untyped
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
# Array of supported method names for a Class
|
15
|
+
# @rbs klass: Class
|
16
|
+
# @rbs return: Array[Symbol]
|
17
|
+
def supported_method_names: (Class klass) -> Array[Symbol]
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# Generated from lib/fmt/registries/rainbow_registry.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Fmt
|
4
|
+
# Extends native Ruby String format specifications with Rainbow methods
|
5
|
+
# @see https://ruby-doc.org/3.3.4/format_specifications_rdoc.html
|
6
|
+
# @note Rainbow macros convert the Object to a String
|
7
|
+
class RainbowRegistry < Registry
|
8
|
+
# Constructor
|
9
|
+
def initialize: () -> untyped
|
10
|
+
end
|
11
|
+
end
|