Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle characters in the parser. #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions app.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
application: "olp-rdm-staging"
#application: "rdmprotocol-hrd"
#application: "olp-rdm-staging"
application: "rdmprotocol-hrd"
Copy link
Member

Choose a reason for hiding this comment

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

Revert this

version: 1
runtime: python27
api_version: 1
Expand Down
16 changes: 11 additions & 5 deletions js_src/rdm.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,20 +340,26 @@ angular.module('rdmApp', [])
var token = tokens[j];
var hex_suffix_match = token.match(/^([\da-fA-F]{1,2})h$/);
if (hex_suffix_match) {
binary_data.push(parseInt(hex_suffix_match[0], 16));
binary_data.push(parseInt(hex_suffix_match[1], 16));
Copy link
Member

Choose a reason for hiding this comment

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

Can we have a comment at the top of this block reminding people of the broken way capture groups work in JS (it gets even messier if it's a global match with groups!

continue;
}

var hex_prefix_match = token.match(/^0x([\da-fA-F]{1,2})$/);
if (hex_prefix_match) {
binary_data.push(parseInt(hex_prefix_match[0], 16));
binary_data.push(parseInt(hex_prefix_match[1], 16));
continue;
}

var char_match = token.match(/^'(.)'$/);
if (char_match) {
binary_data.push(char_match[1].charCodeAt());
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be

binary_data.push(char_match[1].charCodeAt(0));

Copy link
Member Author

Choose a reason for hiding this comment

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

Apparently 0 is the default.

I think I'm going to re-write the parser anyway.

continue;
}

if (as_hex) {
var hex_match = token.match(/^([\da-fA-F]{1,2})$/);
if (hex_match) {
binary_data.push(parseInt(hex_match[0], 16));
binary_data.push(parseInt(hex_match[1], 16));
continue;
} else {
error = 'Invalid byte: ' + token;
Expand All @@ -362,8 +368,8 @@ angular.module('rdmApp', [])
} else {
var decimal_match = token.match(/^(\d{1,3})$/);
if (decimal_match) {
if (decimal_match[0] <= 255) {
binary_data.push(parseInt(decimal_match[0], 10));
if (decimal_match[1] <= 255) {
binary_data.push(parseInt(decimal_match[1], 10));
continue;
} else {
error = 'Invalid byte: ' + token;
Expand Down
2 changes: 1 addition & 1 deletion static/js/rdm.js

Large diffs are not rendered by default.

Loading