Skip to content

Commit

Permalink
feat[venom]: allow alphanumeric variables and source comments (#4403)
Browse files Browse the repository at this point in the history
This commit implements minor improvements to the venom parser.
Specifically it allows for alphanumeric variable names, and for single
line source code comments in various styles: ";" "#" and "//"

---------

Co-authored-by: Charles Cooper <cooper.charles.m@gmail.com>
  • Loading branch information
harkal and charles-cooper authored Dec 17, 2024
1 parent 135c2d6 commit ebe26a6
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions vyper/venom/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
%import common.WS
%import common.INT
# Allow multiple comment styles
COMMENT: ";" /[^\\n]*/ | "//" /[^\\n]*/ | "#" /[^\\n]*/
start: function* data_section?
# TODO: consider making entry block implicit, e.g.
Expand All @@ -40,12 +43,10 @@
CONST: INT
OPCODE: CNAME
VAR_IDENT: "%" INT (":" INT)?
VAR_IDENT: "%" NAME
LABEL: "@" NAME
NAME: (DIGIT|LETTER|"_")+
COMMENT: ";" /[^\\n]/*
%ignore WS
%ignore COMMENT
"""
Expand All @@ -59,7 +60,9 @@ def _set_last_var(fn: IRFunction):
continue
value = inst.output.value
assert value.startswith("%")
fn.last_variable = max(fn.last_variable, int(value[1:]))
varname = value[1:]
if varname.isdigit():
fn.last_variable = max(fn.last_variable, int(varname))


def _set_last_label(ctx: IRContext):
Expand Down Expand Up @@ -172,7 +175,7 @@ def VAR_IDENT(self, var_ident) -> IRVariable:
varname = parts[0]
version = None
if len(parts) > 1:
version = parts[1]
version = int(parts[1])
return IRVariable(varname, version=version)

def CONST(self, val) -> IRLiteral:
Expand Down

0 comments on commit ebe26a6

Please sign in to comment.