Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AHK v2 a108 code #21

Open
wants to merge 56 commits into
base: v2
Choose a base branch
from
Open

AHK v2 a108 code #21

wants to merge 56 commits into from

Conversation

TheArkive
Copy link

I played around with the code in Jxon.ahk and got a working version for AHK v1 and v2 (a108). Some lines have to be toggled as commented / uncommented to get both AHK v1 and v2 functionality. Straight {} objects have been dropped in the AHK v2 bit. Only Arrays() and Maps() are included.

AHK v1 issues:

  • blank arrays/maps are always detected as maps since there's no way to determine array type
  • maps with sequential numerical indexes are detected as linear arrays
  • numbers quoted or not come out unquoted
  • numbers starting with 0 come out quoted
  • Jxon_Load() accepts unquoted numbers now

AHK v2 progress:

  • quoted strings are properly detected regardless of contents
  • arrays/maps are properly detected regardless of contents
  • Jxon_Load() accepts unquoted numbers now

JXON.ahk.txt

- JSON.object.len() returning blank("") instead of 0.
- JSON.object.Remove() now behaves like AHK's obj.Remove() except existing
  integer key(s) are not adjusted when an integer key(or a range of integer keys)
  is removed. Return value is the same with AHK's obj.Remove().
 - parse(): Improved validation of JSON source. Most (if all)
   common format errors are detected. As before, an exception
   is thrown. Code refactored.
   Added 'OutputNormal' class property to allow users to set
   whether returned object(s)/array(s) are sublclassed as
   JSON.object/JSON.array instance(s). Default is 'true' which
   returns instance(s) of JSON._object/JSON._array(notice the
   underscores) which are actually just normal AHK object(s)
   with no special behavior.
 - stringify(): A space is no longer added after a comma or colon
   if indent is not specified. Output is truly compact.
- parse():
  Removed 'OutputNormal', '_object' and '_array' class
  properties. 'OutputNormal' has been replaced with 'jsonize'
  parameter. Defaults to 'false' which returns object(s) as
  normal/ordinary AHK object(s).
  Changed parsing of true,false,null values -> no longer loops
  through each character to validate.
  Minor optimizations + code refactoring.
- stringify():
  Fixed output for empty object(s) when indentation is specified.
  No longer checks if an object is an instance of JSON.object or
  JSON.array as this will cause erroneous output if the user
  modifies the object's contents prior stringification.
  Minor optimization + changed some variable names.
- Alternative to JSON.ahk.
- Interface implemented as a function instead of a class.
- Will work on both AHK v1.1 and v2.0-a
- FOR v2.0-a -> A_AhkVersion >= v2.0-a049.
such as COM, Func, RegExMatch, File object(s). Fixed dumping bug
when object has a custom enumerator.
range of integer keys, remaining integer keys are not adjusted.
Will fix in next commit.
    - New function names: Jxon_Load(), Jxon_Dump()
    - Added Jxon_Read() and Jxon_Write() -> for file read/write
literal strings are no longer extracted prior markup parsing. This
allows passing of variable(if any) containing the JSON document
as ByRef.
more descriptive and provide information on the line number, column
number and character position of the invalid data/token.
Jxon_Dump(): Improved error info if object key is invalid.
The fact that the block is reached means that the currently evaluated
char/token must be either of these: '01234567890-tfn'. So to signal
an error, 'next' must simply be neither of those.
General
    - [commit cc42d90] Improved string replacement routines.

JSON.parse()
    - [commit b33db32] Changed from two-pass to single-pass method.
    - [commit c664a37] Simplified parsing of number(s), true, false
      and null.
    - [commit 315d6fe] Fixed a bug when validating next char after
      comma(,) in object.
    - [commit 46c262b] Improved exception handling w/ descriptive
      error messages.
    - Lib is now AutoHotkey v1.1 and v2.0-a compatible
    - Added JSON.object.Delete() - similar to ObjDelete()
    - Removed JSON.object.Count() and JSON.object.Insert()
    - Array methods such as InsertAt/RemoveAt and Push/Pop
      are not implemented for JSON.object object(s).
    - Some changes here and there.
    - Changed .parse() to .Load()
    - Changed .stringify() to .Dump()
    - For compatibility, call(s) to .parse()/.stringify() are casted
      to .Load()/.Dump() respectively.
    - [cdac8d4] Method names changed.
    - [0f527d6] Updated to use backported v2.0-a features.
Conform with ECMAScript's JSON.parse() and JSON.stringfy() specifications

    - Remove backward support for old Parse() and Stringify() methods
    - Remove JSON.Object and JSON.Array objects
    - Remove JSON.Load()'s 'jsonize' paramter
    - Add 'reviver' parameter to JSON.Load()
    - Add 'replacer' parameter to JSON.Dump()
    - Improve handling of array(s) during stringification process
    - Limit indentation(pretty-printing) to 10 characters
    - Add missing error message
    - Disable '/' escaping when stringifying
    - Load(), remove static variable 'null'. This should make it
      AutoHotkey_H-compatible(untested).
    - Dump(), improve skipping of non-serializable objects such as
      ComObject, Func, BoundFunc, FileObject, RegExMatchObject,
      Property, etc.
    - Add JSON.Undefined for use within reviver/replacer functions
    - Properties are not removed if the reviver function returns
      JSON.Undefined
    - When stringifying sparse arrays, Dump() overrides the returned
      value of the replacer function(when an empty element is passed)
      with 'null'.
    - Pass JSON.Undefined as value parameter to the replacer function
      if the current field is an empty field in a sparse array.
Previously math (value += 0) is applied on unquoted numerical values
to "numerify" the numbers. As a side-effect, floating point values
are sometimes altered based on A_FormatFloat. Returning the value as
it appears in the document/text should be the behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants