IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!

#18 Replace jailconf with a peg grammar

Open
opened 3 years ago by sadaszewski1 · 0 comments

Something to think about:

JailConf = conf:(JailBlock / Parameter / Comment)* { return { 'JailConf': conf } }

Comment = comment:(_ "#" CommentText  / _ "//" CommentText) {
  return { 'Comment': comment.join('') } 
}

CommentText = [^\n]+ { return text() }

Parameter = _ name:Name _ op:AssignmentOp _ value:Value _ ";" {
  return { 'Parameter': { 'name': name, 'op': op, 'value': value } }
} / _ name:Name _ ";" {
  return { 'Parameter': { 'name': name, 'value': true } }
}

_ = [ \t\r\n]* { return '' }

Name = [a-zA-Z.][a-zA-Z.0-9]* { return text() }

AssignmentOp = "=" / "+="

Value = ListOfStrings / String

String = UnquotedString / SingleQuotedString / DoubleQuotedString

ListOfStrings = head:String tail:(_ ","  _ String)+ { 
	return [head].concat(tail.map(function(a) { return a[3] }))
}

UnquotedString = [^;"',]+ { return text() }

NotSingleQuote = !("'" / "\\") . { return text() }

EscapedSingleQuote = "\\" "'" { return '\\\'' } / 
  "\\\\" { return '\\\\' }

SingleQuotedString = "'" content:(NotSingleQuote / EscapedSingleQuote)* "'" {
  return content.join('')
}

NotDoubleQuote = !("\"" / "\\") . { return text() }

EscapedDoubleQuote = "\\" "\"" { return '\\"' } /
  "\\\\" { return '\\\\' }

DoubleQuotedString = "\"" content:(NotDoubleQuote / EscapedDoubleQuote)* "\"" { return content.join('') }

JailBlock = _ name:JailName _ "{" _ body:JailBody _ "}" _ {
  return { 'JailBlock': { 'name': name, 'body': body } }
}

JailName = [a-zA-Z0-9][a-zA-Z0-9]* { return text() }

JailBody = (Parameter / Comment)*
Something to think about: ``` JailConf = conf:(JailBlock / Parameter / Comment)* { return { 'JailConf': conf } } Comment = comment:(_ "#" CommentText / _ "//" CommentText) { return { 'Comment': comment.join('') } } CommentText = [^\n]+ { return text() } Parameter = _ name:Name _ op:AssignmentOp _ value:Value _ ";" { return { 'Parameter': { 'name': name, 'op': op, 'value': value } } } / _ name:Name _ ";" { return { 'Parameter': { 'name': name, 'value': true } } } _ = [ \t\r\n]* { return '' } Name = [a-zA-Z.][a-zA-Z.0-9]* { return text() } AssignmentOp = "=" / "+=" Value = ListOfStrings / String String = UnquotedString / SingleQuotedString / DoubleQuotedString ListOfStrings = head:String tail:(_ "," _ String)+ { return [head].concat(tail.map(function(a) { return a[3] })) } UnquotedString = [^;"',]+ { return text() } NotSingleQuote = !("'" / "\\") . { return text() } EscapedSingleQuote = "\\" "'" { return '\\\'' } / "\\\\" { return '\\\\' } SingleQuotedString = "'" content:(NotSingleQuote / EscapedSingleQuote)* "'" { return content.join('') } NotDoubleQuote = !("\"" / "\\") . { return text() } EscapedDoubleQuote = "\\" "\"" { return '\\"' } / "\\\\" { return '\\\\' } DoubleQuotedString = "\"" content:(NotDoubleQuote / EscapedDoubleQuote)* "\"" { return content.join('') } JailBlock = _ name:JailName _ "{" _ body:JailBody _ "}" _ { return { 'JailBlock': { 'name': name, 'body': body } } } JailName = [a-zA-Z0-9][a-zA-Z0-9]* { return text() } JailBody = (Parameter / Comment)* ```
Sign in to join this conversation.
No Label
No Milestone
No Assignees
1 Participants
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
Cancel
Save
There is no content yet.