Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Grammar bugs #13

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "A language server for Verilog",
"author": "chrehall68",
"license": "MIT",
"version": "1.0.2",
"version": "1.0.3",
"repository": {
"type": "git",
"url": "https://github.com/chrehall68/vls"
Expand Down
2 changes: 1 addition & 1 deletion client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function downloadToBin(
}

async function resolveServerExecutable(ctx: ExtensionContext): Promise<string> {
const version = "1.0.2";
const version = "1.0.3";
const platformDetails = {
win32: {
url: `https://github.com/chrehall68/vls/releases/download/${version}/vls-windows-amd64.exe`,
Expand Down
49 changes: 41 additions & 8 deletions server/internal/lang/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,13 +785,27 @@ func (p *Parser) parseAssignmentNode(tokens []Token, pos int) (result Assignment
}

func (p *Parser) parseTypeNode(tokens []Token, pos int) (result TypeNode, newPos int, err error) {
// TYPE [<range>]
pos, err = p.checkToken("type", []string{"type"}, pos, tokens)
// (TYPE | DIRECTION [TYPE]) [<range>]
pos, err = p.checkToken("type", []string{"type", "direction"}, pos, tokens)
if err != nil {
return
}
result.Type = tokens[pos]
pos++

if tokens[pos].Type == "direction" {
// potentially take a type
potentialPos, e := p.checkToken("type", []string{"type"}, pos+1, tokens)
if e == nil {
// success!
result.Type = tokens[potentialPos]
pos = potentialPos + 1
} else {
result.Type = tokens[pos]
pos++
}
} else {
result.Type = tokens[pos]
pos++
}

// now try taking the range; it's ok if it fails since it's optional
rangeNode, potentialPos, e := p.parseRangeNode(tokens, pos)
Expand Down Expand Up @@ -900,14 +914,27 @@ func (p *Parser) parseDeclarationNode(tokens []Token, pos int) (result Declarati
}

func (p *Parser) parseBeginBlock(tokens []Token, pos int) (result BeginBlockNode, newPos int, err error) {
// BEGIN <generateable_statements> END
// BEGIN [ COLON <identifier> ] { <alwaysable_statement> } END
pos, err = p.checkToken("begin block", []string{"begin"}, pos, tokens)
if err != nil {
return
}
pos++

// get the generateable statements
// optionally, get colon
potentialPos, e := p.checkToken("begin block", []string{"colon"}, pos, tokens)
if e == nil {
pos = potentialPos + 1

// get identifier
pos, err = p.checkToken("begin block", []string{"identifier"}, pos, tokens)
if err != nil {
return
}
pos++
}

// get the alwaysable statements
generateableStatements, potentialPos, e := p.parseAlwaysStatements(tokens, pos)
if e != nil {
err = e
Expand Down Expand Up @@ -1824,6 +1851,9 @@ func getInteriorStatementsFromAlwaysStatement(statement AlwaysStatement) []Inter
result = append(result, getInteriorStatementsFromAlwaysStatement(statement.ForBlock.Body)...)
} else if statement.IfBlock != nil {
result = append(result, getInteriorStatementsFromAlwaysStatement(statement.IfBlock.Body)...)
if statement.IfBlock.Else != nil {
result = append(result, getInteriorStatementsFromAlwaysStatement(*statement.IfBlock.Else)...)
}
} else if statement.InteriorNode != nil {
result = append(result, getInteriorStatementsFromInteriorNode(*statement.InteriorNode)...)
}
Expand Down Expand Up @@ -1882,6 +1912,9 @@ func getFunctionStatementsFromAlwaysStatement(statement AlwaysStatement) []Funct
result = append(result, *statement.FunctionNode)
} else if statement.IfBlock != nil {
result = append(result, getFunctionStatementsFromAlwaysStatement(statement.IfBlock.Body)...)
if statement.IfBlock.Else != nil {
result = append(result, getFunctionStatementsFromAlwaysStatement(*statement.IfBlock.Else)...)
}
} else if statement.InteriorNode != nil {
result = append(result, getFunctionStatementsFromInteriorNode(*statement.InteriorNode)...)
}
Expand Down Expand Up @@ -1949,7 +1982,7 @@ Grammar:

<declaration> -> <type> <single_var> EQUAL <expr> { COMMA <single_var> EQUAL <expr> } SEMICOLON
| <type> <single_var> { COMMA <single_var> } SEMICOLON
<type> -> TYPE [<range>]
<type> -> (TYPE | DIRECTION [TYPE]) [<range>]
<index> -> LBRACKET <identifier> RBRACKET | LBRACKET <integer> RBRACKET
<range> -> LBRACKET <integer> COLON <integer> RBRACKET
<integer> -> LITERAL | DEFINE
Expand All @@ -1967,7 +2000,7 @@ Grammar:
<defparam> -> DEFPARAM <identifier> { DOT <identifier> } EQUAL <expr> SEMICOLON

<generate> -> GENERATE { <alwaysable_statement> } ENDGENERATE
<begin_block> -> BEGIN { <alwaysable_statement> } END
<begin_block> -> BEGIN [ COLON <identifier> ] { <alwaysable_statement> } END
<for> -> FOR LPAREN [<assignment_without_semicolon>] SEMICOLON [<expr>] SEMICOLON [<assignment_without_semicolon>] RPAREN <alwaysable_statement>
<if> -> IF LPAREN <expr> RPAREN <alwaysable_statement> [ELSE <alwaysable_statement>]
<builtin_function_call> -> DOLLAR <identifier> [LPAREN <expr> { COMMA <expr> } RPAREN] SEMICOLON
Expand Down
3 changes: 2 additions & 1 deletion server/internal/lang/vlexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ func NewVLexer(logger *zap.Logger) *VLexer {
vlexer.AddMappingNoCapture(regexp.MustCompile(`^((\$time)|(\$realtime))`), "funcliteral")
vlexer.AddMappingNoCapture(regexp.MustCompile(`^((\$signed)|(\$unsigned))`), "signed")
// variable-related
vlexer.AddMappingNoCapture(regexp.MustCompile(`^((reg)|(wire)|(genvar)|(parameter)|(input)|(output)|(inout)|(integer))`), "type")
vlexer.AddMappingNoCapture(regexp.MustCompile(`^((reg)|(wire)|(genvar)|(parameter)|(integer))`), "type")
vlexer.AddMappingNoCapture(regexp.MustCompile(`^((input)|(output)|(inout))`), "direction")
vlexer.AddMappingNoCapture(regexp.MustCompile(`^defparam`), "defparam")
vlexer.AddMapping(regexp.MustCompile("^`?[A-Za-z][a-zA-Z0-9_]*"), func(code string) (Token, error) {
re := regexp.MustCompile("^`?(?P<IDENTIFIER>[A-Za-z][a-zA-Z0-9_]*)")
Expand Down
1 change: 1 addition & 0 deletions server/internal/vlsp/semtokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func Encode(tokens []lang.Token) []uint32 {
tokenTypeToInt := map[string]uint32{
"comment": 1,
"type": 0,
"direction": 0,
"defparam": 0,
"literal": 2,
"module": 3,
Expand Down
Loading