Skip to content

Commit

Permalink
Merge pull request #96 from Eclalang/issue-#78-addition
Browse files Browse the repository at this point in the history
added murloc node to parser as well as documentation
  • Loading branch information
tot0p authored Dec 13, 2023
2 parents 757891a + 84a6497 commit ea520c1
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 20 deletions.
25 changes: 14 additions & 11 deletions parser/Keywords.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package parser

import "github.com/Eclalang/Ecla/lexer"

const (
Int = "int"
String = "string"
Expand All @@ -12,17 +14,18 @@ const (

var (
Keywords = map[string]interface{}{
"var": nil,
"function": nil,
"return": nil,
"range": nil,
"import": nil,
"type": nil,
"for": nil,
"while": nil,
"if": nil,
"else": nil,
"null": nil,
"var": nil,
"function": nil,
"return": nil,
"range": nil,
"import": nil,
"type": nil,
"for": nil,
"while": nil,
"if": nil,
"else": nil,
"null": nil,
lexer.MURLOC: nil,
}
VarTypes = map[string]interface{}{
Int: nil,
Expand Down
14 changes: 14 additions & 0 deletions parser/NodeTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,17 @@ func (r ReturnStmt) EndPos() int {
}

func (r ReturnStmt) stmtNode() {}

type MurlocStmt struct {
MurlocToken lexer.Token
}

func (m MurlocStmt) StartPos() int {
return m.MurlocToken.Position
}

func (m MurlocStmt) EndPos() int {
return m.MurlocToken.Position + len(lexer.MURLOC)
}

func (m MurlocStmt) stmtNode() {}
26 changes: 26 additions & 0 deletions parser/Nodes-Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- [ForStmt node](#forstmt-node)
- [ImportStmt node](#importstmt-node)
- [ReturnStmt node](#returnstmt-node)
- [MurlocStmt node](#murlocstmt-node)
- [Declaration nodes](#declaration-nodes)
- [VariableDecl node](#variabledecl-node)
- [FunctionDecl node](#functiondecl-node)
Expand Down Expand Up @@ -625,6 +626,31 @@ for example :

***

#### MurlocStmt node
The `MurlocStmt` node represents a murloc statement in the Ecla language.

##### Fields
The `MurlocStmt` node is defined as follows :

```go
type MurlocStmt struct {
MurlocToken lexer.Token
}
```

The `MurlocToken` field is the token that represents the murloc statement.

##### Code Example
a murloc statement is a statement that contains a murloc token.

for example :
```ecla
mgrlgrl;
```

***


### Declaration nodes
This part of the documentation will cover all the declaration nodes.

Expand Down
14 changes: 5 additions & 9 deletions parser/Parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ func (p *Parser) Step() {
} else {
p.CurrentToken = p.Tokens[p.TokenIndex]
}
if p.CurrentToken.TokenType == lexer.MURLOC {
p.HandleFatal("Mrgle, Mmmm Uuua !")
}
}

// Back moves the parser back one token
Expand All @@ -38,9 +35,6 @@ func (p *Parser) Back() {
p.TokenIndex = 0
}
p.CurrentToken = p.Tokens[p.TokenIndex]
if p.CurrentToken.TokenType == lexer.MURLOC {
p.HandleFatal("Mrgle, Mmmm Uuua !")
}
}

// MultiStep moves the parser forward n times givens as parameter
Expand All @@ -51,9 +45,6 @@ func (p *Parser) MultiStep(steps int) {
} else {
p.CurrentToken = p.Tokens[p.TokenIndex]
}
if p.CurrentToken.TokenType == lexer.MURLOC {
p.HandleFatal("Mrgle, Mmmm Uuua !")
}
}

// MultiBack moves the parser back n times given as parameter
Expand Down Expand Up @@ -231,6 +222,11 @@ func (p *Parser) ParseKeyword() Node {
p.Step()
return tempLiteral
}
if p.CurrentToken.Value == lexer.MURLOC {
tempStmt := MurlocStmt{MurlocToken: p.CurrentToken}
p.Step()
return tempStmt
}
p.HandleFatal("Unknown keyword: " + p.CurrentToken.Value)
return nil
}
Expand Down

0 comments on commit ea520c1

Please sign in to comment.