lib/junoser/js_ruler.rb in junoser-0.4.0 vs lib/junoser/js_ruler.rb in junoser-0.4.1

- old
+ new

@@ -61,12 +61,10 @@ # enum(("foo" | "bar")).as(:arg) ( -> {"(bar|baz)": # TODO: support "enum" in the middle of line str.gsub!(/enum\(\(([^)]+)\)\)\.as\(:arg\) \(/) {"{\"(#{$1.gsub('"', '').split(' | ').join('|')})\":"} str.gsub! '.as(:arg)', '' - # any -> "any" - # c( -> { str.gsub!(/^(\s*)c\(/) {"#$1{"} # foo /* doc */, -> foo() /* doc */, str.gsub!(%r|^(\s*)(?!arg)(\w+)( /\* (.*) \*/,?)$|) {"#$1this.#$2()#$3"} @@ -224,13 +222,18 @@ # "arg" -> "arg_1" lines.gsub('"arg":') {%["arg_#{sequence}":]} end + # } -> ) def balance_parenthesis(lines) # Fixes lines.gsub! 'Timeslots (1..24;', 'Timeslots (1..24);' + lines.gsub! '(such that the VLAN range is x <= range <= y.', '(such that the VLAN range is x <= range <= y).' + lines.gsub! '(intended primarily for use with a peer or group"', '(intended primarily for use with a peer or group)"' + lines.gsub! '(e.g. QSFP28 and QSFP+,', '(e.g. QSFP28 and QSFP+),' + lines.gsub! '(see the description of policy evaluation at the top of this module."', '(see the description of policy evaluation at the top of this module)."' count = 0 target = nil buf = '' stack = [] @@ -271,42 +274,33 @@ end def objectize_arg_of_s(lines) # s( -> s({ lines.gsub!(/^( *(?:return|\S+:)? +)s\($/m) {"#$1this.s({"} + # sc( -> sc({ + lines.gsub!(/^( *(?:return|\S+:)? +)sc\($/m) {"#$1this.sc({"} # ) -> }) - lines.gsub!(/^( *)\)$/m) {"#$1})"} + lines.gsub!(/^( *)\)(,?)$/m) {"#$1})#$2"} lines end def rule_header <<~EOS + /* eslint-disable semi */ + class Enumeration { constructor(list) { this.list = list; - this.children = []; } + } - map(callback) { - // NOTE: This is a bit hacky but assuming that it's called like "this.children.map((node) => node.name)" - return this.list; + class Repeatable { + constructor(list) { + this.list = list; } - - find(callback) { - // NOTE: This is a bit hacky but assuming that it's called like "this.children.find((node) => node.name === string)" - return; - } - - forEach(callback) { - return this.list.forEach(callback); - } - - keywords() { - return this.list; - } } class Sequence { constructor(list) { this.list = list; @@ -325,18 +319,23 @@ s(obj) { const list = Object.entries(obj).map(([key, value]) => ({[key]: value})); return new Sequence(list); } + sc(obj) { + return new Repeatable(obj); + } + EOS end def rule_footer <<~EOS } - module.exports = {JunosSchema: JunosSchema, Enumeration: Enumeration, Sequence: Sequence}; + // eslint-disable-next-line no-undef + module.exports = {JunosSchema, Enumeration, Repeatable, Sequence}; EOS end end end