parseSCPI.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // BNF notation:
  2. // <> Defined element
  3. // = is defined as
  4. // | Exclusive OR
  5. // {} Group, one element is required
  6. // [] Optional, can be omitted
  7. // ... Previous element(s) may be repeated
  8. // Message elements
  9. // [:]<Header>[<Space><Argument>[<Comma>[<Space>]<Argument>]...]
  10. // Agrument types
  11. // <NR1> Signed integer value
  12. // <NR2> Floating point value
  13. // <NR3> Floating point value with exponent
  14. // <Nrf> Mixed format, any of <NR1>, <NR2>, <NR3>
  15. // <Nrf+> Mixed format, any of <Nrf>, MIN, MAX or DEF
  16. // <bin> Signed or unsigned integer in binary format
  17. // <Bool> 0|1|ON|OFF
  18. // <QString> Quoted with single (') or double quotes (")
  19. // <NZDig> Non-zero digit character 1-9
  20. // <Dig> Digit character 0-9
  21. // <DChar> Character with hex equivalent 00-FF (0-255 decimal)
  22. // <Block> {#<NZDig><Dig>[<Dig>...][<DChar>...]|#0[<DChar>...]<terminator>}
  23. // Mnemonics
  24. // CH<x> channel specifier, <x> is 1 through 4
  25. // CURSOR<x> cursor selector, <x> is 1 or 2
  26. const nr1 = `[+-]?\d+`
  27. const nr2 = `[+-]?(?:\d+\.?\d*|\d*\.\d+)`
  28. const nr3 = `${nr2}(?:[eE]${nr2})?`
  29. const NR1 = new RegExp(`(${nr1})`)
  30. const NR2 = new RegExp(`(${nr2})`)
  31. const NR3 = new RegExp(`(${nr3})`)
  32. const nfr = `${nr1}|${nr2}|${nr3}`
  33. const nfrp = `${nfr}|MIN|MAX|DEF`
  34. const Nfr = new RegExp(`(${nfr})`)
  35. const Nfrp = new RegExp(`(${nfrp})`)
  36. const bool = `0|1|ON|OFF`
  37. const Bool = new RegExp(`(${bool})`)
  38. const qString = `(?:["'])(?:(?:\\{2})*|(?:.*?[^\\](?:\\{2})*))\1`
  39. const QString = new RegExp(`(${qString})`)
  40. const dig = `\d`
  41. const nzdig = `[1-9]`
  42. const dchar = `[\\x00-\\xFF]`
  43. const Dig = new RegExp(`(${dig})`)
  44. const ZNDig = new RegExp(`(${nzdig})`)
  45. const DChar = new RegExp(`(${dchar})`)
  46. const block = `#${nzdig}(?:${dig})+(?:${dchar})*|#0(?:${dchar})*`
  47. const Block = new RegExp(`(${block})`)
  48. const header = `v`
  49. const Header = new RegExp(`(${header})`)