Skip to content

Instantly share code, notes, and snippets.

@sp3c73r2038
Created February 19, 2013 09:03
Show Gist options
  • Save sp3c73r2038/4984204 to your computer and use it in GitHub Desktop.
Save sp3c73r2038/4984204 to your computer and use it in GitHub Desktop.
Augmented BNF for Syntax Specifications example in ruby.
#!/usr/bin/env ruby
# -*- coding:utf-8 -*-
# some syntax define in RFC
# refer to http://tools.ietf.org/html/rfc5234
def loop_print(range)
if range.is_a? Range
range.each do |v|
print v, ":", v.to_s.to_i.chr, "\n"
end
else
v = range
print v, ":", v.to_s.to_i.chr, "\n"
end
end
# VSCHAR
puts "=========== VSCHAR =========="
loop_print((0x20..0x7E))
# NQCHAR
puts "=========== NQCHAR =========="
[(0x21), (0x23..0x5B), (0x5D..0x7E)].each do |range|
loop_print(range)
end
# NQSCHAR
puts "=========== NQSCHAR =========="
[(0x20), (0x23..0x5B), (0x5D..0x7E)].each do |range|
loop_print(range)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment