Skip to content

Commit

Permalink
add rspec for parser
Browse files Browse the repository at this point in the history
  • Loading branch information
robertDurst committed Jan 4, 2024
1 parent 6eb352b commit 2521330
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
19 changes: 19 additions & 0 deletions spec/zodiac/parser_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require './spec/spec_helper'
require './src/zodiac/parser'

describe Zodiac::Parser do
describe '.parse' do
context 'when empty program' do
it 'returns empty program' do
parser = described_class.new('')

actual = parser.parse
expected = { kind: 'PROGRAM', value: [] }

expect(actual).to eq(expected)
end
end
end
end
10 changes: 8 additions & 2 deletions src/zodiac/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,19 @@ def initialize(raw_string)
@tokens = []
end

def parse; end
def parse
parse_program
end

private

# PROGRAM : COMPSTMT
def parse_program
{ kind: 'PROGRAM', value: parse_compstmt }
cmp_stmts = []

cmp_stmts << parse_compstmt while @cur_index < @raw_string.length

{ kind: 'PROGRAM', value: cmp_stmts }
end

# COMPSTMT : STMT (TERM EXPR)* [TERM]
Expand Down

0 comments on commit 2521330

Please sign in to comment.