Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Support for IETF ABNF (RFC 5234 and extensions) #542

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/lang-ietfabnf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @license
* Copyright (C) 2008 Julian Reschke
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @fileoverview
* Registers a language handler for IETF ABNF, as specified in RFC 5234,
* and extended in RFCs 7230 and 7405.
*/

PR['registerLangHandler'](
PR['createSimpleLexer'](
[
// comment
[PR['PR_COMMENT'], /;[^\r\n]*/, null, ";"],
],
[
// string, binary, decimal and hex literals
[PR['PR_LITERAL'], /((\%s)?"[^"]*"|(\%x[A-Za-z0-9]+(-[A-Za-z0-9]+|[\.[A-Za-z0-9]+]*))|(\%d[0-9]+(-[0-9]+|[\.[0-9]+]*))|(\%b[01]+(-[01]+|[\.[01]+]*)))/, null],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure (-[A-Za-z0-9]+|[\.[A-Za-z0-9]+]*) doesn't do what you want. Notice the [ and ] around \.[A-Za-z0-9]+ instead of parentheses.

Maybe (?:[-.][A-Za-z0-9]+)* does what you want.

If so, this problem occurs thrice.

Also, AFAICT, %s doesn't appear in RFC 5234. Is that part of an extension? Do those conventions include an escaping convention for strings?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Will check.
  2. %s is defined in https://tools.ietf.org/html/rfc7405#section-2.1 (but so is "%i" which I should include as well)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to address this in d8a2671 - note that the simplified expression would match things like

%x31-39-49

which it should not (but then one could argue that it's not the job of the highlighter to spot errors like these).

// prose rule
[PR['PR_PLAIN'], /<[^<>]*>/, null],
// rule name
[PR['PR_KEYWORD'], /([A-Za-z][A-Za-z0-9-]*)/, null],
[PR['PR_PUNCTUATION'], /[=\(\)\*\/\[\]#]/, null],
]),
['ietfabnf']);