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"
{
@ -17,7 +22,7 @@ AttributesSection
AttributesSectionSATA
= "=== 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
"ID#" _ "ATTRIBUTE_NAME" _ "FLAG" _ "VALUE" _ "WORST" _ "THRESH" _ "TYPE" _ "UPDATED" _ "WHEN_FAILED" _ "RAW_VALUE" Newline
attributes:AttributeFieldSATA+ {
@ -32,7 +37,7 @@ AttributesSectionNVMe
}
AttributeFlags
= "0x" number:HexNumberValue {
= "0x" number:HexInteger {
return mapAttributeFlags(number);
}
@ -50,12 +55,12 @@ AttributeFieldType
/ "Old_age"
AttributeFieldSATA
= _ id:NumberValue
= _? id:Integer
_ attributeName:IdentifierValue
_ flags:AttributeFlags
_ value:NumberValue
_ worstValue:NumberValue
_ threshold:NumberValue
_ value:Integer
_ worstValue:Integer
_ threshold:Integer
_ type:AttributeFieldType
_ updatedWhen:AttributeUpdatedWhen
_ 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"
{
@ -61,7 +66,7 @@ InfoFieldIgnored
InfoFieldSize
// 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 {
key: "size",
value: B(value)
@ -73,7 +78,7 @@ InfoFieldSizeKey
/ "Total NVM Capacity:"
InfoFieldRPM
= "Rotation Rate:" _ value:NumberValue _ "rpm" Newline {
= "Rotation Rate:" _ value:Integer _ "rpm" Newline {
return {
key: "rpm",
value: value

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

@ -1,42 +1,20 @@
import { Newline } from "../../peg-newline"
import { CommaDelimitedInteger as GroupedInteger } from "../../peg-grouped-number"
{
const syncpipe = require("syncpipe");
const {B} = require("../../unit-bytes-iec");
}
_
= (" " / "\t")*
RestOfLine
= content:$[^\n]+ Newline {
return content;
}
Newline
= "\n"
/ "\r\n"
BytesValue
= value:SeparatedNumberValue {
= value:GroupedInteger {
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
= value:$[a-zA-Z_-]+ {

@ -1,4 +1,6 @@
import { RestOfLine, Newline } from "./primitives"
import { Newline } from "../../peg-newline"
import { RestOfLine } from "./primitives"
Header 'header'
= "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