automatic whitespace for scheme
This commit is contained in:
parent
68cf598920
commit
304f11f224
@ -1,12 +1,11 @@
|
|||||||
ws:alias = [ \b\f\n\r\t\v];
|
whitespace:ws = [ \b\f\n\r\t\v];
|
||||||
comment:alias = ";" [^\n]*;
|
comment:ws = ";" [^\n]*;
|
||||||
wsc:alias = ws | comment;
|
number:nows = "-"? ("0" | [1-9][0-9]*) ("." [0-9]+)? ([eE] [+\-]? [0-9]+)?;
|
||||||
number = "-"? ("0" | [1-9][0-9]*) ("." [0-9]+)? ([eE] [+\-]? [0-9]+)?;
|
string:nows = "\"" ([^\\"] | "\\" .)* "\"";
|
||||||
string = "\"" ([^\\"] | "\\" .)* "\"";
|
symbol:nows = ([^\\ \n\t\b\f\r\v\"()\[\]#] | "\\" .)+;
|
||||||
symbol = ([^\\ \n\t\b\f\r\v\"()\[\]#] | "\\" .)+;
|
list-form:alias = "(" expression* ")"
|
||||||
list-form:alias = "(" wsc* (expression wsc*)* ")"
|
| "[" expression* "]";
|
||||||
| "[" wsc* (expression wsc*)* "]";
|
|
||||||
list = list-form;
|
list = list-form;
|
||||||
vector = "#" list-form;
|
vector = "#" list-form;
|
||||||
expression:alias = number | string | symbol | list;
|
expression:alias = number | string | symbol | list;
|
||||||
scheme = wsc* (expression wsc*)*;
|
scheme = expression*;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
whitespace:ws = [ \b\f\n\r\t\v];
|
whitespace:ws = [ \b\f\n\r\t\v];
|
||||||
comment:alias:ws = ";" [^\n]*;
|
comment:ws = ";" [^\n]*;
|
||||||
number:nows = "-"? ("0" | [1-9][0-9]*) ("." [0-9]+)? ([eE] [+\-]? [0-9]+)?;
|
number:nows = "-"? ("0" | [1-9][0-9]*) ("." [0-9]+)? ([eE] [+\-]? [0-9]+)?;
|
||||||
string:nows = "\"" ([^\\"] | "\\" .)* "\"";
|
string:nows = "\"" ([^\\"] | "\\" .)* "\"";
|
||||||
symbol:nows = ([^\\ \n\t\b\f\r\v\"()] | "\\" .)+;
|
symbol:nows = ([^\\ \n\t\b\f\r\v\"()] | "\\" .)+;
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package treerack
|
package treerack
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
const whitespaceName = ":ws"
|
const whitespaceName = ":ws"
|
||||||
|
|
||||||
@ -52,6 +55,10 @@ func mergeWhitespaceDefs(ws []definition) definition {
|
|||||||
|
|
||||||
// TODO: validate min and max
|
// TODO: validate min and max
|
||||||
|
|
||||||
|
func patchName(s ...string) string {
|
||||||
|
return strings.Join(s, ":")
|
||||||
|
}
|
||||||
|
|
||||||
func applyWhitespaceToSeq(s *sequenceDefinition) []definition {
|
func applyWhitespaceToSeq(s *sequenceDefinition) []definition {
|
||||||
var (
|
var (
|
||||||
defs []definition
|
defs []definition
|
||||||
@ -70,7 +77,7 @@ func applyWhitespaceToSeq(s *sequenceDefinition) []definition {
|
|||||||
|
|
||||||
singleItem := SequenceItem{Name: item.Name, Min: 1, Max: 1}
|
singleItem := SequenceItem{Name: item.Name, Min: 1, Max: 1}
|
||||||
|
|
||||||
restName := item.Name + ":wsrest"
|
restName := patchName(item.Name, s.nodeName(), "wsrest")
|
||||||
restDef := newSequence(restName, Alias, []SequenceItem{{Name: whitespaceName, Min: 0, Max: -1}, singleItem})
|
restDef := newSequence(restName, Alias, []SequenceItem{{Name: whitespaceName, Min: 0, Max: -1}, singleItem})
|
||||||
defs = append(defs, restDef)
|
defs = append(defs, restDef)
|
||||||
|
|
||||||
@ -87,7 +94,7 @@ func applyWhitespaceToSeq(s *sequenceDefinition) []definition {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
optName := item.Name + ":wsopt"
|
optName := patchName(item.Name, s.nodeName(), "wsopt")
|
||||||
optDef := newSequence(optName, Alias, []SequenceItem{singleItem, restItems})
|
optDef := newSequence(optName, Alias, []SequenceItem{singleItem, restItems})
|
||||||
defs = append(defs, optDef)
|
defs = append(defs, optDef)
|
||||||
items = append(items, SequenceItem{Name: optName, Min: 0, Max: 1})
|
items = append(items, SequenceItem{Name: optName, Min: 0, Max: 1})
|
||||||
@ -120,7 +127,7 @@ func applyWhitespace(defs []definition) []definition {
|
|||||||
|
|
||||||
func applyWhitespaceRoot(root definition) (definition, definition) {
|
func applyWhitespaceRoot(root definition) (definition, definition) {
|
||||||
original, name := root, root.nodeName()
|
original, name := root, root.nodeName()
|
||||||
wsName := ":wsroot:" + name
|
wsName := patchName(name, "wsroot")
|
||||||
|
|
||||||
original.setNodeName(wsName)
|
original.setNodeName(wsName)
|
||||||
original.setCommitType(original.commitType() &^ Root)
|
original.setCommitType(original.commitType() &^ Root)
|
||||||
|
Loading…
Reference in New Issue
Block a user