Skip to content

Instantly share code, notes, and snippets.

@dirk
Created August 3, 2011 15:18
Show Gist options
  • Save dirk/1122891 to your computer and use it in GitHub Desktop.
Save dirk/1122891 to your computer and use it in GitHub Desktop.
syntax = r'''
<ts> := [ \t]*
# Variable delcarations
local_var := [a-z], [a-z0-9_]*
global_var := [A-Z], [a-z0-9_]+
# The chain of indexes and properties for objects
tail := (index/property/func_call)+
index := "[", expression, "]"
property := ".", local_var
func_call := ts, ("(", arg_list?, ")")/(" "+, arg_list, " "+), ts
arg_list := ts, expression, ts, (",", arg_list)?
# Structure of the basic code
body := [ \n\t]*, statement, (terminal, statement)*, terminal?, [ \n\t]*
<terminal> := ";"/"\n"
statement := assignment/expression
assignment := identifier, ts, '=', expression
# Basic expressions and grouping (identifiers are like special expressions for variables)
identifier := local_var/global_var, tail?
expression := ts, identifier/(expression_group/literal/block, tail?), ts, (operator, ts, expression)?
expression_group := "(", ts, expression, ts, ")"
# Blocks and their assorted stuff
block := "{", ("|", param_list, "|")?, body, "}"
param_list := ts, local_var, ts, (",", param_list)?
operator := math_op
<math_op> := "+"/"-"/"*"/"/"
literal := string/number
number := [1-9], [0-9]*, decimal?
string := ("\"", -"\""+, "\"")/("'", -"'"+, "'")
<decimal> := ".", [0-9]+
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment