Skip to content

Commit

Permalink
Add keywords and test keyword identification
Browse files Browse the repository at this point in the history
Gamelan currently playing: Lancaran Penghijauan

co-authored-by: Connor Walsh <[email protected]>
co-authored-by: Octavia <[email protected]>
  • Loading branch information
3 people committed Apr 7, 2018
1 parent eff5c13 commit 6f14d3d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
19 changes: 19 additions & 0 deletions lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@ func (s *LexerSuite) TestTokenizeIdentifier() {
}
}

func (s *LexerSuite) TestTokenizeIdentifier_Keyword() {
conf := &Config{SrcFileName: "test/test_identifiers_keyword.doc"}
compt := NewCompterpreter(conf)

err := compt.LoadSourceCode()
s.NoError(err)

compt.Advance()
// advance ptr to first character
for _, op := range []string{"if"} {
compt.CurrentToken = Token{}
compt.TokenizeIdentifier(compt.CurrentChar)
if string(compt.CurrentChar) == "EOF" {
break
}
s.EqualValues(compt.CurrentToken.Value, op)
}
}

func (s *LexerSuite) TestLex() {
conf := &Config{SrcFileName: "test/test_tokenize.doc"}
compt := NewCompterpreter(conf)
Expand Down
8 changes: 7 additions & 1 deletion symbols.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const (

VARIABLE_IDENTIFIER = "VARIABLE_IDENTIFIER"
FUNCTION_IDENTIFIER = "FUNCTION_IDENTIFIER"

IF_KEYWORD = "if"
FUNCTION_KEYWORD = "❦"
)

var (
Expand Down Expand Up @@ -55,7 +58,10 @@ func PopulateSymbols() *Symbols {
EXIT_OPERATOR,
NOOP,
},
Keywords: []string{},
Keywords: []string{
IF_KEYWORD,
FUNCTION_KEYWORD,
},
Punctuation: []string{
R_PAREN_PUNCTION,
L_PAREN_PUNCUTATION,
Expand Down

0 comments on commit 6f14d3d

Please sign in to comment.