Skip to content

Commit

Permalink
support more sexpr code
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmuth committed Jun 3, 2024
1 parent 0c7f6c5 commit c713212
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
6 changes: 2 additions & 4 deletions FrontEnd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ TESTS_CONCRETE = $(LANG_TESTS) $(TESTS) \
Lib/trig.cw \
Lib/trig_test.cw

# Lib/flate.cw
# Lib/flate.cw ***
# Lib/flate_test.cw
# Lib/fmt.cw
# Lib/fmt.cw poly
# Lib/fmt_test.cw
# Lib/huffman.cw
# Lib/huffman_test.cw
# Lib/sha3.cw
# Lib/sha3_test.cw

Expand Down
18 changes: 9 additions & 9 deletions FrontEnd/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def _ExtractAnnotations(tk: TK) -> dict[str, str]:
assert c.text.startswith("-- ")
comments.append(c.text[3:-1])
if comments:
if len(comments) == 1:
if len(comments) == 1 and '"' not in comments[0]:
out["doc"] = f'"{comments[0]}"'
else:
c = '\n'.join(comments)
Expand Down Expand Up @@ -544,11 +544,11 @@ def _PParseParenGroup(inp: Lexer, tk: TK, _precedence) -> Any:

_PREFIX_EXPR_PARSERS = {
TK_KIND.KW: (10, _PParseKeywordConstants),
TK_KIND.OP1: (9, _PParsePrefix),
TK_KIND.OP2: (10, _PParsePrefix),
TK_KIND.OP1: (pp.PREC1_NOT, _PParsePrefix),
TK_KIND.OP2: (10, _PParsePrefix), # only used for "-"
TK_KIND.ID: (10, _PParseId),
TK_KIND.NUM: (10, _PParseNum),
TK_KIND.SQUARE_OPEN: (10, _PParseArrayType),
TK_KIND.SQUARE_OPEN: (pp.PREC_INDEX, _PParseArrayType),
TK_KIND.STR: (10, _PParseStr),
TK_KIND.CHAR: (10, _PParseChar),
TK_KIND.PAREN_OPEN: (10, _PParseParenGroup),
Expand Down Expand Up @@ -713,10 +713,10 @@ def _PParseTernary(inp: Lexer, cond, _tk: TK, _precedence) -> Any:
#
"(": (20, _PParseFunctionCall),
"{": (10, _PParseInitializer),
"[": (13, _PParseIndex),
"^": (20, _PParseDeref),
".": (20, _PParseFieldAccess),
"^.": (20, _PParseDerefFieldAccess),
"[": (pp.PREC_INDEX, _PParseIndex),
"^": (pp.PREC_INDEX, _PParseDeref),
".": (pp.PREC_INDEX, _PParseFieldAccess),
"^.": (pp.PREC_INDEX, _PParseDerefFieldAccess),
"?": (6, _PParseTernary),
}

Expand Down Expand Up @@ -885,7 +885,7 @@ def _ParseStatement(inp: Lexer):
else:
assert kind.kind is TK_KIND.COMPOUND_ASSIGN, f"{kind}"
op = cwast.ASSIGNMENT_SHORTCUT[kind.text]
return cwast.StmtCompoundAssignment(op, lhs, rhs)
return cwast.StmtCompoundAssignment(op, lhs, rhs, ** _ExtractAnnotations(kw))
elif kw.text == "return":
if inp.peek().srcloc.lineno == kw.srcloc.lineno:
val = _ParseExpr(inp)
Expand Down
3 changes: 3 additions & 0 deletions FrontEnd/pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
PREC2_ADD = 10 # + - or xor
PREC2_MUL = 11 # * / % and
PREC2_SHIFT = 12
PREC1_NOT = 13
PREC_INDEX = 14 # &a[i] &struct^.field
#PREC_DEREF = 15


_OPS_PRECENDENCE_EXPR2 = {
Expand Down

0 comments on commit c713212

Please sign in to comment.