Compare commits
2 commits
fe507437ea
...
abdff4f65c
Author | SHA1 | Date | |
---|---|---|---|
abdff4f65c | |||
09f230985e |
3 changed files with 40 additions and 12 deletions
|
@ -1,10 +0,0 @@
|
||||||
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
|
|
||||||
integer = ['-' | '+'] "0" digit {digit} ;
|
|
||||||
|
|
||||||
hex_letters = "a" | "b" | "c" | "d" | "e" | "f"
|
|
||||||
hex_integer = "0x", {hex_letters | digit} ;
|
|
||||||
|
|
||||||
oct_digits = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" ;
|
|
||||||
octal_integer = "0o", {oct_digits} ;
|
|
||||||
|
|
||||||
program =
|
|
|
@ -2,8 +2,12 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import pprint
|
import pprint
|
||||||
|
import logging
|
||||||
|
|
||||||
from jortsc.parser.lexer import lex_jorts
|
from jortsc.parser.lexer import lex_jorts
|
||||||
|
from jortsc.parser.parser import parse
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""main entry point"""
|
"""main entry point"""
|
||||||
|
@ -16,5 +20,8 @@ def main():
|
||||||
pprint.pprint(tokens)
|
pprint.pprint(tokens)
|
||||||
print([t[0] for t in tokens])
|
print([t[0] for t in tokens])
|
||||||
|
|
||||||
|
tree = parse(in_data)
|
||||||
|
print(tree)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -1,9 +1,40 @@
|
||||||
|
|
||||||
from lark import Lark
|
from lark import Lark
|
||||||
|
|
||||||
# TODO: write a grammar
|
|
||||||
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):
|
def parse(string: str):
|
||||||
|
|
Loading…
Reference in a new issue