put more things in grammar
This commit is contained in:
parent
09f230985e
commit
abdff4f65c
2 changed files with 40 additions and 2 deletions
|
@ -2,8 +2,12 @@
|
|||
|
||||
import sys
|
||||
import pprint
|
||||
import logging
|
||||
|
||||
from jortsc.parser.lexer import lex_jorts
|
||||
from jortsc.parser.parser import parse
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
def main():
|
||||
"""main entry point"""
|
||||
|
@ -16,5 +20,8 @@ def main():
|
|||
pprint.pprint(tokens)
|
||||
print([t[0] for t in tokens])
|
||||
|
||||
tree = parse(in_data)
|
||||
print(tree)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -1,9 +1,40 @@
|
|||
|
||||
from lark import Lark
|
||||
|
||||
# TODO: write a grammar
|
||||
GRAMMAR = """
|
||||
yeet
|
||||
FN: "fn"
|
||||
IMPORT: "import"
|
||||
COMMA: ","
|
||||
DOT: "."
|
||||
SINGLE_COMMENT: "//"
|
||||
NEWLINE: /[ \\n\\t]+/
|
||||
ANY: /.+/
|
||||
WHITESPACE: " "
|
||||
INTEGER: /[0-9]+/
|
||||
ARROW: "->"
|
||||
COM_START: "/*"
|
||||
COM_END: "*/"
|
||||
QUOTE: "\\""
|
||||
|
||||
identifier: WHITESPACE* ANY WHITESPACE*
|
||||
|
||||
single_comment: "//" ANY* NEWLINE
|
||||
multi_comment: COM_START ANY* COM_END
|
||||
|
||||
import_stmt: IMPORT identifier NEWLINE
|
||||
|
||||
fn_arg: identifier identifier
|
||||
fn_stmt: FN identifier? "(" [fn_arg COMMA] ")" [ARROW identifier] "{" [stmt NEWLINE]* "}"
|
||||
|
||||
sign_int: "+" | "-"
|
||||
string: QUOTE ANY* QUOTE
|
||||
value: (sign_int* INTEGER) | string
|
||||
|
||||
call_stmt: [identifier DOT] identifier "(" [value COMMA]* ")"
|
||||
|
||||
stmt: (NEWLINE*) | import_stmt | fn_stmt | call_stmt
|
||||
|
||||
start: (stmt NEWLINE)*
|
||||
"""
|
||||
|
||||
def parse(string: str):
|
||||
|
|
Loading…
Reference in a new issue