Adding and improving grammars.

This commit is contained in:
Bruce Hill 2021-01-17 20:05:19 -08:00
parent fdc91544b7
commit 008db80229
4 changed files with 43 additions and 18 deletions

View File

@ -8,9 +8,6 @@
comment: "//" .. $ / "/*" .. "*/" % \n
string: `"..`" % (`\.)
char: `' [`\] . `'
array: `{..`} % (array/comment/\n)
struct: array
keyword: |(
"auto" / "break" / "case" / "char" / "const" / "continue" / "default" / "do" /
"double" / "else" / "enum" / "extern" / "float" / "for" / "goto" / "if" /
@ -21,3 +18,4 @@ keyword: |(
function-def: ^_ 2+(keyword / id / `*) % __ parens (__`; / >(__`{))
function: function-def __ braces
macro: ^"#define " ..$ *(<`\ \n..$)
import: |"#include"| __ (string / `<..`>)

18
grammars/go.bp Normal file
View File

@ -0,0 +1,18 @@
# Syntax definitions for some Go-specific patterns
#
# NOTE: this is *NOT* intended to be a complete definition of the language's
# syntax! Providing a full language grammar is overkill, because the intended
# use case is finding/replacing string patterns. This task does not require a
# full parse tree, and having one makes the task considerably more complicated.
# See the accompanying README.md for more info.
comment: "//" .. $ / "/*" .. "*/" % \n
string: `"..`" % (`\.)
keyword: |(
"break" / "default" / "func" / "interface" / "select" / "case" / "defer" / "go" /
"map" / "struct" / "chan" / "else" / "goto" / "package" / "switch" / "const" /
"fallthrough" / "if" / "range" / "type" / "continue" / "for" / "import" / "return" / "var"
)|
function-def: |"func"| __ id __ parens __ [id / parens] >(__`{)
function: function-def __ braces
import: |"import"| __ (parens / string)

View File

@ -7,24 +7,14 @@
# See the accompanying README.md for more info.
comment: `# ..$
string: quoted-string / `b quoted-string / `f quoted-string
quoted-string: "'''".."'''" % \n / '"""'..'"""' % \n / `"..`" % (`\.) / `'..`' % (`\.)
dict: `{__`} / `{ __ +(expr__`:__expr) % (__`,__) __ `}
set: `{ __ +expr % (__`,__) __ `}
list: `[ __ +expr % (__`,__) __ `]
string: "'''".."'''" % \n / '"""'..'"""' % \n / `"..`" % (`\.) / `'..`' % (`\.)
keyword: |("and" / "as" / "assert" / "break" / "class" / "continue" / "def" /
"del" / "elif" / "else" / "except" / "finally" / "for" / "from" /
"global" / "if" / "import" / "in" / "is" / "lambda" / "None" / "nonlocal" /
"not" / "or" / "pass" / "raise" / "return" / "try" / "while" /
"with" / "yield")|
expr: (function-call / lambda / string / dict / set / list / id / number / `(__expr__`)) *(method/attr/index)
method: `. function-call
attr: `. id
index: `[__expr[__`:__expr [__`:__expr]]__`]
tuple: `(__`) / +(__expr__`,) [__expr]
empty-tuple: `(__`)
class: |"class"|_id`: +(\N ..$)
class: class-def +(\N ..$)
class-def: ^_|"class"|_id[_parens]_`:
function: function-def +(\N ..$)
function-def: |"def"|_id parens `:
function-call: !<"def " id parens
lambda: |"lambda"| .. `:__expr
function-def: ^_|"def"|_id parens `:
import: |"import"| _ (parens / *id%(_`,__)) [_ |"as"| (parens / *id%(_`,__))]

19
grammars/rust.bp Normal file
View File

@ -0,0 +1,19 @@
# Syntax definitions for some Rust-specific patterns
#
# NOTE: this is *NOT* intended to be a complete definition of the language's
# syntax! Providing a full language grammar is overkill, because the intended
# use case is finding/replacing string patterns. This task does not require a
# full parse tree, and having one makes the task considerably more complicated.
# See the accompanying README.md for more info.
comment: "//" .. $ / "/*" .. "*/" % (comment / \n)
string: `"..`" % (`\.)
keyword: |(
"as" / "break" / "const" / "continue" / "crate" / "else" / "enum" / "extern" /
"false" / "fn" / "for" / "if" / "impl" / "in" / "let" / "loop" / "match" /
"mod" / "move" / "mut" / "pub" / "ref" / "return" / "self" / "Self" / "static" /
"struct" / "super" / "trait" / "true" / "type" / "unsafe" / "use" / "where" / "while"
)|
function-def: |"fn"| __ id __ parens __ ["->"__(id / parens)] >(__`{)
function: function-def __ braces
import: |"use"| _ *(id / braces) % "::" _ `;