Skip to content

Commit

Permalink
Define an Inlining grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Feb 14, 2024
1 parent 5cf4525 commit 27b5288
Show file tree
Hide file tree
Showing 6 changed files with 767 additions and 518 deletions.
21 changes: 21 additions & 0 deletions lib/lrama/grammar/inline/resolver.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Lrama
class Grammar
class Inline
class Resolver
attr_accessor :rules

def initialize
@rules = []
end

def add_inline_rule(rule)
@rules << rule
end

def find(token)
@rules.select { |rule| rule.name == token.s_value }.last
end
end
end
end
end
15 changes: 15 additions & 0 deletions lib/lrama/grammar/inline/rhs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Lrama
class Grammar
class Inline
class Rhs
attr_accessor :symbols, :user_code, :precedence_sym

def initialize
@symbols = []
@user_code = nil
@precedence_sym = nil
end
end
end
end
end
14 changes: 14 additions & 0 deletions lib/lrama/grammar/inline/rule.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Lrama
class Grammar
class Inline
class Rule
attr_reader :name, :rhs_list

def initialize(name, rhs_list)
@name = name
@rhs_list = rhs_list
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/lrama/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Lexer
%code
%rule
%no-stdlib
%inline
)

def initialize(grammar_file)
Expand Down
Loading

0 comments on commit 27b5288

Please sign in to comment.