WIP: Modularize out parsers

feature/node-rewrite
Sven Slootweg 4 years ago
parent f85ab90be1
commit 6b5bd204d3

@ -1,4 +1,9 @@
import { _, RestOfLine, Newline, NumberValue, HexNumberValue, IdentifierValue } from "../primitives" import { Integer } from "../../../peg-number"
import { HexInteger } from "../../../peg-hex-number"
import { Newline } from "../../../peg-newline"
import { SameLine as _ } from "../../../peg-whitespace"
import { RestOfLine, IdentifierValue } from "../primitives"
import { Header } from "../shared" import { Header } from "../shared"
{ {
@ -17,7 +22,7 @@ AttributesSection
AttributesSectionSATA AttributesSectionSATA
= "=== START OF READ SMART DATA SECTION ===" Newline = "=== START OF READ SMART DATA SECTION ===" Newline
"SMART Attributes Data Structure revision number:" _ NumberValue Newline "SMART Attributes Data Structure revision number:" _ Integer Newline
"Vendor Specific SMART Attributes with Thresholds:" Newline "Vendor Specific SMART Attributes with Thresholds:" Newline
"ID#" _ "ATTRIBUTE_NAME" _ "FLAG" _ "VALUE" _ "WORST" _ "THRESH" _ "TYPE" _ "UPDATED" _ "WHEN_FAILED" _ "RAW_VALUE" Newline "ID#" _ "ATTRIBUTE_NAME" _ "FLAG" _ "VALUE" _ "WORST" _ "THRESH" _ "TYPE" _ "UPDATED" _ "WHEN_FAILED" _ "RAW_VALUE" Newline
attributes:AttributeFieldSATA+ { attributes:AttributeFieldSATA+ {
@ -32,7 +37,7 @@ AttributesSectionNVMe
} }
AttributeFlags AttributeFlags
= "0x" number:HexNumberValue { = "0x" number:HexInteger {
return mapAttributeFlags(number); return mapAttributeFlags(number);
} }
@ -50,12 +55,12 @@ AttributeFieldType
/ "Old_age" / "Old_age"
AttributeFieldSATA AttributeFieldSATA
= _ id:NumberValue = _? id:Integer
_ attributeName:IdentifierValue _ attributeName:IdentifierValue
_ flags:AttributeFlags _ flags:AttributeFlags
_ value:NumberValue _ value:Integer
_ worstValue:NumberValue _ worstValue:Integer
_ threshold:NumberValue _ threshold:Integer
_ type:AttributeFieldType _ type:AttributeFieldType
_ updatedWhen:AttributeUpdatedWhen _ updatedWhen:AttributeUpdatedWhen
_ failedWhen:AttributeFailedWhen _ failedWhen:AttributeFailedWhen

@ -1,4 +1,9 @@
import { _, RestOfLine, Newline, NumberValue, SeparatedNumberValue, BytesValue } from "../primitives" import { Integer } from "../../../peg-number"
import { CommaDelimitedInteger as GroupedNumber } from "../../../peg-grouped-number"
import { Newline } from "../../../peg-newline"
import { SameLine as _ } from "../../../peg-whitespace"
import { RestOfLine, BytesValue } from "../primitives"
import { Header } from "../shared" import { Header } from "../shared"
{ {
@ -61,7 +66,7 @@ InfoFieldIgnored
InfoFieldSize InfoFieldSize
// NOTE: We don't actually care about the human-friendly display size after the 'bytes' specifier, hence the RestOfLine // NOTE: We don't actually care about the human-friendly display size after the 'bytes' specifier, hence the RestOfLine
= InfoFieldSizeKey _ value:SeparatedNumberValue _ "bytes"? _ RestOfLine { = InfoFieldSizeKey _ value:GroupedNumber (_ "bytes")? _ RestOfLine {
return { return {
key: "size", key: "size",
value: B(value) value: B(value)
@ -73,7 +78,7 @@ InfoFieldSizeKey
/ "Total NVM Capacity:" / "Total NVM Capacity:"
InfoFieldRPM InfoFieldRPM
= "Rotation Rate:" _ value:NumberValue _ "rpm" Newline { = "Rotation Rate:" _ value:Integer _ "rpm" Newline {
return { return {
key: "rpm", key: "rpm",
value: value value: value

@ -1,4 +1,6 @@
import { _, RestOfLine } from "../primitives" import { SameLine as _ } from "../../../peg-whitespace"
import { RestOfLine } from "../primitives"
RootScan RootScan
= devices:ScanDevice* { = devices:ScanDevice* {

@ -1,43 +1,21 @@
import { Newline } from "../../peg-newline"
import { CommaDelimitedInteger as GroupedInteger } from "../../peg-grouped-number"
{ {
const syncpipe = require("syncpipe"); const syncpipe = require("syncpipe");
const {B} = require("../../unit-bytes-iec"); const {B} = require("../../unit-bytes-iec");
} }
_
= (" " / "\t")*
RestOfLine RestOfLine
= content:$[^\n]+ Newline { = content:$[^\n]+ Newline {
return content; return content;
} }
Newline
= "\n"
/ "\r\n"
BytesValue BytesValue
= value:SeparatedNumberValue { = value:GroupedInteger {
return B(value); return B(value);
} }
NumberValue
= value:$[0-9]+ {
return parseInt(value);
}
SeparatedNumberValue
= value:$[0-9,]+ {
return syncpipe(value, [
(_) => _.replace(/,/g, ""),
(_) => parseInt(_)
]);
}
HexNumberValue
= value:$[0-9A-Fa-f]+ {
return parseInt(value, 16);
}
IdentifierValue IdentifierValue
= value:$[a-zA-Z_-]+ { = value:$[a-zA-Z_-]+ {
return value; return value;

@ -1,4 +1,6 @@
import { RestOfLine, Newline } from "./primitives" import { Newline } from "../../peg-newline"
import { RestOfLine } from "./primitives"
Header 'header' Header 'header'
= "smartctl " versionString:RestOfLine "Copyright" copyrightStatement:RestOfLine Newline { = "smartctl " versionString:RestOfLine "Copyright" copyrightStatement:RestOfLine Newline {

@ -0,0 +1,29 @@
{
function stripCommas(string) {
return string.replace(/,/g, "");
}
function stripPeriods(string) {
return string.replace(/\./g, "");
}
}
CommaDelimitedInteger
= value:$[0-9,]+ {
return parseInt(stripCommas(value));
}
CommaDelimitedFloat
= value:$([0-9,]+ ("." [0-9]+)?) {
return parseFloat(stripCommas(value));
}
PeriodDelimitedInteger
= value:$[0-9.]+ {
return parseInt(stripPeriods(value));
}
PeriodDelimitedFloat
= value:$([0-9.]+ ("," [0-9]+)?) {
return parseFloat(stripPeriods(value).replace(/,/g, "."));
}

@ -0,0 +1,4 @@
HexInteger // NOTE: This is assumed to be an unsigned integer!
= value:$[0-9a-zA-Z]+ {
return parseInt(value, 16);
}

@ -0,0 +1,3 @@
Newline
= "\n"
/ "\r\n"

@ -0,0 +1,14 @@
Integer
= value:$[0-9]+ {
return parseInt(value);
}
CommaFloat
= value:$([0-9]+ ("," [0-9]+)?) {
return parseFloat(value.replace(/,/g, "."));
}
PeriodFloat
= value:$([0-9]+ ("." [0-9]+)?) {
return parseFloat(value);
}

@ -0,0 +1,17 @@
import { Newline } from "../peg-newline"
SameLine
= whitespace:$(" " / "\t")+ {
return whitespace;
}
AcrossLines
= whitespace:$(SameLine / Newline)+ {
return whitespace;
}
SameLineOptional
= SameLine?
AcrossLinesOptional
= AcrossLines?
Loading…
Cancel
Save